Skip to content

Commit dc45a78

Browse files
committed
Remove log
1 parent a3e513b commit dc45a78

File tree

5 files changed

+50
-55
lines changed

5 files changed

+50
-55
lines changed

JSON-Diff.js

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,19 @@ exports = module.exports.diff = diff;
99
exports = module.exports.apply = apply;
1010

1111
function apply(app_old, jpn_patch) {
12-
console.log("===========Begin to apply patches==============");
1312
applyPatches.apply(app_old, jpn_patch);
1413
}
1514

1615
function diff(oldJson, newJson) {
17-
console.log("=========== Data ======================");
18-
console.log(JSON.stringify(oldJson));
19-
console.log(JSON.stringify(newJson));
2016

2117
// Get the unchanged area
2218
var unchanged = [];
2319
unchangedArea.generateUnchanged(oldJson, newJson, unchanged, '');
24-
console.log("=========== Unchanged =================");
25-
console.log(unchanged);
26-
console.log("=========================================");
2720

2821
// Generate the diff
2922
var patches = [];
3023
generateDiff(oldJson, newJson, unchanged, patches, '');
3124
patchArea.handlePatch(patches);
32-
console.log("===========Final Patches=================");
33-
console.log(patches);
3425

3526
return patches;
3627
}
@@ -57,25 +48,24 @@ function generateDiff(oldJson, newJson, unchanged, patches, path) {
5748
function generateValueDiff(oldJson, newJson, unchanged, patches, path) {
5849
// the endpoint
5950
if (newJson !== oldJson) {
60-
console.log({ op: "replace", path: path, value: copy.clone(newJson)});
51+
// console.log({ op: "replace", path: path, value: copy.clone(newJson)});
6152
patches.push({ op: "replace", path: path, value: copy.clone(newJson)});
6253
}
6354

6455
}
6556

6657
function generateArrayDiff(oldJson, newJson, unchanged, patches, path) {
67-
console.log("--------This is Array-------------");
58+
// console.log("--------This is Array-------------");
6859
// Hash array
6960
var x = oldJson.map(hashArray);
7061
var y = newJson.map(hashArray);
7162
// Use LCS
7263
var tmpPatches = [];
7364
lcs.LCS(x, y, unchanged, tmpPatches, path);
7465
for (var l = 0; l < tmpPatches.length; l++) {
75-
console.log(tmpPatches[l]);
7666
patches.push(tmpPatches[l]);
7767
}
78-
console.log("--------Array complete-------");
68+
// console.log("--------Array complete-------");
7969
}
8070

8171
function hashArray(obj) {
@@ -87,29 +77,29 @@ function generateObjectDiff(oldJson, newJson, unchanged, patches, path) {
8777
var newKeys = Object.keys(newJson);
8878
var removed = false;
8979

90-
console.log("oldKeys: " + oldKeys);
91-
console.log("newKeys: " + newKeys);
80+
// console.log("oldKeys: " + oldKeys);
81+
// console.log("newKeys: " + newKeys);
9282

9383
// Loop from the old; from lengths -1 to 0
9484
for (var i = oldKeys.length -1; i >= 0; i--) {
9585
var oldKey = oldKeys[i];
9686
var oldValue = oldJson[oldKey];
9787

98-
console.log("oldKey: " + oldKey);
99-
console.log("oldValue: " + JSON.stringify(oldValue));
88+
// console.log("oldKey: " + oldKey);
89+
// console.log("oldValue: " + JSON.stringify(oldValue));
10090

10191
if (newJson.hasOwnProperty(oldKey)) {
10292
var newValue = newJson[oldKey];
10393

104-
console.log("newValue: " + JSON.stringify(newValue));
94+
// console.log("newValue: " + JSON.stringify(newValue));
10595

10696
// go deeper
10797
generateDiff(oldJson[oldKey], newJson[oldKey], unchanged, patches, path + "/" + oldKey );
10898
// ???? patchPointString(oldKey)
10999

110100
} else {
111101
// Remove
112-
console.log({ op: "remove", path: path + "/" + patchPointString(oldKey), value: copy.clone(oldValue) });
102+
// console.log({ op: "remove", path: path + "/" + patchPointString(oldKey), value: copy.clone(oldValue) });
113103
removed = true;
114104
patches.push({ op: "remove", path: path + "/" + patchPointString(oldKey), value: copy.clone(oldValue) });
115105
}
@@ -131,25 +121,25 @@ function generateObjectDiff(oldJson, newJson, unchanged, patches, path) {
131121
//Try to find the value in the unchanged area
132122
// change JSON.stringify()
133123
var pointer = unchangedArea.findValueInUnchanged(JSON.stringify(newVal), unchanged);
134-
console.log("pointer: " + pointer);
124+
// console.log("pointer: " + pointer);
135125
if (pointer) {
136126
//COPY
137-
console.log({ op: "copy", path: path + "/" + patchPointString(newKey), from: pointer});
127+
// console.log({ op: "copy", path: path + "/" + patchPointString(newKey), from: pointer});
138128
patches.push({ op: "copy", path: path + "/" + patchPointString(newKey), from: pointer});
139129
} else {
140130
// no json.stringnify
141131
var previousIndex = patchArea.findValueInPatch(newVal, patches);
142-
console.log("previousIndex: " + previousIndex);
132+
// console.log("previousIndex: " + previousIndex);
143133

144134
if (previousIndex !== -1) {
145135
// MOVE
146136
var oldPath = patches[previousIndex].path;
147137
patches.splice(previousIndex, 1);
148-
console.log({ op: "move", from: oldPath, path: path + "/" + patchPointString(newKey)});
138+
// console.log({ op: "move", from: oldPath, path: path + "/" + patchPointString(newKey)});
149139
patches.push({ op: "move", from: oldPath, path: path + "/" + patchPointString(newKey)});
150140
} else {
151141
//ADD
152-
console.log({ op: "add", path: path + "/" + patchPointString(newKey), value: copy.clone(newVal)});
142+
// console.log({ op: "add", path: path + "/" + patchPointString(newKey), value: copy.clone(newVal)});
153143
patches.push({ op: "add", path: path + "/" + patchPointString(newKey), value: copy.clone(newVal)});
154144
}
155145

LCS.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ function LCS (x, y, unchanged, patches, path) {
2424
var newY = y.slice(start, y_end + 1);
2525

2626
var matrix = lcsMatrix(newX, newY);
27-
var result = lcsResult(newX, newY, matrix);
28-
var finalResult = x.slice(0, start) + result + x.slice(x_end + 1, x.length);
27+
28+
//backtrack
29+
// var result = lcsResult(newX, newY, matrix);
30+
// var finalResult = x.slice(0, start) + result + x.slice(x_end + 1, x.length);
2931
// For Array
30-
console.log("Result: " + finalResult);
32+
// console.log("Result: " + finalResult);
3133

3234
// Set offset = 1, offset is the array index adjuster for JSON format patch
3335
var offset = {};
@@ -67,7 +69,7 @@ function lcsMatrix(x, y) {
6769
}
6870
}
6971

70-
console.log("LCSLength = " + matrix[x_length][y_length]);
72+
// console.log("LCSLength = " + matrix[x_length][y_length]);
7173
return matrix;
7274
}
7375

@@ -112,37 +114,37 @@ function printDiff(x, y, matrix, i, j, start, offset, unchanged, patches, path)
112114
var tmpPath = path + "/" + (i + start + offset.value);
113115
if (lastElement !== void 0 && lastElement.op === "remove" && lastElement.path === tmpPath) {
114116
//First Replace
115-
console.log({ op: "replace", path: tmpPath, value: y[j] });
117+
// console.log({ op: "replace", path: tmpPath, value: y[j] });
116118
patches[patches.length - 1].op = "replace";
117119
patches[patches.length - 1].value = JSON.parse(y[j]);
118120
} else {
119121

120122
// First MOVE or ADD or COPY
121123
var previousIndex = patchArea.findValueInPatch(y[j], patches);
122-
console.log("previousIndex: " + previousIndex);
124+
// console.log("previousIndex: " + previousIndex);
123125
// ********Need to be fiexed*****************
124126
// only move when the previousIndex is 0 and patchLength is 1
125127
// if (previousIndex !== -1) {
126128
if (previousIndex === 0 && patches.length === 1) {
127129
// MOVE
128130
var oldPath = patches[previousIndex].path;
129-
console.log({ op: "move", from: oldPath, path: tmpPath});
131+
// console.log({ op: "move", from: oldPath, path: tmpPath});
130132
patches.splice(previousIndex, 1);
131133
patches.push({ op: "move", from: oldPath, path: tmpPath});
132134
} else {
133135
// ADD OR COPY
134136
//Try to find the value in the unchanged area
135137
// var pointer = findValueInUnchanged(JSON.stringify(y[j]), unchanged);
136138
var pointer = unchangedArea.findValueInUnchanged(y[j], unchanged);
137-
console.log("pointer: " + pointer);
139+
// console.log("pointer: " + pointer);
138140
if (pointer) {
139141
// COPY
140142
// Adjust the index in the unchanged area
141143
var newPointerArr = pointer.split('/');
142144
var initIndex = parseInt(newPointerArr[newPointerArr.length - 1]);
143-
console.log("offset: " + offset.value);
144-
console.log("start: " + start);
145-
console.log("initIndex: " + initIndex);
145+
// console.log("offset: " + offset.value);
146+
// console.log("start: " + start);
147+
// console.log("initIndex: " + initIndex);
146148

147149
var newIndex;
148150
// change index
@@ -151,23 +153,23 @@ function printDiff(x, y, matrix, i, j, start, offset, unchanged, patches, path)
151153
} else {
152154
newIndex = initIndex + offset.value - 1;
153155
}
154-
console.log("newIndex: " + newIndex);
156+
// console.log("newIndex: " + newIndex);
155157
if (newIndex >= 0) {
156158
// newIndex >= 0, hence the element exists in the array, copy
157159
var index = pointer.lastIndexOf('/');
158160
if (index !== -1) {
159161
var newPointer = pointer.slice(0, index + 1) + newIndex;
160-
console.log({ op: "copy", path: tmpPath, from: newPointer });
162+
// console.log({ op: "copy", path: tmpPath, from: newPointer });
161163
patches.push({ op: "copy", path: tmpPath, from: newPointer });
162164
}
163165
} else {
164166
// newIndex < 0, hence the element doesn't exist in the array, add
165-
console.log({ op: "add", path: tmpPath, value: y[j] });
167+
// console.log({ op: "add", path: tmpPath, value: y[j] });
166168
patches.push({ op: "add", path: tmpPath, value: JSON.parse(y[j]) });
167169
}
168170
} else {
169171
// ADD
170-
console.log({ op: "add", path: tmpPath, value: y[j] });
172+
// console.log({ op: "add", path: tmpPath, value: y[j] });
171173
patches.push({ op: "add", path: tmpPath, value: JSON.parse(y[j]) });
172174
}
173175
}
@@ -184,7 +186,7 @@ function printDiff(x, y, matrix, i, j, start, offset, unchanged, patches, path)
184186
//First change offset
185187
offset.value--;
186188
//Then remove
187-
console.log({ op: "remove", path: path + "/" + (i + start + offset.value), value: x[i] });
189+
// console.log({ op: "remove", path: path + "/" + (i + start + offset.value), value: x[i] });
188190
patches.push({ op: "remove", path: path + "/" + (i + start + offset.value), value: JSON.parse(x[i]) });
189191
} else {
190192
// console.log("reach the end i = " + i);

applyPatches.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ var objectOps = {
77
// console.log(this);
88
// console.log(child_json);
99
child_json[key] = this.value;
10-
console.log("Add operation = " + this.value);
10+
// console.log("Add operation = " + this.value);
1111
return true;
1212
},
1313
remove: function(child_json, key, all_json) {
1414
delete child_json[key];
15-
console.log("Remove operation = " + child_json);
15+
// console.log("Remove operation = " + child_json);
1616
return true;
1717
},
1818
replace: function(child_json, key, all_json) {
1919
child_json[key] = this.value;
20-
console.log("replace operation = " + this.value);
20+
// console.log("replace operation = " + this.value);
2121
return true;
2222
},
2323
copy: function(child_json, key, all_json) {
@@ -32,7 +32,7 @@ var objectOps = {
3232
return true;
3333
},
3434
move: function(child_json, key, all_json) {
35-
console.log("move operation = " + JSON.stringify(child_json));
35+
// console.log("move operation = " + JSON.stringify(child_json));
3636
var tmpOp = {"op": "val_get", "path": this.from};
3737
//Get the tmp value
3838
apply(all_json, [tmpOp]);
@@ -47,12 +47,12 @@ var objectOps = {
4747
var arrayOps = {
4848
add: function(arr, key, all_json) {
4949
arr.splice(key, 0, this.value);
50-
console.log("Add operation = " + this.value);
50+
// console.log("Add operation = " + this.value);
5151
return true;
5252
},
5353
remove: function(arr, key, all_json) {
5454
arr.splice(key, 1);
55-
console.log("Remove operation = " + key);
55+
// console.log("Remove operation = " + key);
5656
return true;
5757
},
5858
replace: function(arr, key, all_json) {
@@ -97,7 +97,7 @@ function apply(all_json, patches) {
9797
if (patch !== void 0) {
9898
//when patch = "", it's the root
9999
var path = patch.path || "";
100-
console.log(path);
100+
// console.log(path);
101101
var keys = path.split("/");
102102
var child_json = all_json;
103103

@@ -113,21 +113,21 @@ function apply(all_json, patches) {
113113

114114
//This is the root operations
115115
if (key === "") {
116-
console.log("The key is undefined");
116+
// console.log("The key is undefined");
117117
rootOps[patch.op].call(patch, child_json, stringToPoint(key), all_json);
118118
break;
119119
}
120120

121121
if (Array.isArray(child_json)) {
122-
console.log("***********Array operations****************");
122+
// console.log("***********Array operations****************");
123123
if (key === '-') {
124124
key = child_json.length;
125125
} else {
126126
key = parseInt(key);
127127
}
128128
arrayOps[patch.op].call(patch, child_json, key, all_json);
129129
} else {
130-
console.log("***********Object operations***************");
130+
// console.log("***********Object operations***************");
131131
objectOps[patch.op].call(patch, child_json, stringToPoint(key), all_json);
132132
}
133133
}

bower.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"version": "1.0.1",
55
"homepage": "https://github.com/caohanyang/JSON-Diff",
66
"description": "This framework is to compare two JSON data and generate the Patch",
7-
"moduleType": [
8-
"node"
9-
],
107
"keywords": [
118
"JSON",
129
"Diff",
@@ -15,7 +12,13 @@
1512
"authors": [
1613
"Hanyang CAO"
1714
],
18-
"ignore": [],
15+
"ignore": [
16+
"**/.*",
17+
"node_modules",
18+
"bower_components",
19+
"test",
20+
"tests"
21+
],
1922
"license": "MIT",
2023
"dependencies": {
2124
"deep-equal": "~0.0.0"

unchangedArea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function generateUnchanged(oldJson, newJson, unchanged, path) {
3333
//********************Need to be changed ********************
3434
function generateUnchangedArray(oldJson, newJson, unchanged, path) {
3535
var miniLength = Math.min(oldJson.length, newJson.length);
36-
console.log("miniLength is " + miniLength);
36+
// console.log("miniLength is " + miniLength);
3737
for (var i = 0; i < miniLength; i++) {
3838
generateUnchanged(oldJson[i], newJson[i], unchanged, path + "/" + i);
3939
}

0 commit comments

Comments
 (0)