@thi.ng/resolve-map 7.0.0 → 7.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-07-07T13:36:28Z
3
+ - **Last updated**: 2022-08-01T14:54:00Z
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.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [7.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/resolve-map@7.1.0) (2022-07-12)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add `onlyFnRefs` option ([a23fc98](https://github.com/thi-ng/umbrella/commit/a23fc98))
17
+
12
18
  # [7.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/resolve-map@7.0.0) (2022-07-07)
13
19
 
14
20
  #### 🛑 Breaking changes
package/README.md CHANGED
@@ -76,7 +76,7 @@ node --experimental-repl-await
76
76
  > const resolveMap = await import("@thi.ng/resolve-map");
77
77
  ```
78
78
 
79
- Package sizes (gzipped, pre-treeshake): ESM: 1.11 KB
79
+ Package sizes (gzipped, pre-treeshake): ESM: 1.13 KB
80
80
 
81
81
  ## Dependencies
82
82
 
@@ -320,6 +320,20 @@ res.b.deref()
320
320
  // 42
321
321
  ```
322
322
 
323
+ Since v7.1.0 a new `onlyFnRefs` option has been added which changes the
324
+ resolution behavior to **not** consider string values for resolution at all
325
+ anymore and instead requires the use of function values to trigger resolution.
326
+
327
+ ```ts
328
+ // default behavior
329
+ resolve({ a: "@c", b: ({a}) => a, c: 42 })
330
+ // { a: 42, b: 42, c: 42 }
331
+
332
+ // with option enabled
333
+ resolve({ a: "@c", b: ({a}) => a, c: 42 }, { onlyFnRefs: true })
334
+ // { a: '@c', b: '@c', c: 42 }
335
+ ```
336
+
323
337
  ## Authors
324
338
 
325
339
  Karsten Schmidt
package/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare type LookupPath = NumOrString[];
7
7
  export interface ResolveOpts {
8
8
  /**
9
9
  * Prefix for auto-recognizing & interpreting embedded string values as
10
- * lookup paths.
10
+ * lookup paths (only if {@link ResolveOpts.onlyFnRefs} is false, default)
11
11
  *
12
12
  * @defaultValue `@`
13
13
  */
@@ -19,6 +19,11 @@ export interface ResolveOpts {
19
19
  * @defaultValue true
20
20
  */
21
21
  unwrap: boolean;
22
+ /**
23
+ * If true, only function values (not strings!) will be considered for
24
+ * resolution.
25
+ */
26
+ onlyFnRefs: boolean;
22
27
  }
23
28
  /**
24
29
  * Visits all key-value pairs or array items in depth-first order, expands any
@@ -35,14 +40,17 @@ export interface ResolveOpts {
35
40
  * access any parent levels. Absolute refs are always resolved from the root
36
41
  * level (the original object passed to this function).
37
42
  *
38
- * Values can be protected from further resolution attempts by wrapping them via
39
- * {@link resolved}. By default (unless `unwrap` is set to `false`), these
40
- * wrapped values are only used during the resolution phase and the final result
41
- * object/array will only contain the original, unwrapped values. In any way,
42
- * unwrapped values will also be supplied to any lookup functions, no `.deref()`
43
- * necessary there.
43
+ * Values can be protected from (further) resolution attempts in two ways:
44
+ *
45
+ * 1) by wrapping them via {@link resolved}. By default (unless `unwrap` is set
46
+ * to `false`), these wrapped values are only used during the resolution
47
+ * phase and the final result object/array will only contain the original,
48
+ * unwrapped values. In any way, unwrapped values will also be supplied to
49
+ * any lookup functions, no `.deref()` necessary there.
50
+ * 2) Enabling the `onlyFnRefs` option, only function values will be considered
51
+ * for resolution and strings (regardless of prefix) will be ignored.
44
52
  *
45
- * See {@link ResolveOpts} for further details.
53
+ * See {@link ResolveOpts} and package readme for further details.
46
54
  *
47
55
  * @example
48
56
  * ```ts
package/index.js CHANGED
@@ -68,7 +68,9 @@ const _resolve = (root, path, resolved, stack, opts) => {
68
68
  else if (isArray(v)) {
69
69
  resolveArray(v, { ...opts, unwrap: false }, root, path, resolved, stack);
70
70
  }
71
- else if (isString(v) && v.startsWith(opts.prefix)) {
71
+ else if (!opts.onlyFnRefs &&
72
+ isString(v) &&
73
+ v.startsWith(opts.prefix)) {
72
74
  res = _resolve(root, absPath(path, v, opts.prefix.length), resolved, stack, opts);
73
75
  }
74
76
  else if (isFunction(v)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/resolve-map",
3
- "version": "7.0.0",
3
+ "version": "7.1.2",
4
4
  "description": "DAG resolution of vanilla objects & arrays with internally linked values",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,18 +34,18 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.3.7",
38
- "@thi.ng/checks": "^3.2.1",
39
- "@thi.ng/errors": "^2.1.7",
40
- "@thi.ng/paths": "^5.1.8"
37
+ "@thi.ng/api": "^8.3.9",
38
+ "@thi.ng/checks": "^3.2.3",
39
+ "@thi.ng/errors": "^2.1.9",
40
+ "@thi.ng/paths": "^5.1.10"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.25.0",
44
- "@thi.ng/testament": "^0.2.8",
44
+ "@thi.ng/testament": "^0.2.10",
45
45
  "rimraf": "^3.0.2",
46
46
  "tools": "^0.0.1",
47
47
  "typedoc": "^0.22.17",
48
- "typescript": "^4.7.3"
48
+ "typescript": "^4.7.4"
49
49
  },
50
50
  "keywords": [
51
51
  "configuration",
@@ -76,5 +76,5 @@
76
76
  ],
77
77
  "year": 2018
78
78
  },
79
- "gitHead": "4c4aeb0672852c319408c92b56444a5e42826996\n"
79
+ "gitHead": "976ccd698cedaa60dcef2e69030a5eb98898cc4a\n"
80
80
  }