8b900fbf5f73566bc3be976cdc620b98daa9040091073aebb943954a3954de4cc88a2a80717d54252f3ab722f8f0c478714a22fc73b03475f4d8b5f3cb42e0 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # internal-slot <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. Truly private storage, akin to the JS spec’s concept of internal slots.
  10. Uses a WeakMap when available; a Map when not; and a regular object in even older engines. Performance and garbage collection behavior will reflect the environment’s capabilities accordingly.
  11. ## Example
  12. ```js
  13. var SLOT = require('internal-slot');
  14. var assert = require('assert');
  15. var o = {};
  16. assert.throws(function () { SLOT.assert(o, 'foo'); });
  17. assert.equal(SLOT.has(o, 'foo'), false);
  18. assert.equal(SLOT.get(o, 'foo'), undefined);
  19. SLOT.set(o, 'foo', 42);
  20. assert.equal(SLOT.has(o, 'foo'), true);
  21. assert.equal(SLOT.get(o, 'foo'), 42);
  22. assert.doesNotThrow(function () { SLOT.assert(o, 'foo'); });
  23. ```
  24. ## Tests
  25. Simply clone the repo, `npm install`, and run `npm test`
  26. ## Security
  27. Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
  28. [package-url]: https://npmjs.org/package/internal-slot
  29. [npm-version-svg]: https://versionbadg.es/ljharb/internal-slot.svg
  30. [deps-svg]: https://david-dm.org/ljharb/internal-slot.svg
  31. [deps-url]: https://david-dm.org/ljharb/internal-slot
  32. [dev-deps-svg]: https://david-dm.org/ljharb/internal-slot/dev-status.svg
  33. [dev-deps-url]: https://david-dm.org/ljharb/internal-slot#info=devDependencies
  34. [npm-badge-png]: https://nodei.co/npm/internal-slot.png?downloads=true&stars=true
  35. [license-image]: https://img.shields.io/npm/l/internal-slot.svg
  36. [license-url]: LICENSE
  37. [downloads-image]: https://img.shields.io/npm/dm/internal-slot.svg
  38. [downloads-url]: https://npm-stat.com/charts.html?package=internal-slot
  39. [codecov-image]: https://codecov.io/gh/ljharb/internal-slot/branch/main/graphs/badge.svg
  40. [codecov-url]: https://app.codecov.io/gh/ljharb/internal-slot/
  41. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/internal-slot
  42. [actions-url]: https://github.com/ljharb/internal-slot/actions