| 123456789101112131415161718192021222324252627282930313233343536373839 |
- /**
- * Base64 implementation with UTF-8 support
- * Replaces the previous UMD module to ensure correct bundling
- */
- export const Base64 = {
- /**
- * Decode Base64 string to UTF-8 string
- */
- decode(str: string): string {
- try {
- // Use TextDecoder for proper UTF-8 handling
- const binaryString = window.atob(str);
- const bytes = new Uint8Array(binaryString.length);
- for (let i = 0; i < binaryString.length; i++) {
- bytes[i] = binaryString.charCodeAt(i);
- }
- return new TextDecoder().decode(bytes);
- } catch (e) {
- console.error('Base64 decode error:', e);
- return '';
- }
- },
- /**
- * Encode UTF-8 string to Base64
- */
- encode(str: string): string {
- try {
- const bytes = new TextEncoder().encode(str);
- const binaryString = Array.from(bytes, (byte) => String.fromCharCode(byte)).join("");
- return window.btoa(binaryString);
- } catch (e) {
- console.error('Base64 encode error:', e);
- return '';
- }
- }
- };
- export default Base64;
|