租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.7 KiB

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