expiry-set
Version:
A Set implementation with expirable keys
70 lines (38 loc) • 1.27 kB
Markdown
[](https://travis-ci.org/SamVerschueren/expiry-set) [](https://codecov.io/gh/SamVerschueren/expiry-set)
> A [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) implementation with expirable keys
```
$ npm install expiry-set
```
```js
import ExpirySet from 'expiry-set';
const set = new ExpirySet(1000, [
'unicorn'
]);
set.has('unicorn');
//=> true
set.add('rainbow');
console.log(set.size);
//=> 2
// Wait for 1 second...
set.has('unicorn');
//=> false
console.log(set.size);
//=> 0
```
Type: `number`
Milliseconds until a key in the `Set` expires.
Type: `Object`
An `Array` or other `iterable` object.
Any of the [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) methods.
- [expiry-map](https://github.com/SamVerschueren/expiry-map) - A `Map` implementation with expirable items
MIT © [Sam Verschueren](https://github.com/SamVerschueren)