@thi.ng/resolve-map 7.0.0 → 7.1.0
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 +7 -1
- package/README.md +15 -1
- package/index.d.ts +16 -8
- package/index.js +3 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-07-
|
|
3
|
+
- **Last updated**: 2022-07-12T19:50:54Z
|
|
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.
|
|
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
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
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 (
|
|
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.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "DAG resolution of vanilla objects & arrays with internally linked values",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
],
|
|
77
77
|
"year": 2018
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "21abd94ba9e13d4636f3e9a85d3a7d4e9ea269ba\n"
|
|
80
80
|
}
|