1.0.4 • Published 6 years ago

@kingjs/descriptor.nested.array.update v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@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

Parameters

  • tree: The array tree whose values are going to be updated.
  • callback: Used to update values of tree:
    • value: The current value.
  • thisArg: The this argument to pass to callback.

Returns

Returns tree with updated values updated.

Install

With npm installed, run

$ npm install @kingjs/descriptor.nested.array.update

License

MIT

Analytics