Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

get-intrinsic 1.2.4

Get and robustly cache all JS language-level intrinsics at first require time
Package summary
Package created
30 Oct 2020
Version published
6 Feb 2024
Total deps
Direct deps
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does get-intrinsic do?

The get-intrinsic npm package is a handy JavaScript tool that is designed to fetch and efficiently cache all JS language-level intrinsics when they are first required. Its architecture ensures the robust retrieval of these intrinsic objects, regardless of modifications or deletions that may take place within the runtime environment.

How do you use get-intrinsic?

To utilize the get-intrinsic package in your JavaScript files, you will first need to install it using the command npm install get-intrinsic. Once installed, it can be imported into your JS file with var GetIntrinsic = require('get-intrinsic').

Here's an illustrative code snippet showcasing its usage:

var GetIntrinsic = require('get-intrinsic');
var assert = require('assert');
// Retrieving static methods
assert.equal(GetIntrinsic('%Math.pow%'), Math.pow); // Fetches Math.pow method
assert.equal(Math.pow(2, 3), 8); // Normal use of Math.pow
assert.equal(GetIntrinsic('%Math.pow%')(2, 3), 8); // Use of fetched Math.pow
delete Math.pow;
assert.equal(GetIntrinsic('%Math.pow%')(2, 3), 8); // Continues to fetch Math.pow even after deleting it

// Retrieving instance methods
var arr = [1];
assert.equal(GetIntrinsic('%Array.prototype.push%'), Array.prototype.push); // Fetches Array.push method
GetIntrinsic('%Array.prototype.push%').call(arr, 3); // Use of fetched Array.push
delete Array.prototype.push;
GetIntrinsic('%Array.prototype.push%').call(arr, 4); // Continues to fetch Array.push even after deleting it

The package's robustness is apparent in its ability to continue fetching intrinsic methods even after the original methods have been removed from the environment.

Where are the get-intrinsic docs?

Currently, the primary source of documentation for the get-intrinsic package is the readme file provided on its GitHub page at https://github.com/ljharb/get-intrinsic. This readme contains vital information about the package, including a clear introduction to its purpose, examples of its use, as well as guidance on running tests. For the syntax referencing, users are guided to see the JS specification at https://tc39.es/ecma262/#sec-well-known-intrinsic-objects.