1 | # map-age-cleaner
|
2 |
|
3 | ![CI](https://github.com/SamVerschueren/map-age-cleaner/workflows/CI/badge.svg) [![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
|
18 | import mapAgeCleaner = require('map-age-cleaner');
|
19 |
|
20 | const map = new Map([
|
21 | ['unicorn', {data: '🦄', maxAge: Date.now() + 1000}]
|
22 | ]);
|
23 |
|
24 | mapAgeCleaner(map);
|
25 |
|
26 | map.has('unicorn');
|
27 | //=> true
|
28 |
|
29 | // Wait for 1 second...
|
30 |
|
31 | map.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 |
|
42 | Returns the `Map` instance.
|
43 |
|
44 | #### map
|
45 |
|
46 | Type: `Map`
|
47 |
|
48 | Map instance which should be cleaned up.
|
49 |
|
50 | #### property
|
51 |
|
52 | Type: `string`<br>
|
53 | Default: `maxAge`
|
54 |
|
55 | Name 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 |
|
67 | MIT © [Sam Verschueren](https://github.com/SamVerschueren)
|
68 |
|
69 |
|
70 | ---
|
71 |
|
72 | <div align="center">
|
73 | <b>
|
74 | <a href="https://tidelift.com/subscription/pkg/npm-map-age-cleaner?utm_source=npm-map-age-cleaner&utm_medium=referral&utm_campaign=enterprise">Get professional support for this package with a Tidelift subscription</a>
|
75 | </b>
|
76 | <br>
|
77 | <sub>
|
78 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
79 | </sub>
|
80 | </div>
|