🚀 DAY 1 OF LAUNCH WEEK: Reachability for Ruby Now in Beta.Learn more →
Socket
Book a DemoInstallSign in
Socket

id-diff

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

id-diff

diff arrays of identifyable objects

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

#id-diff Diff arrays of identifyable objects.

The output can be used to do 3-way merges with id-merge.

var origin = [
  {id: 1, value: 1},
  {id: 2, value: 2},
  {id: 3, value: 3},
  {id: 4, value: 4}
]
var modified = [
  {id: 5, value: 6},
  {id: 3, value: 8},
  {id: 2, value: 2},
  {id: 4, value: 4},
  {id: 1, value: 5}
]
var result = diff(origin, modified)
// returns:
{
  values: {
    1: ['m', 1, 5],
    2: ['=', 2],
    3: ['m', 3, 8],
    4: ['=', 4],
    5: ['+', 6]
  },
  ids: [["x",1],["x",2],["+",5],["=",3],["p",2],["=",4],["p",1]]
}

result.ids uses array-diff's format.
result.values returns all values both of the original and the changed version including change markers 'm' (modified), '=', '+' and '-'.

An example including deletes:

var origin = [
  {id: 1, value: 1},
  {id: 2, value: 2},
  {id: 3, value: 3},
  {id: 4, value: 4}
]
var modified = [
  {id: 2, value: 2},
  {id: 1, value: 9},
  {id: 4, value: 5}
]
var result = diff(origin, modified)
// returns:
{
  values: {
    1: ['m', 1, 9],
    2: ['=', 2],
    3: ['-', 3],
    4: ['m', 4, 5]
  },
  ids: [["x",1],["=",2],["-",3],["p",1],["=",4]]
}

FAQs

Package last updated on 10 Dec 2012

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