Skip to content
ECMAScript spec-compliant polyfill/shim for `globalThis`.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows [actions] add automatic rebasing / merge commit blocking Dec 15, 2019
test [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `browserify`, `t… Dec 15, 2019
.eslintignore [Tests] remove `jscs` Jun 5, 2019
.eslintrc [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `browserify`, `t… Dec 15, 2019
.gitignore Only apps should have lockfiles Jul 26, 2018
.npmignore Dotfiles. Mar 30, 2016
.npmrc [meta] add `auto-changelog` Dec 15, 2019
LICENSE Initial commit Mar 30, 2016 readme: Fix casing + phrasing Apr 18, 2019
auto.js [New] add `auto` entry point Jul 26, 2018
browserShim.js implementation Mar 30, 2016
implementation.browser.js [Refactor] only use `global` in node; only check browser globals in b… Dec 15, 2019
implementation.js [Refactor] only use `global` in node; only check browser globals in b… Dec 15, 2019
index.js implementation Mar 30, 2016
polyfill.js Rename `` to `global` Sep 27, 2016
shim.js [breaking] update property name, rename repo Jul 26, 2018

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 globalThis if compliant
	/* or */
var globalThis = require('globalthis/polyfill')(); // returns native globalThis if compliant


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());


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

You can’t perform that action at this time.