1.0.3 • Published 8 years ago

object-patch v1.0.3

Weekly downloads
2
License
Apache
Repository
github
Last release
8 years ago

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: []
  }
}