wallet-core/node_modules/atob/browser-atob.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-08-14 05:01:11 +02:00
(function (w) {
"use strict";
2018-09-20 02:56:13 +02:00
function findBest(atobNative) {
2017-08-14 05:01:11 +02:00
// normal window
2018-09-20 02:56:13 +02:00
if ('function' === typeof atobNative) { return atobNative; }
2017-08-14 05:01:11 +02:00
// browserify (web worker)
2018-09-20 02:56:13 +02:00
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');
};
2017-08-14 05:01:11 +02:00
}
2018-09-20 02:56:13 +02:00
2017-08-14 05:01:11 +02:00
// ios web worker with base64js
2018-09-20 02:56:13 +02:00
if ('object' === typeof w.base64js) {
2017-08-14 05:01:11 +02:00
// bufferToBinaryString
2018-09-20 02:56:13 +02:00
// 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('');
};
2017-08-14 05:01:11 +02:00
}
2018-09-20 02:56:13 +02:00
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.");
};
2017-08-14 05:01:11 +02:00
}
2018-09-20 02:56:13 +02:00
var atobBest = findBest(w.atob);
w.atob = atobBest;
2017-08-14 05:01:11 +02:00
2018-09-20 02:56:13 +02:00
if ((typeof module === 'object') && module && module.exports) {
module.exports = atobBest;
2017-08-14 05:01:11 +02:00
}
}(window));