Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

update-diff

dfcreative799.5kMIT1.1.0

Update object by mapping diff properties

update-diff, map, map-obj, object-filter, map-object, update, diff, difference, patch, object, compare, change

readme

update-diff unstable

Update object by mapping differences in order. Comes handy for organizing state updating.

npm install update-diff

let prop = require('update-diff')

let state = {propA: 0, propB: 1, propC: ['foo'], propD: 'bar'}

updateDiff(state, modifications, [
//initial mapping
{
    propA: value => value,
    propB: true,
    propC: Array.isArray
},
//second-pass mapping
{
    propX: (x, state) => state.propB + x
},
//third-pass mapping
{
    propA: (value, state) => state.propA ? 'a' : 'b'
}
])

// {propB: 1, propC: ['foo']}
  • obj-map-prop − map object properties by a dict
  • map-obj − map properties by single function
  • filter-obj − filter properties by single function

Credits

© 2017 Dima Yv. MIT License