bv-ui-core 2.8.0 → 2.8.2
Sign up to get free protection for your applications and to get access to all the features.
package/lib/global/index.js
CHANGED
@@ -6,11 +6,36 @@
|
|
6
6
|
'use strict'; /* eslint strict:0 */
|
7
7
|
|
8
8
|
var getGlobal = function () {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
var globalObj = (function () {
|
10
|
+
if (typeof globalThis !== 'undefined') { return globalThis; }
|
11
|
+
if (typeof window !== 'undefined') { return window; }
|
12
|
+
if (typeof self !== 'undefined') { return self; }
|
13
|
+
if (typeof global !== 'undefined') { return global; }
|
14
|
+
throw new Error('unable to locate global object');
|
15
|
+
})()
|
16
|
+
/*
|
17
|
+
The below code was added in case there is pollution in global namespace
|
18
|
+
windows object during transpilation with __esModule being set. Below code would support
|
19
|
+
global import in all bundle use cases
|
20
|
+
*/
|
21
|
+
if (globalObj && globalObj.__esModule) {
|
22
|
+
const proxyGlobal = new Proxy(globalObj, {
|
23
|
+
get: function (target, prop) {
|
24
|
+
if (prop === 'default') {
|
25
|
+
return target
|
26
|
+
}
|
27
|
+
|
28
|
+
return target[prop]
|
29
|
+
},
|
30
|
+
|
31
|
+
set: function (target, prop, value) {
|
32
|
+
target[prop] = value
|
33
|
+
return true
|
34
|
+
},
|
35
|
+
})
|
36
|
+
return proxyGlobal
|
37
|
+
}
|
38
|
+
return globalObj
|
14
39
|
};
|
15
40
|
|
16
41
|
module.exports = getGlobal();
|
package/package.json
CHANGED
@@ -15,4 +15,13 @@ describe('lib/global', function () {
|
|
15
15
|
}
|
16
16
|
});
|
17
17
|
|
18
|
+
it('should export window with default pointing to windows if __esModule is set', function () {
|
19
|
+
// If we have access to the window object, compare against it.
|
20
|
+
if (typeof window !== 'undefined') {
|
21
|
+
window.__esModule = true
|
22
|
+
var global = require('../../../lib/global')
|
23
|
+
expect(global).to.eql(window);
|
24
|
+
}
|
25
|
+
});
|
26
|
+
|
18
27
|
});
|