1.0.0 • Published 5 years ago
expire-set v1.0.0
expire-set
expire-set is a package that is basically a set - only that its values expire after a certain set time.
Usage
Just use it as if you would be using a normal set:
const ExpireSet = require("expire-set");
const timeout = 10000; // 10 seconds
const set = new ExpireSet(timeout);
set.add("fox");
console.log(set.has("fox")); // outputs true
setTimeout(() => {
console.log(set.has("fox")); // outputs false
}, timeout + 6); // the library needs some time to do its magic
You can also use it with typescript:
import ExpireSet from "expire-set";
const timeout = 10000; // 10 seconds
const set = new ExpireSet<string>(timeout);
set.add("blah");
set.delete("blah");
Methods
The following methods exist:
set.size
: Returns the size of the ExpiredSetset.all
: Returns the ExpiredSet as a normal Setset.add(value)
: Adds a value to the ExpiredSet, returning itselfset.has(value)
: Returns true/false, if the ExpiredSet has the valueset.delete(value)
: Deletes a value of the ExpiredSet, returning itself
1.0.0
5 years ago