@aws-solutions-constructs/core 2.78.0 → 2.78.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +3 -3
- package/node_modules/deep-diff/.circleci/config.yml +76 -0
- package/node_modules/deep-diff/.eslintrc +72 -0
- package/node_modules/deep-diff/.vscode/launch.json +30 -0
- package/node_modules/deep-diff/.vscode/tasks.json +12 -0
- package/node_modules/deep-diff/ChangeLog.md +63 -0
- package/node_modules/deep-diff/LICENSE +7 -0
- package/node_modules/deep-diff/Readme.md +239 -0
- package/node_modules/deep-diff/dist/deep-diff.min.js +1 -0
- package/node_modules/deep-diff/dist/deep-diff.min.js.map +1 -0
- package/node_modules/deep-diff/examples/apply-diff-from-any.js +39 -0
- package/node_modules/deep-diff/examples/array-change.js +45 -0
- package/node_modules/deep-diff/examples/capture_change_apply_elsewhere.js +53 -0
- package/node_modules/deep-diff/examples/diff-ignoring-fun.js +88 -0
- package/node_modules/deep-diff/examples/diff-scenarios.js +49 -0
- package/node_modules/deep-diff/examples/example1.js +41 -0
- package/node_modules/deep-diff/examples/issue-111.js +6 -0
- package/node_modules/deep-diff/examples/issue-113-1.js +14 -0
- package/node_modules/deep-diff/examples/issue-113-2.js +11 -0
- package/node_modules/deep-diff/examples/issue-115.js +17 -0
- package/node_modules/deep-diff/examples/issue-124.js +8 -0
- package/node_modules/deep-diff/examples/issue-125.js +19 -0
- package/node_modules/deep-diff/examples/issue-126.js +33 -0
- package/node_modules/deep-diff/examples/issue-35.js +11 -0
- package/node_modules/deep-diff/examples/issue-47.js +17 -0
- package/node_modules/deep-diff/examples/issue-48.js +48 -0
- package/node_modules/deep-diff/examples/issue-62.js +14 -0
- package/node_modules/deep-diff/examples/issue-70.js +6 -0
- package/node_modules/deep-diff/examples/issue-71.js +15 -0
- package/node_modules/deep-diff/examples/issue-72.js +21 -0
- package/node_modules/deep-diff/examples/issue-74.js +9 -0
- package/node_modules/deep-diff/examples/issue-78.js +24 -0
- package/node_modules/deep-diff/examples/issue-83.js +11 -0
- package/node_modules/deep-diff/examples/issue-88.js +26 -0
- package/node_modules/deep-diff/examples/performance.js +64 -0
- package/node_modules/deep-diff/examples/practice-data.json +2501 -0
- package/node_modules/deep-diff/index.js +526 -0
- package/node_modules/deep-diff/package.json +74 -0
- package/node_modules/deep-diff/test/.eslintrc +10 -0
- package/node_modules/deep-diff/test/tests.html +34 -0
- package/node_modules/deep-diff/test/tests.js +759 -0
- package/node_modules/deepmerge/.editorconfig +7 -0
- package/node_modules/deepmerge/.eslintcache +1 -0
- package/node_modules/deepmerge/changelog.md +167 -0
- package/node_modules/deepmerge/dist/cjs.js +133 -0
- package/node_modules/deepmerge/dist/umd.js +139 -0
- package/node_modules/deepmerge/index.d.ts +20 -0
- package/node_modules/deepmerge/index.js +106 -0
- package/node_modules/deepmerge/license.txt +21 -0
- package/node_modules/deepmerge/package.json +42 -0
- package/node_modules/deepmerge/readme.md +264 -0
- package/node_modules/deepmerge/rollup.config.js +22 -0
- package/node_modules/npmlog/LICENSE.md +20 -0
- package/node_modules/npmlog/README.md +216 -0
- package/node_modules/npmlog/lib/log.js +400 -0
- package/node_modules/npmlog/package.json +52 -0
- package/nohoist.sh +11 -0
- package/package.json +3 -2
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*jshint indent:2, laxcomma:true, laxbreak:true*/
|
|
2
|
+
var util = require('util')
|
|
3
|
+
, assert = require('assert')
|
|
4
|
+
, diff = require('..')
|
|
5
|
+
, data = require('./practice-data')
|
|
6
|
+
;
|
|
7
|
+
|
|
8
|
+
var i = Math.floor(Math.random() * data.length) + 1;
|
|
9
|
+
var j = Math.floor(Math.random() * data.length) + 1;
|
|
10
|
+
|
|
11
|
+
while (j === i) {
|
|
12
|
+
j = Math.floor(Math.random() * data.length) + 1;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var source = data[i];
|
|
16
|
+
var comparand = data[j];
|
|
17
|
+
|
|
18
|
+
// source and comparand are different objects
|
|
19
|
+
assert.notEqual(source, comparand);
|
|
20
|
+
|
|
21
|
+
// source and comparand have differences in their structure
|
|
22
|
+
assert.notDeepEqual(source, comparand);
|
|
23
|
+
|
|
24
|
+
// record the differences between source and comparand
|
|
25
|
+
var changes = diff(source, comparand);
|
|
26
|
+
|
|
27
|
+
// apply the changes to the source
|
|
28
|
+
changes.forEach(function (change) {
|
|
29
|
+
diff.applyChange(source, true, change);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// source and copmarand are now deep equal
|
|
33
|
+
assert.deepEqual(source, comparand);
|
|
34
|
+
|
|
35
|
+
// Simulate serializing to a remote copy of the object (we've already go a copy, copy the changes)...
|
|
36
|
+
|
|
37
|
+
var remote = JSON.parse(JSON.stringify(source));
|
|
38
|
+
var remoteChanges = JSON.parse(JSON.stringify(changes));
|
|
39
|
+
|
|
40
|
+
// source and remote are different objects
|
|
41
|
+
assert.notEqual(source, remote);
|
|
42
|
+
|
|
43
|
+
// changes and remote changes are different objects
|
|
44
|
+
assert.notEqual(changes, remoteChanges);
|
|
45
|
+
|
|
46
|
+
// remote and comparand are different objects
|
|
47
|
+
assert.notEqual(remote, comparand);
|
|
48
|
+
|
|
49
|
+
remoteChanges.forEach(function (change) {
|
|
50
|
+
diff.applyChange(remote, true, change);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
assert.deepEqual(remote, comparand);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*jshint indent:2, laxcomma:true, laxbreak:true*/
|
|
2
|
+
var util = require('util')
|
|
3
|
+
, deep = require('..')
|
|
4
|
+
;
|
|
5
|
+
|
|
6
|
+
function duckWalk() {
|
|
7
|
+
util.log('right step, left-step, waddle');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function quadrapedWalk() {
|
|
11
|
+
util.log('right hind-step, right fore-step, left hind-step, left fore-step');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var duck = {
|
|
15
|
+
legs: 2,
|
|
16
|
+
walk: duckWalk
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
var dog = {
|
|
20
|
+
legs: 4,
|
|
21
|
+
walk: quadrapedWalk
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var diff = deep.diff(duck, dog);
|
|
25
|
+
|
|
26
|
+
// The differences will include the legs, and walk.
|
|
27
|
+
util.log('Differences:\r\n' + util.inspect(diff, false, 9));
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// To ignore behavioral differences (functions); use observableDiff and your own accumulator:
|
|
31
|
+
|
|
32
|
+
var observed = [];
|
|
33
|
+
deep.observableDiff(duck, dog, function (d) {
|
|
34
|
+
if (d && d.lhs && typeof d.lhs !== 'function') {
|
|
35
|
+
observed.push(d);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
util.log('Observed without recording functions:\r\n' + util.inspect(observed, false, 9));
|
|
40
|
+
|
|
41
|
+
util.log(util.inspect(dog, false, 9) + ' walking: ');
|
|
42
|
+
dog.walk();
|
|
43
|
+
|
|
44
|
+
// The purpose of the observableDiff fn is to allow you to observe and apply differences
|
|
45
|
+
// that make sense in your scenario...
|
|
46
|
+
|
|
47
|
+
// We'll make the dog act like a duck...
|
|
48
|
+
deep.observableDiff(dog, duck, function (d) {
|
|
49
|
+
deep.applyChange(dog, duck, d);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
util.log(util.inspect(dog, false, 9) + ' walking: ');
|
|
53
|
+
dog.walk();
|
|
54
|
+
|
|
55
|
+
// Now there are no differences between the duck and the dog:
|
|
56
|
+
if (deep.diff(duck, dog)) {
|
|
57
|
+
util.log("Ooops, that prior statement seems to be wrong! (but it won't be)");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Now assign an "equivalent" walk function...
|
|
61
|
+
dog.walk = function duckWalk() {
|
|
62
|
+
util.log('right step, left-step, waddle');
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
if (diff = deep.diff(duck, dog)) {
|
|
66
|
+
// The dog's walk function is an equivalent, but different duckWalk function.
|
|
67
|
+
util.log('Hrmm, the dog walks differently: ' + util.inspect(diff, false, 9));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Use the observableDiff fn to ingore based on behavioral equivalence...
|
|
71
|
+
|
|
72
|
+
observed = [];
|
|
73
|
+
deep.observableDiff(duck, dog, function (d) {
|
|
74
|
+
// if the change is a function, only record it if the text of the fns differ:
|
|
75
|
+
if (d && typeof d.lhs === 'function' && typeof d.rhs === 'function') {
|
|
76
|
+
var leftFnText = d.lhs.toString();
|
|
77
|
+
var rightFnText = d.rhs.toString();
|
|
78
|
+
if (leftFnText !== rightFnText) {
|
|
79
|
+
observed.push(d);
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
observed.push(d);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (observed.length === 0) {
|
|
87
|
+
util.log('Yay!, we detected that the walk functions are equivalent');
|
|
88
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var util = require('util'),
|
|
2
|
+
expect = require('expect.js'),
|
|
3
|
+
eql = require('deep-equal'),
|
|
4
|
+
deep = require('..')
|
|
5
|
+
extend = util._extend;
|
|
6
|
+
diff = deep.diff,
|
|
7
|
+
apply = deep.applyDiff;
|
|
8
|
+
|
|
9
|
+
function f0() {};
|
|
10
|
+
function f1() {};
|
|
11
|
+
|
|
12
|
+
var one = { it: 'be one', changed: false, with: { nested: 'data'}, f: f1};
|
|
13
|
+
var two = { it: 'be two', updated: true, changed: true, with: {nested: 'data', and: 'other', plus: one} };
|
|
14
|
+
var circ = {};
|
|
15
|
+
var other = { it: 'be other', numero: 34.29, changed: [ { it: 'is the same' }, 13.3, 'get some' ], with: {nested: 'reference', plus: circ} };
|
|
16
|
+
var circular = extend(circ, { it: 'be circ', updated: false, changed: [ { it: 'is not same' }, 13.3, 'get some!', {extra: 'stuff'}], with: { nested: 'reference', circular: other } });
|
|
17
|
+
|
|
18
|
+
util.log(util.inspect(diff(one, two), false, 99));
|
|
19
|
+
util.log(util.inspect(diff(two, one), false, 99));
|
|
20
|
+
|
|
21
|
+
util.log(util.inspect(diff(other, circular), false, 99));
|
|
22
|
+
|
|
23
|
+
var clone = extend({}, one);
|
|
24
|
+
apply(clone, two);
|
|
25
|
+
util.log(util.inspect(clone, false, 99));
|
|
26
|
+
|
|
27
|
+
expect(eql(clone, two)).to.be(true);
|
|
28
|
+
expect(eql(clone, one)).to.be(false);
|
|
29
|
+
|
|
30
|
+
clone = extend({}, circular);
|
|
31
|
+
apply(clone, other);
|
|
32
|
+
util.log(util.inspect(clone, false, 99));
|
|
33
|
+
expect(eql(clone, other)).to.be(true);
|
|
34
|
+
expect(eql(clone, circular)).to.be(false);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
var array = { name: 'array two levels deep', item: { arr: ['it', { has: 'data' }]}};
|
|
38
|
+
var arrayChange = { name: 'array change two levels deep', item: { arr: ['it', { changes: 'data' }]}};
|
|
39
|
+
|
|
40
|
+
util.log(util.inspect(diff(array, arrayChange), false, 99));
|
|
41
|
+
clone = extend({}, array);
|
|
42
|
+
apply(clone, arrayChange);
|
|
43
|
+
util.log(util.inspect(clone, false, 99));
|
|
44
|
+
expect(eql(clone, arrayChange)).to.be(true);
|
|
45
|
+
|
|
46
|
+
var one_prop = { one: 'property' };
|
|
47
|
+
var d = diff(one_prop, {});
|
|
48
|
+
expect(d.length).to.be(1);
|
|
49
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var util = require('util')
|
|
2
|
+
, deep = require('..')
|
|
3
|
+
;
|
|
4
|
+
|
|
5
|
+
var lhs = {
|
|
6
|
+
name: 'my object',
|
|
7
|
+
description: 'it\'s an object!',
|
|
8
|
+
details: {
|
|
9
|
+
it: 'has',
|
|
10
|
+
an: 'array',
|
|
11
|
+
with: ['a', 'few', 'elements']
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var rhs = {
|
|
16
|
+
name: 'updated object',
|
|
17
|
+
description: 'it\'s an object!',
|
|
18
|
+
details: {
|
|
19
|
+
it: 'has',
|
|
20
|
+
an: 'array',
|
|
21
|
+
with: ['a', 'few', 'more', 'elements', { than: 'before' }]
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var differences = deep.diff(lhs, rhs);
|
|
26
|
+
|
|
27
|
+
// Print the differences to the console...
|
|
28
|
+
util.log(util.inspect(differences, false, 99));
|
|
29
|
+
|
|
30
|
+
deep.observableDiff(lhs, rhs, function (d) {
|
|
31
|
+
// Apply all changes except those to the 'name' property...
|
|
32
|
+
if (d.path.length !== 1 || d.path.join('.') !== 'name') {
|
|
33
|
+
deep.applyChange(lhs, rhs, d);
|
|
34
|
+
}
|
|
35
|
+
}, function (path, key) {
|
|
36
|
+
var p = (path && path.length) ? path.join('/') : '<no-path>'
|
|
37
|
+
util.log('prefilter: path = ' + p + ' key = ' + key);
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
console.log(util.inspect(lhs, false, 99));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { log, inspect } = require('util');
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const diff = require('../');
|
|
4
|
+
|
|
5
|
+
const o1 = {};
|
|
6
|
+
const o2 = {};
|
|
7
|
+
o1.foo = o1;
|
|
8
|
+
o2.foo = o2;
|
|
9
|
+
|
|
10
|
+
assert.notEqual(o1, o2, 'not same object');
|
|
11
|
+
assert.notEqual(o1.foo, o2.foo, 'not same object');
|
|
12
|
+
|
|
13
|
+
const differences = diff(o1, o2);
|
|
14
|
+
log(inspect(differences, false, 9));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var diff = require('../');
|
|
2
|
+
var expect = require('expect.js');
|
|
3
|
+
|
|
4
|
+
var thing1 = 'this';
|
|
5
|
+
var thing2 = 'that';
|
|
6
|
+
var thing3 = 'other';
|
|
7
|
+
var thing4 = 'another';
|
|
8
|
+
|
|
9
|
+
var oldArray = [thing1, thing2, thing3, thing4];
|
|
10
|
+
var newArray = [thing1, thing2];
|
|
11
|
+
|
|
12
|
+
diff.observableDiff(oldArray, newArray,
|
|
13
|
+
function (d) {
|
|
14
|
+
diff.applyChange(oldArray, d);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
expect(oldArray).to.eql(newArray);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var diff = require('../');
|
|
2
|
+
|
|
3
|
+
const left = {
|
|
4
|
+
nested: {
|
|
5
|
+
param1: null,
|
|
6
|
+
param2: null
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const right = {
|
|
11
|
+
nested: {
|
|
12
|
+
param1: null,
|
|
13
|
+
param2: null
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var differences = diff(left, right);
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.log(differences);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// This example shows how prefiltering can be used.
|
|
2
|
+
|
|
3
|
+
const diff = require('../'); // deep-diff
|
|
4
|
+
const { log, inspect } = require('util');
|
|
5
|
+
const assert = require('assert');
|
|
6
|
+
|
|
7
|
+
const data = {
|
|
8
|
+
issue: 126,
|
|
9
|
+
submittedBy: 'abuzarhamza',
|
|
10
|
+
title: 'readme.md need some additional example prefilter',
|
|
11
|
+
posts: [
|
|
12
|
+
{
|
|
13
|
+
date: '2018-04-16',
|
|
14
|
+
text: `additional example for prefilter for deep-diff would be great.
|
|
15
|
+
https://stackoverflow.com/questions/38364639/pre-filter-condition-deep-diff-node-js`
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const clone = JSON.parse(JSON.stringify(data));
|
|
21
|
+
clone.title = 'README.MD needs additional example illustrating how to prefilter';
|
|
22
|
+
clone.disposition = 'completed';
|
|
23
|
+
|
|
24
|
+
const two = diff(data, clone);
|
|
25
|
+
const none = diff(data, clone,
|
|
26
|
+
(path, key) => path.length === 0 && ~['title', 'disposition'].indexOf(key)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
assert.equal(two.length, 2, 'should reflect two differences');
|
|
30
|
+
assert.ok(typeof none === 'undefined', 'should reflect no differences');
|
|
31
|
+
|
|
32
|
+
log(inspect(two, false, 9));
|
|
33
|
+
log(inspect(none, false, 9));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var deep = require('../');
|
|
2
|
+
|
|
3
|
+
var lhs = ['a', 'a'];
|
|
4
|
+
var rhs = ['a'];
|
|
5
|
+
var differences = deep.diff(lhs, rhs);
|
|
6
|
+
differences.forEach(function (change) {
|
|
7
|
+
deep.applyChange(lhs, true, change);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
console.log(lhs); // eslint-disable-line no-console
|
|
11
|
+
console.log(rhs); // eslint-disable-line no-console
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var diff = require('../');
|
|
2
|
+
var expect = require('expect.js');
|
|
3
|
+
|
|
4
|
+
var thing1 = 'this';
|
|
5
|
+
var thing2 = 'that';
|
|
6
|
+
var thing3 = 'other';
|
|
7
|
+
var thing4 = 'another';
|
|
8
|
+
|
|
9
|
+
var oldArray = [thing1, thing2, thing3, thing4];
|
|
10
|
+
var newArray = [thing1, thing2];
|
|
11
|
+
|
|
12
|
+
diff.observableDiff(oldArray, newArray,
|
|
13
|
+
function (d) {
|
|
14
|
+
diff.applyChange(oldArray, newArray, d);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
expect(oldArray).to.eql(newArray);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
|
|
2
|
+
var dd = require('../'); // deep-diff
|
|
3
|
+
var inspect = require('util').inspect;
|
|
4
|
+
var expect = require('expect.js');
|
|
5
|
+
|
|
6
|
+
var before = {
|
|
7
|
+
name: 'my object',
|
|
8
|
+
description: 'it\'s an object!',
|
|
9
|
+
details: {
|
|
10
|
+
it: 'has',
|
|
11
|
+
an: 'array',
|
|
12
|
+
with: ['a', 'few', 'elements']
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
var after = {
|
|
17
|
+
name: 'updated object',
|
|
18
|
+
description: 'it\'s an object!',
|
|
19
|
+
details: {
|
|
20
|
+
it: 'has',
|
|
21
|
+
an: 'array',
|
|
22
|
+
with: ['a', 'few', 'more', 'elements', { than: 'before' }]
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
var revertDiff = function (src, d) {
|
|
27
|
+
d.forEach(function (change) {
|
|
28
|
+
dd.revertChange(src, true, change);
|
|
29
|
+
});
|
|
30
|
+
return src;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var clone = function (src) {
|
|
34
|
+
return JSON.parse(JSON.stringify(src));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var df = dd.diff(before, after);
|
|
38
|
+
var b1 = clone(before);
|
|
39
|
+
var a1 = clone(after);
|
|
40
|
+
|
|
41
|
+
console.log(inspect(a1, false, 9)); // eslint-disable-line no-console
|
|
42
|
+
|
|
43
|
+
var reverted = revertDiff(a1, df);
|
|
44
|
+
console.log(inspect(reverted, false, 9)); // eslint-disable-line no-console
|
|
45
|
+
console.log(inspect(b1, false, 9)); // eslint-disable-line no-console
|
|
46
|
+
|
|
47
|
+
expect(reverted).to.eql(b1);
|
|
48
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var deep = require("../");
|
|
2
|
+
|
|
3
|
+
// https://github.com/flitbit/diff/issues/62#issuecomment-229549984
|
|
4
|
+
// 3: appears to be fixed, probably in fixing #74.
|
|
5
|
+
|
|
6
|
+
var a = {};
|
|
7
|
+
var b = {};
|
|
8
|
+
a.x = b;
|
|
9
|
+
b.x = b;
|
|
10
|
+
deep.diff(a, b); // True
|
|
11
|
+
|
|
12
|
+
a.x = a; // Change to a
|
|
13
|
+
// No change to b
|
|
14
|
+
console.log(deep.diff(a, b)); // Still true...
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var diff = require('../');
|
|
2
|
+
|
|
3
|
+
var before = {
|
|
4
|
+
data: [1, 2, 3]
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
var after = {
|
|
8
|
+
data: [4, 5, 1]
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var differences = diff(before, after);
|
|
12
|
+
console.log(differences); // eslint-disable-line no-console
|
|
13
|
+
differences.reduce(
|
|
14
|
+
(acc, change) => {
|
|
15
|
+
diff.revertChange(acc, true, change);
|
|
16
|
+
return acc;
|
|
17
|
+
},
|
|
18
|
+
after
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
console.log(after); // eslint-disable-line no-console
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
const diff = require('../');
|
|
3
|
+
const ptr = require('json-ptr');
|
|
4
|
+
|
|
5
|
+
const inspect = require('util').inspect;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const objA = { array: [{ a: 1 }] };
|
|
9
|
+
const objB = { array: [{ a: 2 }] };
|
|
10
|
+
|
|
11
|
+
let changes = diff(objA, objB);
|
|
12
|
+
if (changes) {
|
|
13
|
+
// decorate the changes using json-pointers
|
|
14
|
+
for (let i = 0; i < changes.length; ++i) {
|
|
15
|
+
let change = changes[i];
|
|
16
|
+
// get the parent path:
|
|
17
|
+
let pointer = ptr.create(change.path.slice(0, change.path.length - 1));
|
|
18
|
+
if (change.kind === 'E') {
|
|
19
|
+
change.elementLeft = pointer.get(objA);
|
|
20
|
+
change.elementRight = pointer.get(objB);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
console.log(inspect(changes, false, 9)); // eslint-disable-line no-console
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var diff = require("../");
|
|
2
|
+
|
|
3
|
+
var before = {
|
|
4
|
+
length: 3,
|
|
5
|
+
data: [1, 2, 3]
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
var after = {
|
|
9
|
+
data: [4, 5, 1, 2, 3],
|
|
10
|
+
count: 5
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
var differences = diff(before, after);
|
|
14
|
+
console.log(differences);
|
|
15
|
+
|
|
16
|
+
function applyChanges(target, changes) {
|
|
17
|
+
return changes.reduce(
|
|
18
|
+
(acc, change) => {
|
|
19
|
+
diff.applyChange(acc, true, change);
|
|
20
|
+
return acc;
|
|
21
|
+
},
|
|
22
|
+
target
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
console.log(applyChanges(before, differences));
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var util = require('util')
|
|
2
|
+
, diff = require('..')
|
|
3
|
+
, data = require('./practice-data')
|
|
4
|
+
;
|
|
5
|
+
|
|
6
|
+
var cycle = -1
|
|
7
|
+
, i
|
|
8
|
+
, len = data.length
|
|
9
|
+
, prior = {}
|
|
10
|
+
, comparand
|
|
11
|
+
, records
|
|
12
|
+
, roll = []
|
|
13
|
+
, stat
|
|
14
|
+
, stats = []
|
|
15
|
+
, mark, elapsed, avg = { diff: { ttl: 0 }, apply: { ttl: 0 } }, ttl = 0
|
|
16
|
+
;
|
|
17
|
+
|
|
18
|
+
mark = process.hrtime();
|
|
19
|
+
while (++cycle < 10) {
|
|
20
|
+
i = -1;
|
|
21
|
+
while (++i < len) {
|
|
22
|
+
stats.push(stat = { mark: process.hrtime() });
|
|
23
|
+
|
|
24
|
+
comparand = roll[i] || data[i];
|
|
25
|
+
|
|
26
|
+
stat.diff = { mark: process.hrtime() };
|
|
27
|
+
records = diff(prior, comparand);
|
|
28
|
+
stat.diff.intv = process.hrtime(stat.diff.mark);
|
|
29
|
+
|
|
30
|
+
if (records) {
|
|
31
|
+
stat.apply = { count: diff.length, mark: process.hrtime() };
|
|
32
|
+
records.forEach(function (ch) {
|
|
33
|
+
diff.applyChange(prior, comparand, ch);
|
|
34
|
+
});
|
|
35
|
+
stat.apply.intv = process.hrtime(stat.apply.mark);
|
|
36
|
+
|
|
37
|
+
prior = comparand;
|
|
38
|
+
}
|
|
39
|
+
stat.intv = process.hrtime(stat.mark);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ms(intv) {
|
|
44
|
+
return (intv[0] * 1e9 + intv[1] / 1e6);
|
|
45
|
+
}
|
|
46
|
+
elapsed = ms(process.hrtime(mark));
|
|
47
|
+
|
|
48
|
+
stats.forEach(function (stat) {
|
|
49
|
+
stat.elapsed = ms(stat.intv);
|
|
50
|
+
stat.diff.elapsed = ms(stat.diff.intv);
|
|
51
|
+
avg.diff.ttl += stat.diff.elapsed;
|
|
52
|
+
if (stat.apply) {
|
|
53
|
+
stat.apply.elapsed = ms(stat.apply.intv);
|
|
54
|
+
ttl += stat.apply.count;
|
|
55
|
+
avg.apply.ttl += stat.apply.elapsed;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
avg.diff.avg = avg.diff.ttl / ttl;
|
|
60
|
+
avg.apply.avg = avg.apply.ttl / ttl;
|
|
61
|
+
|
|
62
|
+
console.log('Captured '.concat(stats.length, ' samples with ', ttl, ' combined differences in ', elapsed, 'ms'));
|
|
63
|
+
console.log('\tavg diff: '.concat(avg.diff.avg, 'ms or ', (1 / avg.diff.avg), ' per ms'));
|
|
64
|
+
console.log('\tavg apply: '.concat(avg.apply.avg, 'ms or ', (1 / avg.apply.avg), ' per ms'));
|