Socket
Socket
Sign inDemoInstall

globalthis

Package Overview
Dependencies
12
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    globalthis

ECMAScript spec-compliant polyfill/shim for `globalThis`


Version published
Weekly downloads
25M
increased by2.1%
Maintainers
1
Install size
154 kB
Created
Weekly downloads
 

Package description

What is globalthis?

The globalthis npm package provides a polyfill for the global `globalThis` object, which is a standard way to access the global object (e.g., `window` in browsers, `global` in Node.js) in a universal manner across different JavaScript environments. This package ensures that you can reliably use `globalThis` in environments where it might not be natively supported.

What are globalthis's main functionalities?

Polyfill for globalThis

This code snippet demonstrates how to polyfill the global `globalThis` object using the globalthis package. After requiring and invoking the package, you can reliably use `globalThis` in your code to refer to the global object.

require('globalthis')(); // This will polyfill globalThis if it doesn't exist

Other packages similar to globalthis

Changelog

Source

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

Readme

Source

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

Keywords

FAQs

Last updated on 07 May 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc