Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

globalthis

ljharb92.2mMIT1.0.4TypeScript support: definitely-typed

ECMAScript spec-compliant polyfill/shim for globalThis

window, self, global, globalThis, System.global, global object, global this value, ECMAScript, es-shim API, polyfill, shim

readme

globalThis Version Badge

github actions coverage 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

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.4 - 2024-04-29

Commits

  • [actions] remove redundant finisher 280d796
  • [Refactor] use gopd 0209ccb
  • [actions] update rebase action to use reusable workflow c08aea6
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, tape f38f2af
  • [Dev Deps] update aud, tape a1be102
  • [Deps] update define-properties 3e41644
  • [Deps] update define-properties 3d81f70
  • [Dev Deps] add missing npmignore dep c2d00f7

v1.0.3 - 2022-05-07

Commits

  • [actions] reuse common workflows 65891e4
  • [actions] use node/install instead of node/run; use codecov action 82f8481
  • [meta] use npmignore to autogenerate an npmignore file 53afc39
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, tape 03169d4
  • [Dev Deps] update eslint, @ljharb/eslint-config, safe-publish-latest, tape 4986e3e
  • [actions] update codecov uploader 15c4b06
  • [Dev Deps] update eslint, @ljharb/eslint-config, auto-changelog, tape 8b04a74
  • [Fix] globalThis should be writable 8759985
  • [readme] add github actions/codecov badges 0263f0d
  • [Dev Deps] update aud, eslint, tape e88d296
  • [meta] use prepublishOnly script for npm 7+ c81fde6
  • [Tests] nycignore dist bde0c0d
  • [meta] gitignore coverage output 79f73f8

v1.0.2 - 2021-02-22

Commits

  • [Tests] migrate tests to Github Actions a3f50f7
  • [meta] do not publish github action workflow files eb5c787
  • [Tests] add implementation est; run es-shim-api in postlint; use tape runner c9dd792
  • [Tests] fix native tests 6b76dff
  • [Tests] run nyc on all tests 0407f79
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, tape, browserify b8cc020
  • [actions] add "Allow Edits" workflow e2854df
  • [readme] remove travis badge 262eb76
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog; add safe-publish-latest 3c76883
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, tape 7276123
  • [actions] update workflows bcb0f42
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape 5485851
  • [Dev Deps] update auto-changelog, tape 6a01da3
  • [Dev Deps] update @ljharb/eslint-config, tape 7a07f4e
  • [meta] only run the build script in publish 797e492
  • [meta] combine duplicate prepublish scripts 92bbef0
  • [Dev Deps] update auto-changelog; add aud be6dbec
  • [actions] switch Automatic Rebase workflow to pull_request_target event bfd54f8
  • [Tests] only audit prod deps 0f64b47

v1.0.1 - 2019-12-15

Fixed

  • [Refactor] only use global in node; only check browser globals in browsers #2

Commits

  • [Tests] use shared travis-ci configs edb1cc9
  • [Tests] remove jscs 1847ac2
  • [meta] add auto-changelog 933c381
  • [Dev Deps] update eslint, @ljharb/eslint-config, browserify, tape 93310bc
  • [actions] add automatic rebasing / merge commit blocking 231dec5
  • [Dev Deps] update eslint, @ljharb/eslint-config, browserify, covert, is, tape e50c1f6
  • [Tests] use npx aud instead of nsp or npm audit with hoops 4abd340
  • [meta] add funding field 2d1f9eb
  • [meta] remove unused deps 5bd6bef
  • readme: Fix casing + phrasing 66379cc
  • [Deps] update define-properties, object-keys 4585e5a
  • fix issue with Webpack's CaseSensitivePathsPlugin 842e84e

v1.0.0 - 2018-08-10

Commits

  • Dotfiles. f01b02d
  • [Tests] up to node v10.7, v9.11, v8.11, v7.10, v6.14, v4.9; use nvm install-latest-npm; improve matrix ed1fa5d
  • Tests ab99527
  • [breaking] update property name, rename repo be42e3d
  • package.json ca43a36
  • implementation 80b5a40
  • read me f6df9b3
  • Rename System.global to global fa8503c
  • Initial commit 99f1dc3
  • [Tests] up to node v6.7, v5.12, v4.6; improve test matrix 712ec0e
  • [Dev Deps] update browserify, tape, jscs, nsp, eslint, @ljharb/eslint-config 73278bd
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, browserify, eslint, for-each, is, nsp, tape 75fa992
  • [Dev Deps] update browserify, is, tape, nsp, eslint b223e86
  • [Tests] fix linting; remove parallelshell 271b329
  • [Deps] update function-bind, object-keys 002d0c5
  • Only apps should have lockfiles 960f1d0
  • [Tests] on node v10.8 37fad9d
  • [Dev Deps] update eslint, @ljharb/eslint-config df28dfe
  • [New] add auto entry point 86eb2ab
  • [Dev Deps] update eslint 1bdc1aa
  • [Deps] update object-keys 72cdbf5
  • Update most common usage to invoke the function upon being required 5026296