Node/browser library to detect global/window namespace pollution.
- With npm:
$ npm install antiglobal
- With bower:
$ bower install antiglobal
var antiglobal = require('antiglobal');
Take a browserified version of the library from the dist/
folder:
dist/antiglobal-X.Y.Z.js
: The uncompressed version.dist/antiglobal-X.Y.Z.min.js
: The compressed production-ready version.dist/antiglobal.js
: A copy of the uncompressed version.
They all expose the global window.antiglobal
function.
<script src='antiglobal.js'></script>
<script src='js/antiglobal.js'></script>
<script src='js/foo.js'></script> // Creates window.FOO
<script>
antiglobal('FOO'); // OK, returns true
</script>
<script src='js/bar.js'></script> // Creates window.BAR
<script>
antiglobal('QWE'); // ERROR: given globals do not match real new globals
// [given: QWE | real: BAR]
</script>
nameN
: The name (string) of a new expected element in the global/window namespace.
Returns true
if given arguments match the new elements in the global/window namespace.
It updates the list of elements in the global/window namespace for the next execution.
Reset the list of elements in the global/window namespace. Useful to ignore globals introduced by a library while still allowing antiglobal()
to check other libraries loaded after that.
If set to true
, errors when calling antiglobal()
are logged to console.error
.
Default value is true
.
If set to true
, errors when calling antiglobal()
throw an Error
exception.
Default value is false
.
Iñaki Baz Castillo.
ISC.