@omni-tools/map-age-cleaner
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-alpha.1 • Public • Published

map-age-cleaner

Npm Version Build Status codecov

Automatically cleanup expired items in a Map

📢 This is a fork of @SamVerschueren map-age-cleaner, to be used for @omni-tools/mem

So far its still kind of experiment, but It might end up to be merged 🙂

Install

$ npm install @omni-tools/map-age-cleaner

Usage

import mapAgeCleaner from '@omni-tools/map-age-cleaner';

const map = new Map([
	['unicorn', {data: '🦄', maxAge: Date.now() + 1000}]
]);

mapAgeCleaner(map);

map.has('unicorn'); //=> true

// Wait for 1 second... 😴

map.has('unicorn'); //=> false

API

mapAgeCleaner(map, [options={property?,onExpire?}])

Returns the Map instance.

  • map: Map instance which should be cleaned up. (Type: Map)
  • options: object containing eventualy the two options possible
    • property: Name of the property which olds the expiry timestamp. (Type: string, Default: maxAge)
    • onExpire: Handler to be called with expired object on expiration. (Type: (key, value) => void, Default: undefined) takes the key and value of expired item as argument

Related

  • expiry-map - A Map implementation with expirable items
  • expiry-set - A Set implementation with expirable keys
  • mem - Memoize functions

License

MIT © Sam Verschueren

Package Sidebar

Install

npm i @omni-tools/map-age-cleaner

Weekly Downloads

0

Version

1.0.0-alpha.1

License

MIT

Unpacked Size

10.2 kB

Total Files

5

Last publish

Collaborators

  • adriean.khisbe