1.3.2 • Published 8 months ago

@openally/ephemeral-map v1.3.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @openally/ephemeral-map
# or
$ yarn add @openally/ephemeral-map

Usage example

import EphemeralMap, { tSv } from "@openally/ephemeral-map";

const data = [
  ["hello", "world"]
];

// Note: ttl is not mandatory
const em = new EphemeralMap(data, { ttl: 500 });
em.on(EphemeralMap.Expired, (key, value) => {
  console.log(`Identifier '${key}' with value '${value}' has expired!`);
});

em.set(tSv({ ttl: 200 })("key"), "value");

API

EphemeralMap extend from a normal Map. By default the inner TimeStore set his ttl to 0 (which mean that no keys expire).

get ttl(): number

Read-only TTL. Return 0 if the class has no ttl.

emplace(key, handler)

Method inspired from the TC39 proposal to add an upsert method on Map.

static set

Add a pair (key, value) to a Map or EphemeralMap. If the first argument is a Map then the third argument is ignored.

const em = new EphemeralMap();

EphemeralMap.set(em, ["foo", "bar"], {
  ttl: 400
});

Events

The EphemeralMap EventEmitter broadcast two distinct events:

  • EphemeralMap.Expired (when a given identifier expire)
  • EphemeralMap.Renewed (when an identifier TTL is Renewed with add() method)

!WARNING Both value are JavaScript Symbols primitive

License

MIT

1.3.2

8 months ago

1.3.1

8 months ago

1.3.0

8 months ago

1.2.0

11 months ago

1.1.0

1 year ago

1.0.0

1 year ago