b64-lite
Version:
isomorphic base64 library in 152 bytes
26 lines (20 loc) • 728 B
JavaScript
function atob(base64) {
return Buffer.from(base64, 'base64').toString('binary');
}
function btoa(byteString) {
for (var i = 0, list = byteString; i < list.length; i += 1) {
var byte = list[i];
if (String.prototype.charCodeAt.call(byte, 0) > 255) {
throw "Failed to execute 'btoa': The string to be encoded contains characters outside of the Latin1 range.";
}
}
return Buffer.from(byteString, 'binary').toString('base64');
}
function toBase64(string) {
return btoa(unescape(encodeURIComponent(string)));
}
function fromBase64(b64) {
return decodeURIComponent(escape(atob(b64)));
}
export { atob, btoa, toBase64, fromBase64 };
//# sourceMappingURL=b64-lite.mjs.map