用工小程序前端代码
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.

62 lines
2.2 KiB

2 months ago
  1. # side-channel-map <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![License][license-image]][license-url]
  5. [![Downloads][downloads-image]][downloads-url]
  6. [![npm badge][npm-badge-png]][package-url]
  7. Store information about any JS value in a side channel, using a Map.
  8. Warning: if the `key` is an object, this implementation will leak memory until you `delete` it.
  9. Use [`side-channel`](https://npmjs.com/side-channel) for the best available strategy.
  10. ## Getting started
  11. ```sh
  12. npm install --save side-channel-map
  13. ```
  14. ## Usage/Examples
  15. ```js
  16. const assert = require('assert');
  17. const getSideChannelMap = require('side-channel-map');
  18. const channel = getSideChannelMap();
  19. const key = {};
  20. assert.equal(channel.has(key), false);
  21. assert.throws(() => channel.assert(key), TypeError);
  22. channel.set(key, 42);
  23. channel.assert(key); // does not throw
  24. assert.equal(channel.has(key), true);
  25. assert.equal(channel.get(key), 42);
  26. channel.delete(key);
  27. assert.equal(channel.has(key), false);
  28. assert.throws(() => channel.assert(key), TypeError);
  29. ```
  30. ## Tests
  31. Clone the repo, `npm install`, and run `npm test`
  32. [package-url]: https://npmjs.org/package/side-channel-map
  33. [npm-version-svg]: https://versionbadg.es/ljharb/side-channel-map.svg
  34. [deps-svg]: https://david-dm.org/ljharb/side-channel-map.svg
  35. [deps-url]: https://david-dm.org/ljharb/side-channel-map
  36. [dev-deps-svg]: https://david-dm.org/ljharb/side-channel-map/dev-status.svg
  37. [dev-deps-url]: https://david-dm.org/ljharb/side-channel-map#info=devDependencies
  38. [npm-badge-png]: https://nodei.co/npm/side-channel-map.png?downloads=true&stars=true
  39. [license-image]: https://img.shields.io/npm/l/side-channel-map.svg
  40. [license-url]: LICENSE
  41. [downloads-image]: https://img.shields.io/npm/dm/side-channel-map.svg
  42. [downloads-url]: https://npm-stat.com/charts.html?package=side-channel-map
  43. [codecov-image]: https://codecov.io/gh/ljharb/side-channel-map/branch/main/graphs/badge.svg
  44. [codecov-url]: https://app.codecov.io/gh/ljharb/side-channel-map/
  45. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/side-channel-map
  46. [actions-url]: https://github.com/ljharb/side-channel-map/actions