@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -68,7 +68,7 @@ For Node.js REPL:
68
68
  const memoize = await import("@thi.ng/memoize");
69
69
  ```
70
70
 
71
- Package sizes (brotli'd, pre-treeshake): ESM: 248 bytes
71
+ Package sizes (brotli'd, pre-treeshake): ESM: 247 bytes
72
72
 
73
73
  ## Dependencies
74
74
 
package/api.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/defonce.js CHANGED
@@ -1,16 +1,5 @@
1
1
  const cache = {};
2
- /**
3
- * Lightweight named singleton factory, intended for hot-module
4
- * replacement situations. Takes a (preferably globally unique) `id` and
5
- * `factory` function. If there's no value defined for `id` yet, calls
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
- * Similar to {@link memoize1}, however optimized for side effects only, i.e.
3
- * functions which DO NOT return any result.
4
- *
5
- * @param fn -
6
- * @param cache -
7
- */
8
- export const doOnce = (fn, cache) => {
9
- !cache && (cache = new Map());
10
- return (x) => {
11
- if (!cache.has(x)) {
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
- export function memoize(fn, cache) {
2
- return (...args) => {
3
- let res;
4
- return cache.has(args)
5
- ? cache.get(args)
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
- * Optimized memoization for single arg functions. If the function expects args
3
- * other than strings or numbers, you MUST provide a `Map` implementation which
4
- * supports value (rather than object) equality, e.g. one of those provided by
5
- * [`thi.ng/associative`](https://thi.ng/associative). Using a native `Map` type
6
- * here will lead to memory leaks! Alternatively, use {@link memoizeJ}.
7
- *
8
- * @param fn -
9
- * @param cache -
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
- export function memoizeJ(fn, cache) {
2
- !cache && (cache = {});
3
- return (...args) => {
4
- const key = JSON.stringify(args);
5
- if (key !== undefined) {
6
- return key in cache
7
- ? cache[key]
8
- : (cache[key] = fn.apply(null, args));
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.45",
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 clean && tsc --declaration",
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.11"
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": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
93
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
91
94
  }