I know that we can import all named modules with alias as below,
import * as name from \"module-name\";
Ref: https://developer.mozilla.org
global
is your current scope in node.js, similar to the window
object in the browser, so you can import into this object.
To import all symbols from util module:
import * as util from "./util";
util.importAll(util, global);
In util.js:
/**
* Takes all functions/objects from |sourceScope|
* and adds them to |targetScope|.
*/
function importAll(sourceScope, targetScope) {
for (let name in sourceScope) {
targetScope[name] = sourceScope[name];
}
}
... and a number of other functions like assert()
etc., which I need everywhere, and which should be part of the JavaScript language, but are not yet. But as others said, use this sparingly.