diff options
Diffstat (limited to 'lib/getImportGlobalsSrc.js')
-rw-r--r-- | lib/getImportGlobalsSrc.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/getImportGlobalsSrc.js b/lib/getImportGlobalsSrc.js new file mode 100644 index 0000000..1bcfed4 --- /dev/null +++ b/lib/getImportGlobalsSrc.js @@ -0,0 +1,28 @@ +"use strict"; // run code in ES5 strict mode
+
+/**
+ * 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() {
+ var key,
+ value,
+ src = "";
+
+ for (key in global) {
+ if (global.hasOwnProperty(key) && key !== "global") {
+ value = global[key];
+ src += "var " + key + " = global." + key + "; ";
+ }
+ }
+
+
+ return src;
+}
+
+module.exports = getImportGlobalsSrc;
\ No newline at end of file |