source: trip-planner-front/node_modules/map-age-cleaner/readme.md@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1# map-age-cleaner
2
3[![Build Status](https://travis-ci.org/SamVerschueren/map-age-cleaner.svg?branch=master)](https://travis-ci.org/SamVerschueren/map-age-cleaner) [![codecov](https://codecov.io/gh/SamVerschueren/map-age-cleaner/badge.svg?branch=master)](https://codecov.io/gh/SamVerschueren/map-age-cleaner?branch=master)
4
5> Automatically cleanup expired items in a Map
6
7
8## Install
9
10```
11$ npm install map-age-cleaner
12```
13
14
15## Usage
16
17```js
18import mapAgeCleaner from 'map-age-cleaner';
19
20const map = new Map([
21 ['unicorn', {data: '🦄', maxAge: Date.now() + 1000}]
22]);
23
24mapAgeCleaner(map);
25
26map.has('unicorn');
27//=> true
28
29// Wait for 1 second...
30
31map.has('unicorn');
32//=> false
33```
34
35> **Note**: Items have to be ordered ascending based on the expiry property. This means that the item which will be expired first, should be in the first position of the `Map`.
36
37
38## API
39
40### mapAgeCleaner(map, [property])
41
42Returns the `Map` instance.
43
44#### map
45
46Type: `Map`
47
48Map instance which should be cleaned up.
49
50#### property
51
52Type: `string`<br>
53Default: `maxAge`
54
55Name of the property which olds the expiry timestamp.
56
57
58## Related
59
60- [expiry-map](https://github.com/SamVerschueren/expiry-map) - A `Map` implementation with expirable items
61- [expiry-set](https://github.com/SamVerschueren/expiry-set) - A `Set` implementation with expirable keys
62- [mem](https://github.com/sindresorhus/mem) - Memoize functions
63
64
65## License
66
67MIT © [Sam Verschueren](https://github.com/SamVerschueren)
Note: See TracBrowser for help on using the repository browser.