expiry-map
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.0 • Public • Published

    expiry-map

    Build Status Coverage Status

    A Map implementation with expirable items

    Memory is automatically released when an item expires by removing it from the Map.

    Install

    $ npm install expiry-map
    

    Usage

    import ExpiryMap from 'expiry-map';
     
    const map = new ExpiryMap(1000, [
        ['unicorn', '🦄']
    ]);
     
    map.get('unicorn');
    //=> 🦄
     
    map.set('rainbow', '🌈');
     
    console.log(map.size);
    //=> 2
     
    // Wait for 1 second...
    map.get('unicorn');
    //=> undefined
     
    console.log(map.size);
    //=> 0

    API

    ExpiryMap(maxAge, [iterable])

    maxAge

    Type: number

    Milliseconds until an item in the Map expires.

    iterable

    Type: Object

    An Array or other iterable object whose elements are key-value pairs.

    Instance

    Any of the Map methods.

    Related

    License

    MIT © Sam Verschueren

    Install

    npm i expiry-map

    DownloadsWeekly Downloads

    570

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    6.6 kB

    Total Files

    5

    Last publish

    Collaborators

    • samverschueren