object-scan
Advanced tools
Comparing version 17.0.1 to 17.1.0
@@ -30,3 +30,3 @@ "use strict"; | ||
assert(typeof ctx.abort === 'boolean'); | ||
assert([undefined, 'context', 'key', 'value', 'entry', 'property', 'gproperty', 'parent', 'gparent', 'parents', 'isMatch', 'matchedBy', 'excludedBy', 'traversedBy', 'isCircular', 'isLeaf', 'depth', 'bool', 'count'].includes(ctx.rtn) || Array.isArray(ctx.rtn) && ctx.rtn.every(e => ['key', 'value', 'entry', 'property', 'gproperty', 'parent', 'gparent', 'parents', 'isMatch', 'matchedBy', 'excludedBy', 'traversedBy', 'isCircular', 'isLeaf', 'depth'].includes(e))); | ||
assert(typeof ctx.rtn === 'function' && ctx.rtn.length === 1 || [undefined, 'context', 'key', 'value', 'entry', 'property', 'gproperty', 'parent', 'gparent', 'parents', 'isMatch', 'matchedBy', 'excludedBy', 'traversedBy', 'isCircular', 'isLeaf', 'depth', 'bool', 'count'].includes(ctx.rtn) || Array.isArray(ctx.rtn) && ctx.rtn.every(e => ['key', 'value', 'entry', 'property', 'gproperty', 'parent', 'gparent', 'parents', 'isMatch', 'matchedBy', 'excludedBy', 'traversedBy', 'isCircular', 'isLeaf', 'depth'].includes(e))); | ||
assert(typeof ctx.joined === 'boolean'); | ||
@@ -33,0 +33,0 @@ assert(typeof ctx.useArraySelector === 'boolean'); |
@@ -33,5 +33,15 @@ "use strict"; | ||
return { | ||
onMatch: Array.isArray(ctx.rtn) ? () => result.push(ctx.rtn.map(rtn => kwargs[rtn])) : () => result.push(kwargs[ctx.rtn]), | ||
onMatch: (() => { | ||
if (typeof ctx.rtn === 'function') { | ||
return () => result.push(ctx.rtn(kwargs)); | ||
} | ||
if (Array.isArray(ctx.rtn)) { | ||
return () => result.push(ctx.rtn.map(rtn => kwargs[rtn])); | ||
} | ||
return () => result.push(kwargs[ctx.rtn]); | ||
})(), | ||
get: () => ctx.abort ? result[0] : result | ||
}; | ||
}; |
{ | ||
"name": "object-scan", | ||
"version": "17.0.1", | ||
"version": "17.1.0", | ||
"description": "Traverse object hierarchies using matching and callbacks.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -659,3 +659,3 @@ # Object-Scan | ||
Type: `string` or `array`<br> | ||
Type: `string` or `array` or `function`<br> | ||
Default: _dynamic_ | ||
@@ -685,6 +685,8 @@ | ||
Or, when set as an `array`, can contain any of the above except `context`, `bool` and `count`. | ||
When set to `array`, can contain any of the above except `context`, `bool` and `count`. | ||
When set to `function`, called with _callback_ signature for every match. Returned value is added to the result. | ||
When **abort** is set to `true` and the result would be a list, the first match or _undefined_ is returned. | ||
When **abort** is set to `true` and _rtn_ is not `context`, `bool` or `count`, | ||
the first entry of the result or _undefined_ is returned. | ||
@@ -755,3 +757,15 @@ _Examples_: | ||
</details> | ||
<details><summary> <code>['**']</code> <em>(return value plus one)</em> </summary> | ||
<!-- eslint-disable no-undef --> | ||
```js | ||
const haystack = { a: { b: { c: 0, d: 1 } } }; | ||
objectScan(['**'], { | ||
filterFn: ({ isLeaf }) => isLeaf, | ||
rtn: ({ value }) => value + 1 | ||
})(haystack); | ||
// => [ 2, 1 ] | ||
``` | ||
</details> | ||
#### joined | ||
@@ -758,0 +772,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64458
895
1094