@common.js/quick-lru 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @common.js/quick-lru
2
+
3
+ The [quick-lru](https://www.npmjs.com/package/quick-lru) package exported as CommonJS modules.
4
+
5
+ Exported from [quick-lru@6.1.1](https://www.npmjs.com/package/quick-lru/v/6.1.1) using https://github.com/etienne-martin/common.js.
package/index.d.ts ADDED
@@ -0,0 +1,123 @@
1
+ export interface Options<KeyType, ValueType> {
2
+ /**
3
+ The maximum number of milliseconds an item should remain in the cache.
4
+
5
+ @default Infinity
6
+
7
+ By default, `maxAge` will be `Infinity`, which means that items will never expire.
8
+ Lazy expiration upon the next write or read call.
9
+
10
+ Individual expiration of an item can be specified by the `set(key, value, maxAge)` method.
11
+ */
12
+ readonly maxAge?: number;
13
+
14
+ /**
15
+ The maximum number of items before evicting the least recently used items.
16
+ */
17
+ readonly maxSize: number;
18
+
19
+ /**
20
+ Called right before an item is evicted from the cache.
21
+
22
+ Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
23
+ */
24
+ onEviction?: (key: KeyType, value: ValueType) => void;
25
+ }
26
+
27
+ export default class QuickLRU<KeyType, ValueType> extends Map implements Iterable<[KeyType, ValueType]> {
28
+ /**
29
+ The stored item count.
30
+ */
31
+ readonly size: number;
32
+
33
+ /**
34
+ Simple ["Least Recently Used" (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29).
35
+
36
+ The instance is an [`Iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) of `[key, value]` pairs so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
37
+
38
+ @example
39
+ ```
40
+ import QuickLRU from 'quick-lru';
41
+
42
+ const lru = new QuickLRU({maxSize: 1000});
43
+
44
+ lru.set('πŸ¦„', '🌈');
45
+
46
+ lru.has('πŸ¦„');
47
+ //=> true
48
+
49
+ lru.get('πŸ¦„');
50
+ //=> '🌈'
51
+ ```
52
+ */
53
+ constructor(options: Options<KeyType, ValueType>);
54
+
55
+ [Symbol.iterator](): IterableIterator<[KeyType, ValueType]>;
56
+
57
+ /**
58
+ Set an item. Returns the instance.
59
+
60
+ Individual expiration of an item can be specified with the `maxAge` option. If not specified, the global `maxAge` value will be used in case it is specified in the constructor, otherwise the item will never expire.
61
+
62
+ @returns The list instance.
63
+ */
64
+ set(key: KeyType, value: ValueType, options?: {maxAge?: number}): this;
65
+
66
+ /**
67
+ Get an item.
68
+
69
+ @returns The stored item or `undefined`.
70
+ */
71
+ get(key: KeyType): ValueType | undefined;
72
+
73
+ /**
74
+ Check if an item exists.
75
+ */
76
+ has(key: KeyType): boolean;
77
+
78
+ /**
79
+ Get an item without marking it as recently used.
80
+
81
+ @returns The stored item or `undefined`.
82
+ */
83
+ peek(key: KeyType): ValueType | undefined;
84
+
85
+ /**
86
+ Delete an item.
87
+
88
+ @returns `true` if the item is removed or `false` if the item doesn't exist.
89
+ */
90
+ delete(key: KeyType): boolean;
91
+
92
+ /**
93
+ Delete all items.
94
+ */
95
+ clear(): void;
96
+
97
+ /**
98
+ Update the `maxSize` in-place, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.
99
+
100
+ Useful for on-the-fly tuning of cache sizes in live systems.
101
+ */
102
+ resize(maxSize: number): void;
103
+
104
+ /**
105
+ Iterable for all the keys.
106
+ */
107
+ keys(): IterableIterator<KeyType>;
108
+
109
+ /**
110
+ Iterable for all the values.
111
+ */
112
+ values(): IterableIterator<ValueType>;
113
+
114
+ /**
115
+ Iterable for all entries, starting with the oldest (ascending in recency).
116
+ */
117
+ entriesAscending(): IterableIterator<[KeyType, ValueType]>;
118
+
119
+ /**
120
+ Iterable for all entries, starting with the newest (descending in recency).
121
+ */
122
+ entriesDescending(): IterableIterator<[KeyType, ValueType]>;
123
+ }