This package has been deprecated

Author message:

This proposal has been renamed. Please use the `globalthis` package instead.

system.global

2.0.0 • Public • Published

system.global Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

An ECMAScript spec-compliant polyfill/shim for global. Invoke its "shim" method to shim global if it is unavailable.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec proposal.

Most common usage:

var global = require('system.global')(); // returns native method if compliant
    /* or */
var global = require('system.global/polyfill')(); // returns native method if compliant

Example

var assert = require('assert');
 
// the below function is not CSP-compliant, but reliably gets the
// global object in sloppy mode in every engine.
var getGlobal = Function('return this');
 
assert.equal(global, getGlobal());
/* when `global` is not present */
var shimmedGlobal = require('system.global').shim();
    /* or */
var shimmedGlobal = require('system.global/shim')();
 
assert.equal(shimmedGlobal, global);
assert.equal(shimmedGlobal, getGlobal());
/* when `global` is present */
var shimmedGlobal = require('system.global').shim();
 
assert.equal(shimmedGlobal, global);
assert.equal(shimmedGlobal, getGlobal());

Tests

Simply clone the repo, npm install, and run npm test

Package Sidebar

Install

npm i system.global

Weekly Downloads

4

Version

2.0.0

License

MIT

Last publish

Collaborators

  • ljharb