b64-lite
Version:
isomorphic base64 library in 152 bytes
37 lines (29 loc) • 1.05 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.b64Lite = {})));
}(this, (function (exports) {
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.umd.js.map