diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-27 04:19:34 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-27 04:19:34 +0200 |
commit | 665e88c72b568bf25ff0ec8a14109e2504f99aa8 (patch) | |
tree | c380e91e40efa8a47dea9ff833415f17e273d106 /node_modules/axios/lib/helpers/btoa.js | |
parent | 24181bdf20e0d23ec5ec5d2eaa08ae1cfb905f0f (diff) |
node_modules
Diffstat (limited to 'node_modules/axios/lib/helpers/btoa.js')
-rw-r--r-- | node_modules/axios/lib/helpers/btoa.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/node_modules/axios/lib/helpers/btoa.js b/node_modules/axios/lib/helpers/btoa.js new file mode 100644 index 000000000..2fe501428 --- /dev/null +++ b/node_modules/axios/lib/helpers/btoa.js @@ -0,0 +1,36 @@ +'use strict'; + +// btoa polyfill for IE<10 courtesy https://github.com/davidchambers/Base64.js + +var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + +function E() { + this.message = 'String contains an invalid character'; +} +E.prototype = new Error; +E.prototype.code = 5; +E.prototype.name = 'InvalidCharacterError'; + +function btoa(input) { + var str = String(input); + var output = ''; + for ( + // initialize result and counter + var block, charCode, idx = 0, map = chars; + // 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) { + throw new E(); + } + block = block << 8 | charCode; + } + return output; +} + +module.exports = btoa; |