object-patch

1.0.3 • Public • Published

object-patch

Deep object extend / merge with a mongo-like $inc operator.

Usage

var patch = require('object-patch');
 
var document = {
  name: 'Dan Scanlon',
  grade: 6,
  country: 'USA',
  state: 'PA',
  rewardPoints: {
    outstanding: 600,
    total: 12000,
    monthly: []
  }
};
 
var documentPatch = {
  school: 'SAHS',
  grade: 7,
  rewardPoints: {
    outstanding: { $inc: 200 },
    total: { $inc: 200 }
  }
};
 
patch(document, documentPatch);
> {
  name: 'Dan Scanlon',
  grade: 7,
  country: 'USA',
  school: 'SAHS',
  state: 'PA',
  rewardPoints: {
    outstanding: 800,
    total: 12200,
    monthly: []
  }
}

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i object-patch

    Weekly Downloads

    2

    Version

    1.0.3

    License

    Apache

    Last publish

    Collaborators

    • danscan