b64-lite
Version:
isomorphic base64 library in 152 bytes
30 lines (23 loc) • 787 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)));
}
exports.atob = atob;
exports.btoa = btoa;
exports.toBase64 = toBase64;
exports.fromBase64 = fromBase64;
//# sourceMappingURL=b64-lite.js.map