source: imaps-frontend/node_modules/get-intrinsic/README.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.7 KB
Line 
1# get-intrinsic <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
3[![github actions][actions-image]][actions-url]
4[![coverage][codecov-image]][codecov-url]
5[![dependency status][deps-svg]][deps-url]
6[![dev dependency status][dev-deps-svg]][dev-deps-url]
7[![License][license-image]][license-url]
8[![Downloads][downloads-image]][downloads-url]
9
10[![npm badge][npm-badge-png]][package-url]
11
12Get and robustly cache all JS language-level intrinsics at first require time.
13
14See the syntax described [in the JS spec](https://tc39.es/ecma262/#sec-well-known-intrinsic-objects) for reference.
15
16## Example
17
18```js
19var GetIntrinsic = require('get-intrinsic');
20var assert = require('assert');
21
22// static methods
23assert.equal(GetIntrinsic('%Math.pow%'), Math.pow);
24assert.equal(Math.pow(2, 3), 8);
25assert.equal(GetIntrinsic('%Math.pow%')(2, 3), 8);
26delete Math.pow;
27assert.equal(GetIntrinsic('%Math.pow%')(2, 3), 8);
28
29// instance methods
30var arr = [1];
31assert.equal(GetIntrinsic('%Array.prototype.push%'), Array.prototype.push);
32assert.deepEqual(arr, [1]);
33
34arr.push(2);
35assert.deepEqual(arr, [1, 2]);
36
37GetIntrinsic('%Array.prototype.push%').call(arr, 3);
38assert.deepEqual(arr, [1, 2, 3]);
39
40delete Array.prototype.push;
41GetIntrinsic('%Array.prototype.push%').call(arr, 4);
42assert.deepEqual(arr, [1, 2, 3, 4]);
43
44// missing features
45delete JSON.parse; // to simulate a real intrinsic that is missing in the environment
46assert.throws(() => GetIntrinsic('%JSON.parse%'));
47assert.equal(undefined, GetIntrinsic('%JSON.parse%', true));
48```
49
50## Tests
51Simply clone the repo, `npm install`, and run `npm test`
52
53## Security
54
55Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
56
57[package-url]: https://npmjs.org/package/get-intrinsic
58[npm-version-svg]: https://versionbadg.es/ljharb/get-intrinsic.svg
59[deps-svg]: https://david-dm.org/ljharb/get-intrinsic.svg
60[deps-url]: https://david-dm.org/ljharb/get-intrinsic
61[dev-deps-svg]: https://david-dm.org/ljharb/get-intrinsic/dev-status.svg
62[dev-deps-url]: https://david-dm.org/ljharb/get-intrinsic#info=devDependencies
63[npm-badge-png]: https://nodei.co/npm/get-intrinsic.png?downloads=true&stars=true
64[license-image]: https://img.shields.io/npm/l/get-intrinsic.svg
65[license-url]: LICENSE
66[downloads-image]: https://img.shields.io/npm/dm/get-intrinsic.svg
67[downloads-url]: https://npm-stat.com/charts.html?package=get-intrinsic
68[codecov-image]: https://codecov.io/gh/ljharb/get-intrinsic/branch/main/graphs/badge.svg
69[codecov-url]: https://app.codecov.io/gh/ljharb/get-intrinsic/
70[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/get-intrinsic
71[actions-url]: https://github.com/ljharb/get-intrinsic/actions
Note: See TracBrowser for help on using the repository browser.