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.7 to 1.0.8

test/objects.js

7

index.js

@@ -139,5 +139,3 @@ /**

path.push(key);
if ((_.isUndefined(parentValue) || (!_.isObject(parentValue) && parentValue !== null))
|| (_.isUndefined(theirsValue) || (!_.isObject(theirsValue) && theirsValue !== null))
|| (_.isUndefined(mineValue) || (!_.isObject(mineValue) && mineValue !== null))) {
if ((typeof parentValue !== typeof theirsValue || typeof parentValue !== typeof mineValue) && typeof theirsValue !== typeof mineValue) {
var differences = compareValues(parentValue, theirsValue, mineValue, path, options[key] || {});

@@ -221,3 +219,4 @@ } else {

}
else if(_.isArray(parent) || _.isArray(mine) || _.isArray(theirs)) {
else if((_.isArray(parent) || _.isArray(mine) || _.isArray(theirs))
|| (_.isObject(parent) || _.isObject(mine) || _.isObject(theirs))) {
// Maintain array order unless flagged as ignoreOrder

@@ -224,0 +223,0 @@ if (!_.isUndefined(options) && options['ignoreOrder']) {

{
"name": "3-way-diff",
"version": "1.0.7",
"version": "1.0.8",
"description": "3-way diffing of JavaScript objects",

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

@@ -289,4 +289,3 @@ var assert = require('assert');

theirs: theirs.key[0]
}
,
},
{

@@ -293,0 +292,0 @@ kind: 'D',

@@ -345,263 +345,4 @@ 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'],
mine: mine.key.childKey1
}
];
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);
});
it('mine add nested childKey where the parent is empty', function() {
var parent = {
};
var theirs = {
};
var mine = {
key: {
childKey: 'value',
}
};
var expected = [
{
kind: 'N',
path: [ 'key'],
mine: mine.key
}
];
assert.deepEqual(diff(parent, theirs, mine), expected);
});
it('mine add nested childKey where the parent/theirs key are null', function() {
var parent = {
key: null
};
var theirs = {
key: null
};
var mine = {
key: {
childKey: 'value',
}
};
var expected = [
{
kind: 'N',
path: [ 'key', 'childKey'],
mine: mine.key.childKey
}
];
assert.deepEqual(diff(parent, theirs, mine), expected);
});
it('mine/theirs add nested childKey where the parent key is null', function() {
var parent = {
key: null
};
var theirs = {
key: {
childKey: 'value',
}
};
var mine = {
key: {
childKey: 'value',
}
};
var expected = [
// No differences
];
assert.deepEqual(diff(parent, theirs, mine), expected);
});
it('mine/theirs add nested childKey with different values where the parent key is null', function() {
var parent = {
key: null
};
var theirs = {
key: {
childKey: 'value',
}
};
var mine = {
key: {
childKey: 'value1',
}
};
var expected = [
{
kind: 'C',
path: [ 'key', 'childKey'],
mine: mine.key.childKey,
theirs: theirs.key.childKey,
parent: parent.key
}
];
assert.deepEqual(diff(parent, theirs, mine), expected);
});
it('mine/theirs add nested childKey where the parent key is null', function() {
var parent = {
key: null
};
var theirs = {
key: {
childKey: 'value'
}
};
var mine = {
key: {
childKey: 'value',
}
};
var expected = [
// No differences
];
assert.deepEqual(diff(parent, theirs, mine), expected);
});
it('mine/theirs add nested childKey with different values where the parent key is null', function() {
var parent = {
key: null
};
var theirs = {
key: {
childKey: 'value1'
}
};
var mine = {
key: {
childKey: 'value2',
}
};
var expected = [
{
kind: 'C',
path: [ 'key', 'childKey'],
parent: parent.key,
theirs: theirs.key.childKey,
mine: mine.key.childKey
}
];
assert.deepEqual(diff(parent, theirs, mine), 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