Socket
Socket
Sign inDemoInstall

get-intrinsic

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-intrinsic

Get and robustly cache all JS language-level intrinsics at first require time


Version published
Maintainers
1
Created

What is get-intrinsic?

The get-intrinsic package is a utility that allows you to safely obtain references to ECMAScript language intrinsics without relying on the global namespace, which can be altered by other code. It helps in writing robust code that doesn't get affected by modifications to the global objects or functions.

What are get-intrinsic's main functionalities?

Getting intrinsic values

This feature allows you to get the original intrinsic value of Array.prototype.push, which can then be used to push elements to arrays without relying on Array.prototype.push being unmodified.

var getIntrinsic = require('get-intrinsic');
var ArrayPrototypePush = getIntrinsic('%Array.prototype.push%');
var anArray = [1, 2, 3];
ArrayPrototypePush(anArray, 4); // anArray becomes [1, 2, 3, 4]

Accessing deep intrinsics

This feature allows you to access deep intrinsic properties like Object.prototype.hasOwnProperty, which can be used to check for properties without relying on the original method being unaltered.

var getIntrinsic = require('get-intrinsic');
var hasOwn = getIntrinsic('%Object.prototype.hasOwnProperty%');
var hasDuck = hasOwn.call({ duck: 'quack' }, 'duck'); // hasDuck is true

Ensuring unmodified constructors

This feature allows you to use the original Array constructor to create new arrays, ensuring that the constructor has not been modified in the global scope.

var getIntrinsic = require('get-intrinsic');
var ArrayConstructor = getIntrinsic('%Array%');
var myArray = new ArrayConstructor(1, 2, 3); // myArray is [1, 2, 3]

Other packages similar to get-intrinsic

Keywords

FAQs

Package last updated on 30 Oct 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc