Giter Site home page Giter Site logo

expire-set's Introduction

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 ExpiredSet
  • set.all: Returns the ExpiredSet as a normal Set
  • set.add(value): Adds a value to the ExpiredSet, returning itself
  • set.has(value): Returns true/false, if the ExpiredSet has the value
  • set.delete(value): Deletes a value of the ExpiredSet, returning itself

expire-set's People

Contributors

sorunome avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.