aboutsummaryrefslogtreecommitdiff
path: root/node_modules/atob/browser-atob.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/atob/browser-atob.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/atob/browser-atob.js')
-rw-r--r--node_modules/atob/browser-atob.js52
1 files changed, 30 insertions, 22 deletions
diff --git a/node_modules/atob/browser-atob.js b/node_modules/atob/browser-atob.js
index f5fc8bce3..af4f357bb 100644
--- a/node_modules/atob/browser-atob.js
+++ b/node_modules/atob/browser-atob.js
@@ -1,36 +1,44 @@
(function (w) {
"use strict";
- var a2b = w.atob;
-
- function atob(str) {
+ function findBest(atobNative) {
// normal window
- if ('function' === typeof a2b) {
- return a2b(str);
- }
+ if ('function' === typeof atobNative) { return atobNative; }
+
+
// browserify (web worker)
- else if ('function' === typeof Buffer) {
- return new Buffer(str, 'base64').toString('binary');
+ if ('function' === typeof Buffer) {
+ return function atobBrowserify(a) {
+ //!! Deliberately using an API that's deprecated in node.js because
+ //!! this file is for browsers and we expect them to cope with it.
+ //!! Discussion: github.com/node-browser-compat/atob/pull/9
+ return new Buffer(a, 'base64').toString('binary');
+ };
}
+
// ios web worker with base64js
- else if ('object' === typeof w.base64js) {
+ if ('object' === typeof w.base64js) {
// bufferToBinaryString
- // https://github.com/coolaj86/unibabel-js/blob/master/index.js#L50
- var buf = w.base64js.b64ToByteArray(str);
-
- return Array.prototype.map.call(buf, function (ch) {
- return String.fromCharCode(ch);
- }).join('');
- }
- // ios web worker without base64js
- else {
- throw new Error("you're probably in an ios webworker. please include use beatgammit's base64-js");
+ // https://git.coolaj86.com/coolaj86/unibabel.js/blob/master/index.js#L50
+ return function atobWebWorker_iOS(a) {
+ var buf = w.base64js.b64ToByteArray(a);
+ return Array.prototype.map.call(buf, function (ch) {
+ return String.fromCharCode(ch);
+ }).join('');
+ };
}
+
+ return function () {
+ // ios web worker without base64js
+ throw new Error("You're probably in an old browser or an iOS webworker." +
+ " It might help to include beatgammit's base64-js.");
+ };
}
- w.atob = atob;
+ var atobBest = findBest(w.atob);
+ w.atob = atobBest;
- if (typeof module !== 'undefined') {
- module.exports = atob;
+ if ((typeof module === 'object') && module && module.exports) {
+ module.exports = atobBest;
}
}(window));