Comparing version 1.1.0 to 1.2.0
@@ -31,22 +31,28 @@ (function(f) { | ||
// encoder | ||
// [https://gist.github.com/999166] by [https://github.com/nignag] | ||
function btoa(input) { | ||
var str = String (input); | ||
for ( | ||
// initialize result and counter | ||
var block, charCode, idx = 0, map = chars, output = ''; | ||
// if the next str index does not exist: | ||
// change the mapping table to "=" | ||
// check if d has no fractional digits | ||
str.charAt (idx | 0) || (map = '=', idx % 1); | ||
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8 | ||
output += map.charAt (63 & block >> 8 - idx % 1 * 8) | ||
) { | ||
charCode = str.charCodeAt (idx += 3 / 4); | ||
if (charCode > 0xFF) { | ||
var data = String (input), o1, o2, o3, bits, i = 0, acc = ''; | ||
while (i < data.length) { | ||
// pack three octets into four hextets | ||
o1 = data.charCodeAt (i++); | ||
o2 = data.charCodeAt (i++); | ||
o3 = data.charCodeAt (i++); | ||
if (o1 > 128 || o2 > 128 || o3 > 128) { | ||
throw new InvalidCharacterError ("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); | ||
} | ||
block = block << 8 | charCode; | ||
bits = (o1 << 16) | (o2 << 8) | o3; | ||
// use hextets to index into b64, and append result to encoded string | ||
acc += chars.charAt ((bits >> 18) & 0x3F) + | ||
chars.charAt ((bits >> 12) & 0x3F) + | ||
chars.charAt ((bits >> 6) & 0x3F) + | ||
chars.charAt ((bits) & 0x3F); | ||
} | ||
return output; | ||
switch (data.length % 3) { | ||
case 0: return acc; | ||
case 1: return acc.slice (0, -2) + '=='; | ||
case 2: return acc.slice (0, -1) + '='; | ||
} | ||
} | ||
@@ -53,0 +59,0 @@ |
{ | ||
"name": "Base64", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Base64 encoding and decoding", | ||
@@ -13,6 +13,6 @@ "author": "David Chambers <dc@davidchambers.me>", | ||
"devDependencies": { | ||
"eslint": "5.15.x", | ||
"eslint": "8.34.x", | ||
"istanbul": "0.4.x", | ||
"mocha": "5.2.x", | ||
"sanctuary-style": "3.0.x", | ||
"sanctuary-style": "6.0.x", | ||
"uglify-js": "3.5.x", | ||
@@ -19,0 +19,0 @@ "xyz": "4.0.x" |
15869
71