1.0.4 • Published 6 years ago
@kingjs/descriptor.nested.array.update v1.0.4
@kingjs/descriptor.nested.array.update
Updates the values of a array tree to values returned by a callback which takes the current value.
Usage
Replace the name of the person followed with the object representing the person being followed like this:
var update = require('@kingjs/descriptor.nested.array.update');
var people = {
alice: {
name: 'Alice',
},
bob: {
name: 'Bob',
},
chris: {
name: 'Chris',
}
};
var tree = ['bob', 'chris', 'alice'];
var result = update(
tree,
x => people[x]
)
result:
[
bob: {
name: 'Bob',
},
chris: {
name: 'Chris',
},
alice: {
name: 'Alice',
}
]
API
declare function update(
tree: NestedDescriptor,
callback: (value) => any,
thisArg?
): NestedDescriptor
Interfaces
NestedArray
: see @kingjs/descriptor/nested/arrayNestedDescriptor
: see @kingjs/descriptor
Parameters
tree
: The array tree whose values are going to be updated.callback
: Used to update values oftree
:value
: The current value.
thisArg
: Thethis
argument to pass tocallback
.
Returns
Returns tree
with updated values updated.
Install
With npm installed, run
$ npm install @kingjs/descriptor.nested.array.update
License
MIT