@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 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
- return setProperty(acc, targetPath, value);
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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orioro/util",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "packageManager": "yarn@4.0.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",