[d565449] | 1 | # internal-slot <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 |
|
---|
| 12 | Truly private storage, akin to the JS spec’s concept of internal slots.
|
---|
| 13 |
|
---|
| 14 | 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.
|
---|
| 15 |
|
---|
| 16 | ## Example
|
---|
| 17 |
|
---|
| 18 | ```js
|
---|
| 19 | var SLOT = require('internal-slot');
|
---|
| 20 | var assert = require('assert');
|
---|
| 21 |
|
---|
| 22 | var o = {};
|
---|
| 23 |
|
---|
| 24 | assert.throws(function () { SLOT.assert(o, 'foo'); });
|
---|
| 25 |
|
---|
| 26 | assert.equal(SLOT.has(o, 'foo'), false);
|
---|
| 27 | assert.equal(SLOT.get(o, 'foo'), undefined);
|
---|
| 28 |
|
---|
| 29 | SLOT.set(o, 'foo', 42);
|
---|
| 30 |
|
---|
| 31 | assert.equal(SLOT.has(o, 'foo'), true);
|
---|
| 32 | assert.equal(SLOT.get(o, 'foo'), 42);
|
---|
| 33 |
|
---|
| 34 | assert.doesNotThrow(function () { SLOT.assert(o, 'foo'); });
|
---|
| 35 | ```
|
---|
| 36 |
|
---|
| 37 | ## Tests
|
---|
| 38 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
| 39 |
|
---|
| 40 | ## Security
|
---|
| 41 |
|
---|
| 42 | Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
|
---|
| 43 |
|
---|
| 44 | [package-url]: https://npmjs.org/package/internal-slot
|
---|
| 45 | [npm-version-svg]: https://versionbadg.es/ljharb/internal-slot.svg
|
---|
| 46 | [deps-svg]: https://david-dm.org/ljharb/internal-slot.svg
|
---|
| 47 | [deps-url]: https://david-dm.org/ljharb/internal-slot
|
---|
| 48 | [dev-deps-svg]: https://david-dm.org/ljharb/internal-slot/dev-status.svg
|
---|
| 49 | [dev-deps-url]: https://david-dm.org/ljharb/internal-slot#info=devDependencies
|
---|
| 50 | [npm-badge-png]: https://nodei.co/npm/internal-slot.png?downloads=true&stars=true
|
---|
| 51 | [license-image]: https://img.shields.io/npm/l/internal-slot.svg
|
---|
| 52 | [license-url]: LICENSE
|
---|
| 53 | [downloads-image]: https://img.shields.io/npm/dm/internal-slot.svg
|
---|
| 54 | [downloads-url]: https://npm-stat.com/charts.html?package=internal-slot
|
---|
| 55 | [codecov-image]: https://codecov.io/gh/ljharb/internal-slot/branch/main/graphs/badge.svg
|
---|
| 56 | [codecov-url]: https://app.codecov.io/gh/ljharb/internal-slot/
|
---|
| 57 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/internal-slot
|
---|
| 58 | [actions-url]: https://github.com/ljharb/internal-slot/actions
|
---|