1.0.7 • Published 6 years ago

@kingjs/mutate.path v1.0.7

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

@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

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago