1.0.9 • Published 7 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
): arrayInterfaces
NestedDescriptor: see @kingjs/descriptor/nested
Parameters
tree: A tree whose leaf values that correspond to a path inpathsare 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 inpathsis replicated with properties whose names correspond to properties oftreenot 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-arrayLicense
MIT