Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
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.
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
core-js is a modular standard library for JavaScript, which includes polyfills for ECMAScript up to the latest standards. It provides more comprehensive polyfills than globalthis, including polyfills for `globalThis`. It is more feature-rich but also larger in size compared to the focused functionality of globalthis.
es6-shim is a shim that provides compatibility shims so that legacy JavaScript engines behave as closely as possible to ECMAScript 6 (Harmony). It includes a polyfill for `globalThis` among many other features. Like core-js, it is more extensive than globalthis but also more heavyweight.
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
v1.0.1 - 2019-12-15
global
in node; only check browser globals in browsers #2
edb1cc9
jscs
1847ac2
auto-changelog
933c381
eslint
, @ljharb/eslint-config
, browserify
, tape
93310bc
231dec5
eslint
, @ljharb/eslint-config
, browserify
, covert
, is
, tape
e50c1f6
npx aud
instead of nsp
or npm audit
with hoops 4abd340
funding
field 2d1f9eb
5bd6bef
66379cc
define-properties
, object-keys
4585e5a
842e84e
FAQs
ECMAScript spec-compliant polyfill/shim for `globalThis`
The npm package globalthis receives a total of 21,342,744 weekly downloads. As such, globalthis popularity was classified as popular.
We found that globalthis demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.