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

61 lines
2.1 KiB

2 months ago
6 months ago
2 months ago
  1. # side-channel <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. Uses WeakMap if available.
  8. Warning: in an environment that lacks `WeakMap`, this implementation will leak memory until you `delete` the `key`.
  9. ## Getting started
  10. ```sh
  11. npm install --save side-channel
  12. ```
  13. ## Usage/Examples
  14. ```js
  15. const assert = require('assert');
  16. const getSideChannel = require('side-channel');
  17. const channel = getSideChannel();
  18. const key = {};
  19. assert.equal(channel.has(key), false);
  20. assert.throws(() => channel.assert(key), TypeError);
  21. channel.set(key, 42);
  22. channel.assert(key); // does not throw
  23. assert.equal(channel.has(key), true);
  24. assert.equal(channel.get(key), 42);
  25. channel.delete(key);
  26. assert.equal(channel.has(key), false);
  27. assert.throws(() => channel.assert(key), TypeError);
  28. ```
  29. ## Tests
  30. Clone the repo, `npm install`, and run `npm test`
  31. [package-url]: https://npmjs.org/package/side-channel
  32. [npm-version-svg]: https://versionbadg.es/ljharb/side-channel.svg
  33. [deps-svg]: https://david-dm.org/ljharb/side-channel.svg
  34. [deps-url]: https://david-dm.org/ljharb/side-channel
  35. [dev-deps-svg]: https://david-dm.org/ljharb/side-channel/dev-status.svg
  36. [dev-deps-url]: https://david-dm.org/ljharb/side-channel#info=devDependencies
  37. [npm-badge-png]: https://nodei.co/npm/side-channel.png?downloads=true&stars=true
  38. [license-image]: https://img.shields.io/npm/l/side-channel.svg
  39. [license-url]: LICENSE
  40. [downloads-image]: https://img.shields.io/npm/dm/side-channel.svg
  41. [downloads-url]: https://npm-stat.com/charts.html?package=side-channel
  42. [codecov-image]: https://codecov.io/gh/ljharb/side-channel/branch/main/graphs/badge.svg
  43. [codecov-url]: https://app.codecov.io/gh/ljharb/side-channel/
  44. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/side-channel
  45. [actions-url]: https://github.com/ljharb/side-channel/actions