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

3-way-diff

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3-way-diff - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

13

index.js

@@ -68,3 +68,3 @@ /**

// Skip all keys that exist in mine
if (_.isUndefined(mine[key])) {
if (_.isUndefined(mine) || (mine && _.isUndefined(mine[key]))) {
results = results.concat(processKeyValuePair(key, value, parent, theirs, mine, path, options));

@@ -76,3 +76,3 @@ }

_.forOwn(theirs, function(value, key) {
if (_.isUndefined(mine[key]) && _.isUndefined(parent[key])) {
if ((_.isUndefined(mine) || (mine && _.isUndefined(mine[key]))) && (_.isUndefined(parent) || (parent && _.isUndefined(parent[key])))) {
results = results.concat(processKeyValuePair(key, value, parent, theirs, mine, path, options));

@@ -99,2 +99,5 @@ }

options = options || {};
var parentValue = typeof parent !== 'undefined' ? parent[key] : undefined;
var theirsValue = typeof theirs !== 'undefined' ? theirs[key] : undefined;
var mineValue = typeof mine !== 'undefined' ? mine[key] : undefined;
var results = [];

@@ -112,3 +115,3 @@

path.push(key);
var differences = compareValues(parent[key], theirs[key], mine[key], path, options[key] || {});
var differences = compareValues(parentValue, theirsValue, mineValue, path, options[key] || {});
if (differences) {

@@ -126,3 +129,3 @@ results = results.concat(differences);

path.push(key);
var differences = recurse(parent[key], theirs[key], mine[key], path, options[key] || {});
var differences = recurse(parentValue, theirsValue, mineValue, path, options[key] || {});
if (differences) {

@@ -135,3 +138,3 @@ results = results.concat(differences);

path.push(key);
var differences = compareValues(parent[key], theirs[key], mine[key], path, options[key] || {});
var differences = compareValues(parentValue, theirsValue, mineValue, path, options[key] || {});
if (differences) {

@@ -138,0 +141,0 @@ results = results.concat(differences);

{
"name": "3-way-diff",
"version": "1.0.3",
"version": "1.0.4",
"description": "3-way diffing of JavaScript objects",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -345,4 +345,127 @@ var assert = require('assert');

});
it('both children edit same nested key to different values', function() {
var parent = {
key: {
childKey: 'value',
childKey1: {
subchildKey: 'value'
}
}
};
var theirs = {
key: {
childKey: 'value1',
childKey1: {
subchildKey: 'value'
}
}
};
var mine = {
key: {
childKey: 'value2',
childKey1: {
subchildKey: 'value'
}
}
};
var expected = [
// Conflict on key modified in both theirs/mine
{
kind: 'C',
path: [ 'key', 'childKey' ],
parent: parent.key.childKey,
theirs: theirs.key.childKey,
mine: mine.key.childKey
}
];
assert.deepEqual(diff(parent, theirs, mine), expected);
});
it('both children edit different nested keys to different values, ignore key', function() {
var parent = {
keyIgnored: {
childKey: 'value',
childKey1: {
subchildKey: 'value'
}
}
};
var theirs = {
keyIgnored: {
childKey: 'value',
childKey1: {
subchildKey: 'value1'
}
}
};
var mine = {
keyIgnored: {
childKey: 'value',
childKey1: {
subchildKey: 'value2'
}
}
};
var expected = [
// No differences
];
assert.deepEqual(diff(parent, theirs, mine, {keyIgnored: {ignoreKey: true}}), expected);
});
it('mine adds nested key that does not exist in parent/theirs', function() {
var parent = {
key: {
childKey: 'value'
}
};
var theirs = {
key: {
childKey: 'value'
}
};
var mine = {
key: {
childKey: 'value',
childKey1: {
subChildKey: 'value1'
}
}
};
var expected = [
{
kind: 'N',
path: [ 'key', 'childKey1', 'subChildKey'],
mine: mine.key.childKey1.subChildKey
}
];
assert.deepEqual(diff(parent, theirs, mine), expected);
});
it('mine adds nested key that does not exist in parent/theirs, ignore key', function() {
var parent = {
keyIgnored: {
childKey: 'value'
}
};
var theirs = {
keyIgnored: {
childKey: 'value'
}
};
var mine = {
keyIgnored: {
childKey: 'value',
childKey1: {
subchildKey: 'value1'
}
}
};
var expected = [
// No differences
];
assert.deepEqual(diff(parent, theirs, mine, {keyIgnored: {ignoreKey: true}}), expected);
});
});
// TODO These are probably useful tests https://github.com/falsecz/3-way-merge/blob/master/test/test.coffee
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