Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
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.4 - 2024-04-29
280d796
gopd
0209ccb
c08aea6
@es-shims/api
, @ljharb/eslint-config
, aud
, tape
f38f2af
aud
, tape
a1be102
define-properties
3e41644
define-properties
3d81f70
npmignore
dep c2d00f7
FAQs
ECMAScript spec-compliant polyfill/shim for `globalThis`
The npm package globalthis receives a total of 22,651,703 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.