@thi.ng/resolve-map 6.1.2 → 6.2.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 +11 -1
- package/README.md +6 -5
- package/index.d.ts +4 -3
- package/index.js +29 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-
|
|
3
|
+
- **Last updated**: 2022-07-07T12:39:33Z
|
|
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,16 @@ 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
|
+
## [6.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/resolve-map@6.2.0) (2022-07-07)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- unwrap all resolved() values in result ([888fa33](https://github.com/thi-ng/umbrella/commit/888fa33))
|
|
17
|
+
- add unwrapResolved() to unwrap any values wrapped via `resolved()`
|
|
18
|
+
- update resolveMap/Array()
|
|
19
|
+
- update doc strings
|
|
20
|
+
- update tests
|
|
21
|
+
|
|
12
22
|
## [6.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/resolve-map@6.1.0) (2022-05-23)
|
|
13
23
|
|
|
14
24
|
#### 🚀 Features
|
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.08 KB
|
|
80
80
|
|
|
81
81
|
## Dependencies
|
|
82
82
|
|
|
@@ -302,10 +302,11 @@ res.e(2);
|
|
|
302
302
|
|
|
303
303
|
Values can be protected from further resolution attempts by wrapping them via
|
|
304
304
|
[`resolved()`](https://docs.thi.ng/umbrella/resolve-map/modules.html#resolved).
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
`.deref()` necessary
|
|
305
|
+
These wrapped values are only used during the resolution phase and the final
|
|
306
|
+
result object/array will only contain the original, unwrapped values. Unwrapped
|
|
307
|
+
values will also be supplied to any lookup functions, no
|
|
308
|
+
[`.deref()`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html) necessary
|
|
309
|
+
there.
|
|
309
310
|
|
|
310
311
|
## Authors
|
|
311
312
|
|
package/index.d.ts
CHANGED
|
@@ -20,9 +20,10 @@ export declare type LookupPath = NumOrString[];
|
|
|
20
20
|
* level (the original object passed to this function).
|
|
21
21
|
*
|
|
22
22
|
* Values can be protected from further resolution attempts by wrapping them via
|
|
23
|
-
* {@link resolved}.
|
|
24
|
-
*
|
|
25
|
-
* unwrapped
|
|
23
|
+
* {@link resolved}. These wrapped values are only used during the resolution
|
|
24
|
+
* phase and the final result object/array will only contain the original,
|
|
25
|
+
* unwrapped values. Unwrapped values will also be supplied to any lookup
|
|
26
|
+
* functions, no `.deref()` necessary there.
|
|
26
27
|
*
|
|
27
28
|
* @example
|
|
28
29
|
* ```ts
|
package/index.js
CHANGED
|
@@ -16,19 +16,21 @@ export function resolve(root, prefix = "@") {
|
|
|
16
16
|
}
|
|
17
17
|
return root;
|
|
18
18
|
}
|
|
19
|
+
/** @internal */
|
|
19
20
|
const resolveMap = (obj, prefix, root, path = [], resolved = {}, stack = []) => {
|
|
20
21
|
root = root || obj;
|
|
21
22
|
for (let k in obj) {
|
|
22
23
|
_resolve(root, [...path, k], resolved, stack, prefix);
|
|
23
24
|
}
|
|
24
|
-
return obj;
|
|
25
|
+
return path.length ? obj : unwrapResolved(obj, resolved);
|
|
25
26
|
};
|
|
27
|
+
/** @internal */
|
|
26
28
|
const resolveArray = (arr, prefix, root, path = [], resolved = {}, stack = []) => {
|
|
27
29
|
root = root || arr;
|
|
28
30
|
for (let k = 0, n = arr.length; k < n; k++) {
|
|
29
31
|
_resolve(root, [...path, k], resolved, stack, prefix);
|
|
30
32
|
}
|
|
31
|
-
return arr;
|
|
33
|
+
return path.length ? arr : unwrapResolved(arr, resolved);
|
|
32
34
|
};
|
|
33
35
|
/**
|
|
34
36
|
* The actual recursive resolution mechanism. Takes root object, key
|
|
@@ -40,6 +42,8 @@ const resolveArray = (arr, prefix, root, path = [], resolved = {}, stack = []) =
|
|
|
40
42
|
* @param path -
|
|
41
43
|
* @param resolved -
|
|
42
44
|
* @param stack -
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
43
47
|
*/
|
|
44
48
|
const _resolve = (root, path, resolved, stack, prefix) => {
|
|
45
49
|
const pathID = path.join("/");
|
|
@@ -95,6 +99,8 @@ const _resolve = (root, path, resolved, stack, prefix) => {
|
|
|
95
99
|
* @param root -
|
|
96
100
|
* @param path -
|
|
97
101
|
* @param resolved -
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
98
104
|
*/
|
|
99
105
|
const resolvePath = (root, path, resolved, stack, prefix) => {
|
|
100
106
|
// temporarily remove current path to avoid cycle detection
|
|
@@ -123,6 +129,8 @@ const resolvePath = (root, path, resolved, stack, prefix) => {
|
|
|
123
129
|
* @param resolve -
|
|
124
130
|
* @param pathID - current base path for marking
|
|
125
131
|
* @param resolved -
|
|
132
|
+
*
|
|
133
|
+
* @internal
|
|
126
134
|
*/
|
|
127
135
|
const resolveFunction = (fn, resolve, pathID, resolved) => {
|
|
128
136
|
const match = RE_ARGS.exec(fn.toString());
|
|
@@ -142,6 +150,7 @@ const resolveFunction = (fn, resolve, pathID, resolved) => {
|
|
|
142
150
|
markResolved(res, pathID, resolved);
|
|
143
151
|
return res;
|
|
144
152
|
};
|
|
153
|
+
/** @internal */
|
|
145
154
|
const markResolved = (v, path, resolved) => {
|
|
146
155
|
resolved[path] = true;
|
|
147
156
|
if (isPlainObject(v)) {
|
|
@@ -151,6 +160,7 @@ const markResolved = (v, path, resolved) => {
|
|
|
151
160
|
markArrayResolved(v, path, resolved);
|
|
152
161
|
}
|
|
153
162
|
};
|
|
163
|
+
/** @internal */
|
|
154
164
|
const markObjResolved = (obj, path, resolved) => {
|
|
155
165
|
let v, p;
|
|
156
166
|
for (let k in obj) {
|
|
@@ -159,6 +169,7 @@ const markObjResolved = (obj, path, resolved) => {
|
|
|
159
169
|
markResolved(v, p, resolved);
|
|
160
170
|
}
|
|
161
171
|
};
|
|
172
|
+
/** @internal */
|
|
162
173
|
const markArrayResolved = (arr, path, resolved) => {
|
|
163
174
|
let v, p;
|
|
164
175
|
for (let i = 0, n = arr.length; i < n; i++) {
|
|
@@ -237,3 +248,19 @@ const getInUnsafe = (obj, path) => {
|
|
|
237
248
|
}
|
|
238
249
|
return [res, isResolved];
|
|
239
250
|
};
|
|
251
|
+
/**
|
|
252
|
+
* Unwraps all known values wrapped using {@link Resolved} in-place.
|
|
253
|
+
*
|
|
254
|
+
* @param root
|
|
255
|
+
* @param resolved
|
|
256
|
+
*
|
|
257
|
+
* @internal
|
|
258
|
+
*/
|
|
259
|
+
const unwrapResolved = (root, resolved) => {
|
|
260
|
+
for (let path in resolved) {
|
|
261
|
+
const $path = path.split("/");
|
|
262
|
+
const val = getInUnsafe(root, $path);
|
|
263
|
+
val[1] && mutInUnsafe(root, $path, val[0]);
|
|
264
|
+
}
|
|
265
|
+
return root;
|
|
266
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/resolve-map",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.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": "04acabdda49dfcfe8cdcf044401f25ce23c872d0\n"
|
|
80
80
|
}
|