https://github.com/lamansky/weakish-set
[Node.js] It’s like WeakSet but it supports non-objects.
https://github.com/lamansky/weakish-set
javascript nodejs nodejs-modules weakset
Last synced: 12 months ago
JSON representation
[Node.js] It’s like WeakSet but it supports non-objects.
- Host: GitHub
- URL: https://github.com/lamansky/weakish-set
- Owner: lamansky
- License: mit
- Created: 2017-11-28T11:27:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-10T17:50:46.000Z (over 7 years ago)
- Last Synced: 2024-10-30T04:43:49.413Z (over 1 year ago)
- Topics: javascript, nodejs, nodejs-modules, weakset
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# WeakishSet
It’s like WeakSet but it supports non-objects.
## Installation
Requires [Node.js](https://nodejs.org/) 6.0.0 or above.
```bash
npm i weakish-map
```
## API
The module exposes a single class.
### Constructor
The constructor supports the following arguments:
1. Optional: `items` (iterable): Initial key-value pairs for the Set.
2. Optional: Object argument:
* `StrongSet` (class): Set this if you have a custom Set class you want to use for storing non-objects. Defaults to the built-in `Set`.
* `WeakSet` (class): Set this if you have a custom WeakSet class you want to use for storing objects. Defaults to the built-in `WeakSet`.
### Methods
Instances of this class have the following methods, which behave just like the corresponding methods on `Set` and `WeakSet`:
* `has()`
* `add()`
* `delete()`
* `clear()`
Instances also have methods which only work on non-objects:
* `entries()`
* `forEach()`
* `values()`
## Example
```javascript
// Before
const set1 = new WeakSet()
set1.add({})
set1.add('test') // Uncaught TypeError: Invalid value used in weak set
// After
const WeakishSet = require('weakish-set')
const set2 = new WeakishSet()
set2.add({})
set2.add('test')
```
## Related
* [weakish-map](https://github.com/lamansky/weakish-map)