This package has been deprecated

Author message:

see @kingjs/descriptor.path

@kingjs/mutate.path

1.0.7 • Public • Published

@kingjs/mutate.path

Updates property values matched by a path.

Usage

Deduct a dollar from the balances of every account like this:

var mapPath = require('@kingjs/mutate.path');

var accounts = {
  alice: {
    id: 0,
    balance: 101
  },
  bob: {
    id: 1,
    balance: 201
  }
}

mapPath.call(
  accounts,
  '*.balance',
  function(x) { return x - 1; }
)

result:

{
  alice: {
    id: 0,
    balance: 100
  },
  bob: {
    id: 1,
    balance: 200
  }
}

API

declare function path(
  this,
  path: string | string[],
  callback: (this, x) => any
): any

Parameters

  • this: The object whose property's values are updated.
  • path: An array of property names and/or the wildcard '*' which specify the path(s) to map.
  • callback: The update function to apply to each property that matches the path.
    • this: The same this as passed to path (which may not be the same as object hosting the property of the value being upated).
    • x: The value of the property being updated.

Returns

Returns this after updating properties which matched path.

Remarks

The path may also be a '.' delimited string composed of property names and/or the wildcard symbol '*'.

Install

With npm installed, run

$ npm install @kingjs/mutate.path

License

MIT

Analytics

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/mutate.path

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

3.65 kB

Total Files

4

Last publish

Collaborators

  • kingces95