All files / asm80-core/utils base64escaped.js

100% Statements 27/27
100% Branches 4/4
100% Functions 2/2
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 271x 1x 1x 1x 1x 1x 1x 347x 347x 347x 1x 1x 1x 1x 1x 1x 1x 1x 1x 350x 350x 350x 2721x 2721x 350x 350x 1x
/**
 * Encode string to Base64 with UTF-8 support
 * Uses TextEncoder for proper Unicode character handling
 * @param {string} str - String to encode
 * @returns {string} Base64 encoded string
 */
export const btoax = (str) => {
  const encoder = new TextEncoder();
  const bytes = encoder.encode(str);
  return btoa(String.fromCharCode(...bytes));
};
 
/**
 * Decode Base64 string with UTF-8 support
 * Uses TextDecoder for proper Unicode character handling
 * @param {string} str - Base64 string to decode
 * @returns {string} Decoded UTF-8 string
 */
export const atobx = (str) => {
  const binaryString = atob(str);
  const bytes = new Uint8Array(binaryString.length);
  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }
  const decoder = new TextDecoder();
  return decoder.decode(bytes);
};