1.0.9 • Published 5 years ago
@kingjs/descriptor.nested.to-array v1.0.9
@kingjs/descriptor.nested.to-array
Returns an array of leaf values that correspond to as set of paths.
Usage
Return an array of pet names like this:
var toArray = require('@kingjs/descriptor.nested.to-array');
var people = {
alice: {
pet: 'tiger'
},
bob: {
pet: 'snuggles'
},
chris: {
pet: 'spike'
}
}
var tree = {
'*': { pet: null }
}
toArray(people, tree);
result:
[ 'tiger', 'snuggles', 'spike' ]
API
declare function toArray(
tree: NestedDescriptor,
paths: NestedDescriptor
): array
Interfaces
NestedDescriptor
: see @kingjs/descriptor/nested
Parameters
tree
: A tree whose leaf values that correspond to a path inpaths
are returned in an array.paths
: Paths to search intree
. If the path is found, then it's value is included in the result array. Any property named'*'
found inpaths
is replicated with properties whose names correspond to properties oftree
not already present as siblings of'*'
.
Returns
Returns an array of values or null
if no values are found.
Install
With npm installed, run
$ npm install @kingjs/descriptor.nested.to-array
License
MIT