@thi.ng/memoize 4.0.0 → 4.0.2
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/CHANGELOG.md +1 -1
- package/README.md +22 -10
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
## About
|
|
32
32
|
|
|
33
|
-
Function memoization with configurable caching.
|
|
33
|
+
Function memoization with configurable caching and support for async functions.
|
|
34
34
|
|
|
35
35
|
This package provides different function memoization implementations for
|
|
36
36
|
functions with arbitrary arguments and custom result caching using ES6
|
|
@@ -48,10 +48,10 @@ based on different strategies. See doc strings for further details.
|
|
|
48
48
|
- [defOnce()](https://docs.thi.ng/umbrella/memoize/functions/defOnce.html)
|
|
49
49
|
- [delay()](https://docs.thi.ng/umbrella/memoize/functions/delay.html)
|
|
50
50
|
- [doOnce()](https://docs.thi.ng/umbrella/memoize/functions/doOnce.html)
|
|
51
|
-
- [memoize()](https://docs.thi.ng/umbrella/memoize/functions/memoize.html)
|
|
52
|
-
- [memoize1()](https://docs.thi.ng/umbrella/memoize/functions/memoize1.html)
|
|
53
|
-
- [memoizeJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeJ.html)
|
|
54
|
-
- [memoizeO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeO.html)
|
|
51
|
+
- [memoize()](https://docs.thi.ng/umbrella/memoize/functions/memoize.html) / [memoizeAsync()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsync.html)
|
|
52
|
+
- [memoize1()](https://docs.thi.ng/umbrella/memoize/functions/memoize1.html) / [memoizeAsync1()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsync1.html)
|
|
53
|
+
- [memoizeJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeJ.html) / [memoizeAsyncJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsyncJ.html)
|
|
54
|
+
- [memoizeO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeO.html) / [memoizeAsyncO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsyncO.html)
|
|
55
55
|
|
|
56
56
|
## Status
|
|
57
57
|
|
|
@@ -126,7 +126,10 @@ import { LRUCache } from "@thi.ng/cache";
|
|
|
126
126
|
```ts
|
|
127
127
|
import { memoize1 } from "@thi.ng/memoize";
|
|
128
128
|
|
|
129
|
-
foo = memoize1((x) =>
|
|
129
|
+
foo = memoize1((x: number) => {
|
|
130
|
+
console.log("exec");
|
|
131
|
+
return x * 10;
|
|
132
|
+
});
|
|
130
133
|
|
|
131
134
|
foo(1);
|
|
132
135
|
// exec
|
|
@@ -138,7 +141,7 @@ import { EquivMap } from "@thi.ng/associative";
|
|
|
138
141
|
|
|
139
142
|
// with custom cache
|
|
140
143
|
foo = memoize1(
|
|
141
|
-
(x) => (console.log("exec"), x[0] * 10),
|
|
144
|
+
(x: number[]) => (console.log("exec"), x[0] * 10),
|
|
142
145
|
// custom ES6 Map impl which compares by value, not by reference
|
|
143
146
|
new EquivMap()
|
|
144
147
|
);
|
|
@@ -148,6 +151,7 @@ foo([1]);
|
|
|
148
151
|
// 10
|
|
149
152
|
|
|
150
153
|
// would be a cache miss w/ native ES6 Map
|
|
154
|
+
// due to lack of value equality semantics
|
|
151
155
|
foo([1]);
|
|
152
156
|
// 10
|
|
153
157
|
|
|
@@ -155,7 +159,7 @@ import { LRUCache } from "@thi.ng/cache";
|
|
|
155
159
|
|
|
156
160
|
// use LRU cache to limit cache size
|
|
157
161
|
foo = memoize1(
|
|
158
|
-
(x) => (console.log("exec"), x[0] * 10),
|
|
162
|
+
(x: number[]) => (console.log("exec"), x[0] * 10),
|
|
159
163
|
new LRUCache(null, { maxlen: 3 })
|
|
160
164
|
);
|
|
161
165
|
```
|
|
@@ -167,7 +171,10 @@ import { memoize } from "@thi.ng/memoize";
|
|
|
167
171
|
import { EquivMap } from "@thi.ng/associative";
|
|
168
172
|
|
|
169
173
|
const dotProduct = memoize(
|
|
170
|
-
(x
|
|
174
|
+
(x: number[], y: number[]) => {
|
|
175
|
+
console.log("exec");
|
|
176
|
+
return x[0] * y[0] + x[1] * y[1];
|
|
177
|
+
},
|
|
171
178
|
new EquivMap()
|
|
172
179
|
);
|
|
173
180
|
|
|
@@ -184,11 +191,16 @@ dotProduct([1,2], [3,4]);
|
|
|
184
191
|
import { memoizeJ } from "@thi.ng/memoize";
|
|
185
192
|
|
|
186
193
|
const dotProduct = memoizeJ(
|
|
187
|
-
(x
|
|
194
|
+
(x: number[], y: number[]) => {
|
|
195
|
+
console.log("exec");
|
|
196
|
+
return x[0] * y[0] + x[1] * y[1];
|
|
197
|
+
}
|
|
188
198
|
);
|
|
199
|
+
|
|
189
200
|
dotProduct([1, 2], [3, 4]);
|
|
190
201
|
// exec
|
|
191
202
|
// 11
|
|
203
|
+
|
|
192
204
|
dotProduct([1, 2], [3, 4]);
|
|
193
205
|
// 11
|
|
194
206
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/memoize",
|
|
3
|
-
"version": "4.0.
|
|
4
|
-
"description": "Function memoization with configurable caching",
|
|
3
|
+
"version": "4.0.2",
|
|
4
|
+
"description": "Function memoization with configurable caching and support for async functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
7
7
|
"typings": "./index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
29
|
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
30
30
|
"clean": "bun ../../tools/src/clean-package.ts",
|
|
31
|
-
"doc": "typedoc --
|
|
31
|
+
"doc": "typedoc --options ../../typedoc.json --out doc src/index.ts",
|
|
32
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
33
33
|
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
34
34
|
"pub": "yarn npm publish --access public",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
39
|
+
"@thi.ng/api": "^8.11.12"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@microsoft/api-extractor": "^7.47.9",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"typescript": "^5.6.2"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|
|
48
|
+
"async",
|
|
48
49
|
"cache",
|
|
49
50
|
"functional",
|
|
50
51
|
"memoization",
|
|
@@ -95,5 +96,5 @@
|
|
|
95
96
|
],
|
|
96
97
|
"year": 2018
|
|
97
98
|
},
|
|
98
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "ef89090bb19fc5bca23be5da8cfce05b82ff4ad1\n"
|
|
99
100
|
}
|