Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-diff

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-diff

Get the diff from objectA to objectB

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.2K
decreased by-27.91%
Maintainers
1
Weekly downloads
 
Created
Source

object diff

Get the minimal patch to extend objectA with to transform it into objectB

[![npm version][npm-image]][npm-url]

Consider an object retrieved from a server:

{
	name: 'Peter',
	age: 26,
	height: 187,
}

Now the user changes stuff using some frontend (e.g. a HTML form) and ends with:

{
	name: 'Peter',
	age: 27,
	height: 186,
}

When he hits save, you only want to send off the changed parts to the servers, to save bits (because you're indeed a programmer), but also to avoid any unnecessary "merge conflicts" at the server.

Imagine two users changing the same object; if they did not change the exact same keys of the object, the last user won't erase the first user's changes - in a lot of cases, that's the expected behavior.

Install

npm install object-diff

Usage

var diff = require('object-diff');

var a = {
	speed: 4,
	power: 54,
	height: undefined,
	level: 1,
};

var b = {
	speed: 4,			// unchanged
	power: 22,			// changed
	level: undefined,	// changed
	weight: 10,			// added
};

diff(a, b);
/*
{
	power: 22,
	level: undefined,
	weight: 10,
}
*/

License

MIT © src.agency / Thomas Jensen [npm-image]: https://img.shields.io/npm/v/object-diff.svg?style=flat [npm-url]: https://npmjs.org/package/object-diff

Keywords

FAQs

Package last updated on 18 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc