CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
README.md72 linesDownload Raw Back to get-intrinsic
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## Example17 18```js19var GetIntrinsic = require('get-intrinsic');20var assert = require('assert');21 22// static methods23assert.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 methods30var 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 features45delete JSON.parse; // to simulate a real intrinsic that is missing in the environment46assert.throws(() => GetIntrinsic('%JSON.parse%'));47assert.equal(undefined, GetIntrinsic('%JSON.parse%', true));48```49 50## Tests51Simply clone the repo, `npm install`, and run `npm test`52 53## Security54 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-intrinsic58[npm-version-svg]: https://versionbadg.es/ljharb/get-intrinsic.svg59[deps-svg]: https://david-dm.org/ljharb/get-intrinsic.svg60[deps-url]: https://david-dm.org/ljharb/get-intrinsic61[dev-deps-svg]: https://david-dm.org/ljharb/get-intrinsic/dev-status.svg62[dev-deps-url]: https://david-dm.org/ljharb/get-intrinsic#info=devDependencies63[npm-badge-png]: https://nodei.co/npm/get-intrinsic.png?downloads=true&stars=true64[license-image]: https://img.shields.io/npm/l/get-intrinsic.svg65[license-url]: LICENSE66[downloads-image]: https://img.shields.io/npm/dm/get-intrinsic.svg67[downloads-url]: https://npm-stat.com/charts.html?package=get-intrinsic68[codecov-image]: https://codecov.io/gh/ljharb/get-intrinsic/branch/main/graphs/badge.svg69[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-intrinsic71[actions-url]: https://github.com/ljharb/get-intrinsic/actions72