@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/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@common.js/quick-lru",
3
+ "version": "6.1.1",
4
+ "description": "Simple “Least Recently Used” (LRU) cache",
5
+ "license": "MIT",
6
+ "repository": "etienne-martin/common.js",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "type": "commonjs",
9
+ "engines": {
10
+ "node": ">=12"
11
+ },
12
+ "scripts": {
13
+ "//test": "xo && nyc ava && tsd",
14
+ "test": "xo && ava && tsd"
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "index.d.ts"
19
+ ],
20
+ "devDependencies": {
21
+ "ava": "^3.15.0",
22
+ "nyc": "^15.1.0",
23
+ "tsd": "^0.14.0",
24
+ "xo": "^0.37.1"
25
+ },
26
+ "nyc": {
27
+ "reporter": [
28
+ "text",
29
+ "lcov"
30
+ ]
31
+ },
32
+ "homepage": "https://github.com/etienne-martin/common.js#readme",
33
+ "dependencies": {},
34
+ "main": "./index.js"
35
+ }
package/readme.md ADDED
@@ -0,0 +1,157 @@
1
+ # quick-lru [![Coverage Status](https://codecov.io/gh/sindresorhus/quick-lru/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/quick-lru/branch/main)
2
+
3
+ > Simple [“Least Recently Used” (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29)
4
+
5
+ Useful when you need to cache something and limit memory usage.
6
+
7
+ Inspired by the [`hashlru` algorithm](https://github.com/dominictarr/hashlru#algorithm), but instead uses [`Map`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) to support keys of any type, not just strings, and values can be `undefined`.
8
+
9
+ ## Install
10
+
11
+ ```
12
+ $ npm install quick-lru
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import QuickLRU from 'quick-lru';
19
+
20
+ const lru = new QuickLRU({maxSize: 1000});
21
+
22
+ lru.set('🦄', '🌈');
23
+
24
+ lru.has('🦄');
25
+ //=> true
26
+
27
+ lru.get('🦄');
28
+ //=> '🌈'
29
+ ```
30
+
31
+ ## API
32
+
33
+ ### new QuickLRU(options?)
34
+
35
+ Returns a new instance.
36
+
37
+ It's a [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) subclass.
38
+
39
+ ### options
40
+
41
+ Type: `object`
42
+
43
+ #### maxSize
44
+
45
+ *Required*\
46
+ Type: `number`
47
+
48
+ The maximum number of items before evicting the least recently used items.
49
+
50
+ #### maxAge
51
+
52
+ Type: `number`\
53
+ Default: `Infinity`
54
+
55
+ The maximum number of milliseconds an item should remain in cache.
56
+ By default maxAge will be Infinity, which means that items will never expire.
57
+
58
+ Lazy expiration happens upon the next `write` or `read` call.
59
+
60
+ Individual expiration of an item can be specified by the `set(key, value, options)` method.
61
+
62
+ #### onEviction
63
+
64
+ *Optional*\
65
+ Type: `(key, value) => void`
66
+
67
+ Called right before an item is evicted from the cache.
68
+
69
+ Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
70
+
71
+ ### Instance
72
+
73
+ 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.
74
+
75
+ Both `key` and `value` can be of any type.
76
+
77
+ #### .set(key, value, options?)
78
+
79
+ Set an item. Returns the instance.
80
+
81
+ 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 on the constructor, otherwise the item will never expire.
82
+
83
+ #### .get(key)
84
+
85
+ Get an item.
86
+
87
+ #### .has(key)
88
+
89
+ Check if an item exists.
90
+
91
+ #### .peek(key)
92
+
93
+ Get an item without marking it as recently used.
94
+
95
+ #### .delete(key)
96
+
97
+ Delete an item.
98
+
99
+ Returns `true` if the item is removed or `false` if the item doesn't exist.
100
+
101
+ #### .clear()
102
+
103
+ Delete all items.
104
+
105
+ #### .resize(maxSize)
106
+
107
+ Update the `maxSize`, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.
108
+
109
+ Useful for on-the-fly tuning of cache sizes in live systems.
110
+
111
+ #### .keys()
112
+
113
+ Iterable for all the keys.
114
+
115
+ #### .values()
116
+
117
+ Iterable for all the values.
118
+
119
+ #### .entriesAscending()
120
+
121
+ Iterable for all entries, starting with the oldest (ascending in recency).
122
+
123
+ #### .entriesDescending()
124
+
125
+ Iterable for all entries, starting with the newest (descending in recency).
126
+
127
+ #### .entries()
128
+
129
+ Iterable for all entries, starting with the newest (ascending in recency).
130
+
131
+ **This method exists for `Map` compatibility. Prefer [.entriesAscending()](#entriesascending) instead.**
132
+
133
+ #### .forEach(callbackFunction, thisArgument)
134
+
135
+ Loop over entries calling the `callbackFunction` for each entry (ascending in recency).
136
+
137
+ **This method exists for `Map` compatibility. Prefer [.entriesAscending()](#entriesascending) instead.**
138
+
139
+ #### .size
140
+
141
+ The stored item count.
142
+
143
+ ## Related
144
+
145
+ - [yocto-queue](https://github.com/sindresorhus/yocto-queue) - Tiny queue data structure
146
+
147
+ ---
148
+
149
+ <div align="center">
150
+ <b>
151
+ <a href="https://tidelift.com/subscription/pkg/npm-quick-lru?utm_source=npm-quick-lru&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
152
+ </b>
153
+ <br>
154
+ <sub>
155
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
156
+ </sub>
157
+ </div>