The data to encode, can be a string, ArrayBuffer, or ArrayBufferView.
Optionaloptions: EncodeBase64OptionsEncoding options.
Base64 encoded string.
// String input
const encoded = encodeBase64('Hello, World!');
console.log(encoded); // 'SGVsbG8sIFdvcmxkIQ=='
// BufferSource input
const buffer = new Uint8Array([72, 101, 108, 108, 111]);
const base64 = encodeBase64(buffer);
console.log(base64); // 'SGVsbG8='
// Base64url with no padding
const url = encodeBase64(buffer, { alphabet: 'base64url', omitPadding: true });
console.log(url); // 'SGVsbG8'
Converts DataSource (string or BufferSource) to a Base64 encoded string.
Uses native
Uint8Array.prototype.toBase64if available, otherwise pure JS fallback.