@thi.ng/memoize 3.1.45 → 3.1.46
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 +1 -1
- package/api.js +0 -1
- package/defonce.js +4 -15
- package/do-once.js +11 -15
- package/memoize.js +8 -7
- package/memoize1.js +9 -18
- package/memoizej.js +12 -11
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/defonce.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
const cache = {};
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* `factory` to produce the singleton value and caches it. Returns
|
|
7
|
-
* singleton value.
|
|
8
|
-
*
|
|
9
|
-
* Note: All created values will remain in the private cache until the
|
|
10
|
-
* JS process terminates or this module itself has been reloaded (though
|
|
11
|
-
* the latter shouldn't happen in an HMR workflow).
|
|
12
|
-
*
|
|
13
|
-
* @param id -
|
|
14
|
-
* @param factory -
|
|
15
|
-
*/
|
|
16
|
-
export const defonce = (id, factory) => cache.hasOwnProperty(id) ? cache[id] : (cache[id] = factory());
|
|
2
|
+
const defonce = (id, factory) => cache.hasOwnProperty(id) ? cache[id] : cache[id] = factory();
|
|
3
|
+
export {
|
|
4
|
+
defonce
|
|
5
|
+
};
|
package/do-once.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
cache.set(x, true);
|
|
13
|
-
fn(x);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
1
|
+
const doOnce = (fn, cache) => {
|
|
2
|
+
!cache && (cache = /* @__PURE__ */ new Map());
|
|
3
|
+
return (x) => {
|
|
4
|
+
if (!cache.has(x)) {
|
|
5
|
+
cache.set(x, true);
|
|
6
|
+
fn(x);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
doOnce
|
|
16
12
|
};
|
package/memoize.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
: (cache.set(args, (res = fn.apply(null, args))), res);
|
|
7
|
-
};
|
|
1
|
+
function memoize(fn, cache) {
|
|
2
|
+
return (...args) => {
|
|
3
|
+
let res;
|
|
4
|
+
return cache.has(args) ? cache.get(args) : (cache.set(args, res = fn.apply(null, args)), res);
|
|
5
|
+
};
|
|
8
6
|
}
|
|
7
|
+
export {
|
|
8
|
+
memoize
|
|
9
|
+
};
|
package/memoize1.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export const memoize1 = (fn, cache) => {
|
|
12
|
-
!cache && (cache = new Map());
|
|
13
|
-
return (x) => {
|
|
14
|
-
let res;
|
|
15
|
-
return cache.has(x)
|
|
16
|
-
? cache.get(x)
|
|
17
|
-
: (cache.set(x, (res = fn(x))), res);
|
|
18
|
-
};
|
|
1
|
+
const memoize1 = (fn, cache) => {
|
|
2
|
+
!cache && (cache = /* @__PURE__ */ new Map());
|
|
3
|
+
return (x) => {
|
|
4
|
+
let res;
|
|
5
|
+
return cache.has(x) ? cache.get(x) : (cache.set(x, res = fn(x)), res);
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
memoize1
|
|
19
10
|
};
|
package/memoizej.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return fn.apply(null, args);
|
|
11
|
-
};
|
|
1
|
+
function memoizeJ(fn, cache) {
|
|
2
|
+
!cache && (cache = {});
|
|
3
|
+
return (...args) => {
|
|
4
|
+
const key = JSON.stringify(args);
|
|
5
|
+
if (key !== void 0) {
|
|
6
|
+
return key in cache ? cache[key] : cache[key] = fn.apply(null, args);
|
|
7
|
+
}
|
|
8
|
+
return fn.apply(null, args);
|
|
9
|
+
};
|
|
12
10
|
}
|
|
11
|
+
export {
|
|
12
|
+
memoizeJ
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/memoize",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.46",
|
|
4
4
|
"description": "Function memoization with configurable caching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,10 +35,11 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
38
|
+
"@thi.ng/api": "^8.9.12"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@microsoft/api-extractor": "^7.38.3",
|
|
42
|
+
"esbuild": "^0.19.8",
|
|
40
43
|
"rimraf": "^5.0.5",
|
|
41
44
|
"tools": "^0.0.1",
|
|
42
45
|
"typedoc": "^0.25.4",
|
|
@@ -87,5 +90,5 @@
|
|
|
87
90
|
],
|
|
88
91
|
"year": 2018
|
|
89
92
|
},
|
|
90
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
91
94
|
}
|