Skip to content
ECMAScript spec-compliant polyfill/shim for `globalThis`.
Branch: master
Clone or download
Latest commit e358997 Aug 10, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test [breaking] update property name, rename repo Jul 26, 2018
.eslintrc
.gitignore Only apps should have lockfiles Jul 26, 2018
.jscs.json
.npmignore Dotfiles. Mar 30, 2016
.npmrc Only apps should have lockfiles Jul 26, 2018
.travis.yml
CHANGELOG.md v1.0.0 Aug 10, 2018
LICENSE
README.md
auto.js [New] add `auto` entry point Jul 26, 2018
browserShim.js
implementation.js
index.js
package.json v1.0.0 Aug 10, 2018
polyfill.js
shim.js

README.md

globalThis Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

An ECMAScript spec-compliant polyfill/shim for globalThis. Invoke its "shim" method to shim globalThis 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 globalThis = require('globalThis')(); // returns native method if compliant
	/* or */
var globalThis = require('globalThis/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(globalThis, getGlobal());
/* when `globalThis` is not present */
var shimmedGlobal = require('globalthis').shim();
	/* or */
var shimmedGlobal = require('globalthis/shim')();

assert.equal(shimmedGlobal, globalThis);
assert.equal(shimmedGlobal, getGlobal());
/* when `globalThis` is present */
var shimmedGlobal = require('globalthis').shim();

assert.equal(shimmedGlobal, globalThis);
assert.equal(shimmedGlobal, getGlobal());

Tests

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

You can’t perform that action at this time.