(text: string)
| 7 | * Works in both Node.js and browser environments |
| 8 | */ |
| 9 | export function encodeBase64(text: string): string { |
| 10 | if (typeof Buffer !== 'undefined') { |
| 11 | // Node.js environment |
| 12 | return Buffer.from(text).toString('base64'); |
| 13 | } else { |
| 14 | // Browser environment - modern approach |
| 15 | const encoder = new TextEncoder(); |
| 16 | const data = encoder.encode(text); |
| 17 | return btoa(String.fromCharCode(...Array.from(data))); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Encode string to hexadecimal |