-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
helpers.js
31 lines (29 loc) · 947 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
var isRN = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
var _btoa = null;
var helpers = null;
if (isNode || isRN) {
_btoa = function(str) {
return Buffer.from(str).toString('base64');
};
var url = require('url');
if (url.URL) {
// Use the new Node 6+ API for parsing URLs that supports username/password
var newURL = url.URL;
helpers = function(url) {
return new newURL(url);
};
} else {
// Web3 supports Node.js 5, so fall back to the legacy URL API if necessary
helpers = require('url').parse;
}
} else {
_btoa = btoa.bind(typeof globalThis === 'object' ? globalThis : self);
helpers = function(url) {
return new URL(url);
};
}
module.exports = {
parseURL: helpers,
btoa: _btoa
};