global-object-guard lets you control and Manage Global Object
global-object-guard
is a utility module which provides straight-forward, powerful functions
for working with global objects in JavaScript. Although originally designed for
use with Node.js, it can not used in the
browser.
global-object-guard provides around 4 functions that include the usual 'functional'
suspects (Create
, getDifference
, rePositionGlobalObject
, refreshGlobalObject
). All these
functions assume you follow the Node.js convention. This will help the developer
to track their global object
in node and allow them to check the status
of the global object and also helps them to clean
the global object.
Quick Example
var GlobalObjectGuard = require('global-object-guard');
_appSetting = {
PORT: 2000,
HOST: "http://localhost"
};
_otherServerSetting = {
};
var gb = GlobalObjectGuard.Create(global);
obj = {name: "Kashish", age: 24};
var result = gb.getDifference();
console.log("Checking Global Object Pollution: ", result);
gb.rePositionGlobalObject(global);
result = gb.getDifference();
console.log("After RePosition the Global Object: " + JSON.stringify(result));
(function () {
person = {address: "B4-90 US"}
})();
result = gb.getDifference();
console.log("Opes Just hit the global object: " + JSON.stringify(result));
gb.refreshGlobalObject();
result = gb.getDifference();
console.log("Everything is clean by GlobalObjectGuard: " + JSON.stringify(result));
Download
The source is available for download from
GitHub.
Alternatively, you can install using Node Package Manager (npm
):
Installation
$ npm install global-object-guard