1.0.6 • Published 6 years ago
@kingjs/descriptor.nested.for-each v1.0.6
@kingjs/descriptor.nested.for-each
Invoke a callback for each path.
Usage
Create a new descriptor with pet names for property names like this:
'use strict';
var forEach = require('@kingjs/descriptor.nested.for-each');
var values = {
alice: {
pet: { name: 'tiger' }
},
bob: {
pet: { name: 'snuggles' }
},
chris: {
pet: { name: 'spike' }
},
}
var result = { };
forEach(values, {
'*': {
pet: {
name: null
}
}
}, o => result[o] = true);
result
result:
{
tiger: true,
snuggles: true,
spike: true
}
API
declare function forEach(
tree: NestedDescriptor,
paths: NestedDescriptor,
callback: (leaf, path) => any,
thisArg?
): void
Interfaces
NestedDescriptor
: see @kingjs/descriptor/nested
Parameters
tree
: The tree whose nodes will be frozen.paths
: The paths of the tree to pass to thecallback
.callback
: Used to updatepaths
oftree
:leaf
: The leaf value.path
: The path value.
thisArg
: Thethis
argument to pass tocallback
.
Install
With npm installed, run
$ npm install @kingjs/descriptor.nested.for-each
License
MIT