blob: f8c73c2e049852f34748f8e74813f8dfd1367adb (
plain)
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
|
/**
* Declares all globals with a var and assigns the global object. Thus you're able to
* override globals without changing the global object itself.
*
* Returns something like
* "var console = console; var process = process; ..."
*
* @return {String}
*/
function getImportGlobalsSrc(ignore) {
var key,
value,
src = "",
globalObj = typeof global === "undefined"? window: global;
ignore = ignore || [];
for (key in globalObj) {
if (globalObj.hasOwnProperty === undefined || globalObj.hasOwnProperty(key)) { // in IE8 window.hasOwnProperty is undefined
if (key !== "global" && ignore.indexOf(key) === -1) {
value = globalObj[key];
src += "var " + key + " = global." + key + "; ";
}
}
}
return src;
}
module.exports = getImportGlobalsSrc;
|