prettydiff
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -171,4 +171,15 @@ /*** | ||
}, | ||
a = bta, | ||
b = nta, | ||
a = [], | ||
b = [], | ||
reverse = false, | ||
lentest = (function () { | ||
if (bta.length > nta.length) { | ||
reverse = true; | ||
a = nta; | ||
b = bta; | ||
} else { | ||
a = bta; | ||
b = nta; | ||
} | ||
}()), | ||
matching_blocks = [], | ||
@@ -202,14 +213,14 @@ bxj = [], | ||
non_adjacent = [], | ||
ntuplecomp = function (a, b) { | ||
ntuplecomp = function (x, y) { | ||
var i = 0, | ||
mlen = Math.max(a.length, b.length); | ||
mlen = Math.max(x.length, y.length); | ||
for (i = 0; i < mlen; i += 1) { | ||
if (a[i] < b[i]) { | ||
if (x[i] < y[i]) { | ||
return -1; | ||
} | ||
if (a[i] > b[i]) { | ||
if (x[i] > y[i]) { | ||
return 1; | ||
} | ||
} | ||
return (a.length === b.length) ? 0 : ((a.length < b.length) ? -1 : 1); | ||
return (x.length === y.length) ? 0 : ((x.length < y.length) ? -1 : 1); | ||
}, | ||
@@ -347,3 +358,22 @@ find_longest_match = function (alo, ahi, blo, bhi) { | ||
blocks = get_matching_blocks(), | ||
d = blocks.length; | ||
d = blocks.length, | ||
closerMatch = function (x, y, z) { | ||
var diffspot = function (a, b) { | ||
var c = a.replace(/^(\s+)/, "").split(""), | ||
d = Math.min(c.length, b.length), | ||
e = 0; | ||
for (e = 0; e < d; e += 1) { | ||
if (c[e] !== b[e]) { | ||
return e; | ||
} | ||
} | ||
return e; | ||
}, | ||
zz = z.replace(/^(\s+)/, "").split(""), | ||
test = diffspot(y, zz) - diffspot(x, zz); | ||
if (test > 0) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
for (c = 0; c < d; c += 1) { | ||
@@ -355,10 +385,42 @@ ai = blocks[c][0]; | ||
if (i < ai && j < bj) { | ||
tag = "replace"; | ||
if (i - j !== ai - bj && j - bj < 3 && i - ai < 3) { | ||
if (reverse && i - ai > j - bj) { | ||
if (closerMatch(b[j], b[j + 1], a[i])) { | ||
answer.push(["delete", j, j + 1, i, i]); | ||
answer.push(["replace", j + 1, bj, i, ai]); | ||
} else { | ||
answer.push(["replace", j, bj, i, ai]); | ||
} | ||
} else if (!reverse && bj - j > ai - i) { | ||
if (closerMatch(b[j], b[j + 1], a[i])) { | ||
answer.push(["insert", i, i, j, j + 1]); | ||
answer.push(["replace", i, ai, j + 1, bj]); | ||
} else { | ||
answer.push(["replace", i, ai, j, bj]); | ||
} | ||
} else { | ||
tag = "replace"; | ||
} | ||
} else { | ||
tag = "replace"; | ||
} | ||
} else if (i < ai) { | ||
tag = "delete"; | ||
if (reverse) { | ||
tag = "insert"; | ||
} else { | ||
tag = "delete"; | ||
} | ||
} else if (j < bj) { | ||
tag = "insert"; | ||
if (reverse) { | ||
tag = "delete"; | ||
} else { | ||
tag = "insert"; | ||
} | ||
} | ||
if (tag !== "") { | ||
answer.push([tag, i, ai, j, bj]); | ||
if (reverse) { | ||
answer.push([tag, j, bj, i, ai]); | ||
} else { | ||
answer.push([tag, i, ai, j, bj]); | ||
} | ||
} | ||
@@ -368,3 +430,7 @@ i = ai + size; | ||
if (size > 0) { | ||
answer.push(["equal", ai, i, bj, j]); | ||
if (reverse) { | ||
answer.push(["equal", bj, j, ai, i]); | ||
} else { | ||
answer.push(["equal", ai, i, bj, j]); | ||
} | ||
} | ||
@@ -813,5 +879,5 @@ } | ||
if (tab !== "") { | ||
if (!btest && typeof bta[b + 1] === "string" && typeof nta[n] === "string" && btab[b + 1] === ntab[n] && btab[b] !== ntab[n] && (typeof nta[n - 1] !== "string" || (btab[b] !== ntab[n - 1]))) { | ||
if (!btest && bta[be] !== nta[ne] && typeof bta[b + 1] === "string" && typeof nta[n] === "string" && btab[b + 1] === ntab[n] && btab[b] !== ntab[n] && (typeof nta[n - 1] !== "string" || btab[b] !== ntab[n - 1])) { | ||
btest = true; | ||
} else if (!ntest && typeof nta[n + 1] === "string" && typeof bta[b] === "string" && ntab[n + 1] === btab[b] && ntab[n] !== btab[b] && (typeof bta[b - 1] !== "string" || (ntab[n] !== btab[b - 1]))) { | ||
} else if (!ntest && bta[be] !== nta[ne] && typeof nta[n + 1] === "string" && typeof bta[b] === "string" && ntab[n + 1] === btab[b] && ntab[n] !== btab[b] && (typeof bta[b - 1] !== "string" || ntab[n] !== btab[b - 1])) { | ||
ntest = true; | ||
@@ -818,0 +884,0 @@ } |
{ | ||
"name": "prettydiff", | ||
"author": "Austin Cheney <austin.cheney@us.army.mil> (http://prettydiff.com/)", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "File comparison tool to accurately diff between file versions regardless of comments or minification to the whitespace. It can also beautify (pretty print) and minify HTML.", | ||
@@ -6,0 +6,0 @@ "keywords": ["diff", "pretty diff", "pretty print", "pretty-print", "beautify", "minify", "xml", "html", "css", "javascript"], |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1204430
15915