@orioro/util 0.4.0 → 0.5.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/dist/index.mjs +8 -2
- package/dist/pickPaths/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -384,9 +384,15 @@ function pickPaths(sourceObj, paths) {
|
|
|
384
384
|
return paths.reduce(function (acc, path) {
|
|
385
385
|
var _a = Array.isArray(path) ? path : [path, path],
|
|
386
386
|
targetPath = _a[0],
|
|
387
|
-
resolver = _a[1]
|
|
387
|
+
resolver = _a[1],
|
|
388
|
+
defaultValue = _a[2];
|
|
388
389
|
var value = typeof resolver === 'string' ? getProperty(sourceObj, resolver) : resolver(sourceObj);
|
|
389
|
-
|
|
390
|
+
var valueAfterDefault = typeof value === 'undefined' ? defaultValue : value;
|
|
391
|
+
//
|
|
392
|
+
// Undefined values are skipped in order to avoid nested
|
|
393
|
+
// setting undefined values
|
|
394
|
+
//
|
|
395
|
+
return typeof valueAfterDefault !== 'undefined' ? setProperty(acc, targetPath, valueAfterDefault) : acc;
|
|
390
396
|
}, {});
|
|
391
397
|
}
|
|
392
398
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
type Resolver = string | ((sourceObj: Record<string, any>) => any);
|
|
2
|
-
type PathSpec = string | [string, Resolver];
|
|
2
|
+
type PathSpec = string | [string, Resolver, any?];
|
|
3
3
|
export declare function pickPaths(sourceObj: Record<string, any>, paths: PathSpec[]): Record<string, any>;
|
|
4
4
|
export {};
|