@checkdigit/memoize 4.0.0 → 4.0.1-PR.17-b2c0
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/dist-mjs/memoize.mjs +4 -2
- package/package.json +1 -61
- package/src/memoize.ts +6 -3
package/dist-mjs/memoize.mjs
CHANGED
|
@@ -37,7 +37,9 @@ var memoize_default = (memoizableFunction) => {
|
|
|
37
37
|
}
|
|
38
38
|
throw new TypeError(`Object argument cannot be memoized`);
|
|
39
39
|
}
|
|
40
|
-
case "number":
|
|
40
|
+
case "number": {
|
|
41
|
+
return Number.isFinite(value2) ? value2 : `${seed}:number:${value2}`;
|
|
42
|
+
}
|
|
41
43
|
case "boolean":
|
|
42
44
|
case "string": {
|
|
43
45
|
return value2;
|
|
@@ -63,4 +65,4 @@ var memoize_default = (memoizableFunction) => {
|
|
|
63
65
|
export {
|
|
64
66
|
memoize_default as default
|
|
65
67
|
};
|
|
66
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
68
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL21lbW9pemUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBZ0NBLElBQU8sa0JBQVEsQ0FDYix1QkFDMEM7QUFDMUMsUUFBTSxRQUFRLG9CQUFJLElBQTZCO0FBQy9DLFFBQU0sVUFBVSxvQkFBSSxJQUFvQjtBQUl4QyxRQUFNLE9BQU8sT0FBTyxXQUFXO0FBRS9CLFNBQU8sSUFBSSxpQkFBaUI7QUFDMUIsVUFBTSxPQUFPLG9CQUFJLElBQVk7QUFFN0IsVUFBTSxZQUFZLEtBQUssVUFBVSxjQUFjLENBQUMsS0FBS0EsV0FBb0I7QUFFdkUsV0FBSyxJQUFJLEdBQUc7QUFFWixjQUFRLE9BQU9BLFFBQU87QUFBQSxRQUNwQixLQUFLLFVBQVU7QUFDYixpQkFBTyxHQUFHLElBQUksSUFBSUE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BSSxFQUFFLFNBQVM7QUFBQSxJQUNyQjtBQUVBLFFBQUksUUFBUSxNQUFNLElBQUksUUFBUTtBQUM5QixRQUFJLFVBQVUsUUFBVztBQUN2QixjQUFRLG1CQUFtQixHQUFHLFlBQVk7QUFDMUMsWUFBTSxJQUFJLFVBQVUsS0FBSztBQUV6QixZQUFNLE1BQU0sTUFBTTtBQUVoQixjQUFNLE9BQU8sUUFBUTtBQUFBLE1BQ3ZCLENBQUM7QUFBQSxJQUNIO0FBQ0EsV0FBTztBQUFBLEVBQ1Q7QUFDRjsiLAogICJuYW1lcyI6IFsidmFsdWUiXQp9Cg==
|
package/package.json
CHANGED
|
@@ -1,61 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@checkdigit/memoize",
|
|
3
|
-
"version": "4.0.0",
|
|
4
|
-
"description": "Memoizing async functions with cache eviction on reject",
|
|
5
|
-
"homepage": "https://github.com/checkdigit/memoize#readme",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/checkdigit/memoize/issues"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/checkdigit/memoize.git"
|
|
12
|
-
},
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"author": "Check Digit, LLC",
|
|
15
|
-
"sideEffects": false,
|
|
16
|
-
"type": "module",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": {
|
|
19
|
-
"types": "./dist-types/index.d.ts",
|
|
20
|
-
"import": "./dist-mjs/index.mjs",
|
|
21
|
-
"default": "./dist-mjs/index.mjs"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"src",
|
|
26
|
-
"dist-types",
|
|
27
|
-
"dist-mjs",
|
|
28
|
-
"!src/**/*.test.ts",
|
|
29
|
-
"!src/**/*.spec.ts",
|
|
30
|
-
"!dist-types/**/*.test.d.ts",
|
|
31
|
-
"!dist-types/**/*.spec.d.ts",
|
|
32
|
-
"!dist-mjs/**/*.test.mjs",
|
|
33
|
-
"!dist-mjs/**/*.spec.mjs",
|
|
34
|
-
"SECURITY.md"
|
|
35
|
-
],
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build:dist-mjs": "node -e \"require('node:fs').rmSync('dist-mjs', { recursive: true, force: true })\" && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs",
|
|
38
|
-
"build:dist-types": "node -e \"require('node:fs').rmSync('dist-types', { recursive: true, force: true })\" && npx builder --type=types --outDir=dist-types",
|
|
39
|
-
"ci:compile": "tsc --noEmit",
|
|
40
|
-
"ci:coverage": "node -e \"const fs = require('node:fs'); fs.rmSync('coverage', { recursive: true, force: true }); fs.mkdirSync('coverage')\" && node --test-timeout 600000 --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"src/**/*.spec.ts\"",
|
|
41
|
-
"ci:lint": "npm run lint",
|
|
42
|
-
"ci:style": "npm run prettier",
|
|
43
|
-
"ci:test": "node --pending-deprecation --throw-deprecation --test-timeout 600000 --test \"src/**/*.spec.ts\"",
|
|
44
|
-
"coverage": "node --test-timeout 600000 --experimental-test-coverage --test \"src/**/*.spec.ts\"",
|
|
45
|
-
"lint": "eslint --max-warnings 0 .",
|
|
46
|
-
"lint:fix": "eslint . --fix",
|
|
47
|
-
"prepublishOnly": "npm run build:dist-types && npm run build:dist-mjs",
|
|
48
|
-
"prettier": "prettier . --check",
|
|
49
|
-
"prettier:fix": "prettier . --write",
|
|
50
|
-
"test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"
|
|
51
|
-
},
|
|
52
|
-
"prettier": "@checkdigit/prettier-config",
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@checkdigit/eslint-config": "^12.1.0",
|
|
55
|
-
"@checkdigit/prettier-config": "^8.1.1",
|
|
56
|
-
"@checkdigit/typescript-config": "^10.2.1"
|
|
57
|
-
},
|
|
58
|
-
"engines": {
|
|
59
|
-
"node": ">=24.18.0"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
{"name":"@checkdigit/memoize","version":"4.0.1-PR.17-b2c0","description":"Memoizing async functions with cache eviction on reject","homepage":"https://github.com/checkdigit/memoize#readme","bugs":{"url":"https://github.com/checkdigit/memoize/issues"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/memoize.git"},"license":"MIT","author":"Check Digit, LLC","sideEffects":false,"type":"module","exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"build:dist-mjs":"node -e \"require('node:fs').rmSync('dist-mjs', { recursive: true, force: true })\" && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","build:dist-types":"node -e \"require('node:fs').rmSync('dist-types', { recursive: true, force: true })\" && npx builder --type=types --outDir=dist-types","ci:compile":"tsc --noEmit","ci:coverage":"node -e \"const fs = require('node:fs'); fs.rmSync('coverage', { recursive: true, force: true }); fs.mkdirSync('coverage')\" && node --test-timeout 600000 --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"src/**/*.spec.ts\"","ci:lint":"npm run lint","ci:style":"npm run prettier","ci:test":"node --pending-deprecation --throw-deprecation --test-timeout 600000 --test \"src/**/*.spec.ts\"","coverage":"node --test-timeout 600000 --experimental-test-coverage --test \"src/**/*.spec.ts\"","lint":"eslint --max-warnings 0 .","lint:fix":"eslint . --fix","prepublishOnly":"npm run build:dist-types && npm run build:dist-mjs","prettier":"prettier . --check","prettier:fix":"prettier . --write","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"},"prettier":"@checkdigit/prettier-config","devDependencies":{"@checkdigit/eslint-config":"^12.3.0","@checkdigit/prettier-config":"^8.4.0","@checkdigit/typescript-config":"^10.2.2"},"engines":{"node":">=24.21.0"}}
|
package/src/memoize.ts
CHANGED
|
@@ -36,7 +36,7 @@ export default <Arguments extends Argument[], Return>(
|
|
|
36
36
|
const cache = new Map<string, Promise<Return>>();
|
|
37
37
|
const symbols = new Map<symbol, string>();
|
|
38
38
|
|
|
39
|
-
// use a random seed
|
|
39
|
+
// use a random seed to distinguish encoded values from ordinary strings
|
|
40
40
|
// eslint-disable-next-line @checkdigit/no-random-v4-uuid
|
|
41
41
|
const seed = crypto.randomUUID();
|
|
42
42
|
|
|
@@ -47,7 +47,6 @@ export default <Arguments extends Argument[], Return>(
|
|
|
47
47
|
// create a set of all object keys used in the argument list
|
|
48
48
|
keys.add(key);
|
|
49
49
|
|
|
50
|
-
// convert BigInts, symbols and undefined to unique strings
|
|
51
50
|
switch (typeof value) {
|
|
52
51
|
case 'bigint': {
|
|
53
52
|
return `${seed}:${value}n`;
|
|
@@ -86,7 +85,11 @@ export default <Arguments extends Argument[], Return>(
|
|
|
86
85
|
throw new TypeError(`Object argument cannot be memoized`);
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
case 'number':
|
|
88
|
+
case 'number': {
|
|
89
|
+
// JSON.stringify would otherwise serialize all non-finite numbers as null
|
|
90
|
+
return Number.isFinite(value) ? value : `${seed}:number:${value}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
90
93
|
case 'boolean':
|
|
91
94
|
case 'string': {
|
|
92
95
|
return value;
|