Created
September 27, 2019 07:05
-
-
Save otakustay/18509980821fe0fb161498434b9b46ee to your computer and use it in GitHub Desktop.
es2015 unidiff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | |
!function (e, n) { | |
"object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? n(exports) : "function" == typeof define && define.amd ? define(["exports"], n) : n(e.unidiff = {}); | |
}(void 0, function (e) { | |
"use strict"; | |
function n(e) { | |
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e; | |
} | |
function t(e, n) { | |
return e(n = { | |
exports: {} | |
}, n.exports), n.exports; | |
} | |
var r = t(function (e, n) { | |
function t() {} | |
function r(e, n, t, r, i) { | |
for (var o = 0, f = n.length, s = 0, a = 0; o < f; o++) { | |
var u = n[o]; | |
if (u.removed) { | |
if (u.value = r.slice(a, a + u.count).join(""), a += u.count, o && n[o - 1].added) { | |
var c = n[o - 1]; | |
n[o - 1] = n[o], n[o] = c; | |
} | |
} else { | |
if (!u.added && i) { | |
var l = t.slice(s, s + u.count); | |
l = l.map(function (e, n) { | |
var t = r[a + n]; | |
return t.length > e.length ? t : e; | |
}), u.value = l.join(""); | |
} else u.value = t.slice(s, s + u.count).join(""); | |
s += u.count, u.added || (a += u.count); | |
} | |
} | |
var d = n[f - 1]; | |
return f > 1 && (d.added || d.removed) && e.equals("", d.value) && (n[f - 2].value += d.value, n.pop()), n; | |
} | |
n.__esModule = !0, n.default = t, t.prototype = { | |
diff: function diff(e, n) { | |
var t = arguments.length <= 2 || void 0 === arguments[2] ? {} : arguments[2], | |
i = t.callback; | |
"function" == typeof t && (i = t, t = {}), this.options = t; | |
var o = this; | |
function f(e) { | |
return i ? (setTimeout(function () { | |
i(void 0, e); | |
}, 0), !0) : e; | |
} | |
e = this.castInput(e), n = this.castInput(n), e = this.removeEmpty(this.tokenize(e)); | |
var s = (n = this.removeEmpty(this.tokenize(n))).length, | |
a = e.length, | |
u = 1, | |
c = s + a, | |
l = [{ | |
newPos: -1, | |
components: [] | |
}], | |
d = this.extractCommon(l[0], n, e, 0); | |
if (l[0].newPos + 1 >= s && d + 1 >= a) return f([{ | |
value: n.join(""), | |
count: n.length | |
}]); | |
function h() { | |
for (var t = -1 * u; t <= u; t += 2) { | |
var i = void 0, | |
c = l[t - 1], | |
d = l[t + 1], | |
h = (d ? d.newPos : 0) - t; | |
c && (l[t - 1] = void 0); | |
var p = c && c.newPos + 1 < s, | |
v = d && 0 <= h && h < a; | |
if (p || v) { | |
if (!p || v && c.newPos < d.newPos ? (i = { | |
newPos: (g = d).newPos, | |
components: g.components.slice(0) | |
}, o.pushComponent(i.components, void 0, !0)) : ((i = c).newPos++, o.pushComponent(i.components, !0, void 0)), h = o.extractCommon(i, n, e, t), i.newPos + 1 >= s && h + 1 >= a) return f(r(o, i.components, n, e, o.useLongestToken)); | |
l[t] = i; | |
} else l[t] = void 0; | |
} | |
var g; | |
u++; | |
} | |
if (i) !function e() { | |
setTimeout(function () { | |
if (u > c) return i(); | |
h() || e(); | |
}, 0); | |
}();else for (; u <= c;) { | |
var p = h(); | |
if (p) return p; | |
} | |
}, | |
pushComponent: function pushComponent(e, n, t) { | |
var r = e[e.length - 1]; | |
r && r.added === n && r.removed === t ? e[e.length - 1] = { | |
count: r.count + 1, | |
added: n, | |
removed: t | |
} : e.push({ | |
count: 1, | |
added: n, | |
removed: t | |
}); | |
}, | |
extractCommon: function extractCommon(e, n, t, r) { | |
for (var i = n.length, o = t.length, f = e.newPos, s = f - r, a = 0; f + 1 < i && s + 1 < o && this.equals(n[f + 1], t[s + 1]);) { | |
f++, s++, a++; | |
} | |
return a && e.components.push({ | |
count: a | |
}), e.newPos = f, s; | |
}, | |
equals: function equals(e, n) { | |
return e === n; | |
}, | |
removeEmpty: function removeEmpty(e) { | |
for (var n = [], t = 0; t < e.length; t++) { | |
e[t] && n.push(e[t]); | |
} | |
return n; | |
}, | |
castInput: function castInput(e) { | |
return e; | |
}, | |
tokenize: function tokenize(e) { | |
return e.split(""); | |
} | |
}; | |
}); | |
n(r); | |
var i = t(function (e, n) { | |
n.__esModule = !0, n.characterDiff = void 0, n.diffChars = function (e, n, t) { | |
return o.diff(e, n, t); | |
}; | |
var t, | |
i = (t = r) && t.__esModule ? t : { | |
default: t | |
}; | |
var o = n.characterDiff = new i.default(); | |
}); | |
n(i); | |
i.characterDiff, i.diffChars; | |
var o = t(function (e, n) { | |
n.__esModule = !0, n.generateOptions = function (e, n) { | |
if ("function" == typeof e) n.callback = e;else if (e) for (var t in e) { | |
e.hasOwnProperty(t) && (n[t] = e[t]); | |
} | |
return n; | |
}; | |
}); | |
n(o); | |
o.generateOptions; | |
var f = t(function (e, n) { | |
n.__esModule = !0, n.wordDiff = void 0, n.diffWords = function (e, n, t) { | |
var r = (0, o.generateOptions)(t, { | |
ignoreWhitespace: !0 | |
}); | |
return a.diff(e, n, r); | |
}, n.diffWordsWithSpace = function (e, n, t) { | |
return a.diff(e, n, t); | |
}; | |
var t, | |
i = (t = r) && t.__esModule ? t : { | |
default: t | |
}; | |
var f = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/, | |
s = /\S/, | |
a = n.wordDiff = new i.default(); | |
a.equals = function (e, n) { | |
return e === n || this.options.ignoreWhitespace && !s.test(e) && !s.test(n); | |
}, a.tokenize = function (e) { | |
for (var n = e.split(/(\s+|\b)/), t = 0; t < n.length - 1; t++) { | |
!n[t + 1] && n[t + 2] && f.test(n[t]) && f.test(n[t + 2]) && (n[t] += n[t + 2], n.splice(t + 1, 2), t--); | |
} | |
return n; | |
}; | |
}); | |
n(f); | |
f.wordDiff, f.diffWords, f.diffWordsWithSpace; | |
var s = t(function (e, n) { | |
n.__esModule = !0, n.lineDiff = void 0, n.diffLines = function (e, n, t) { | |
return f.diff(e, n, t); | |
}, n.diffTrimmedLines = function (e, n, t) { | |
var r = (0, o.generateOptions)(t, { | |
ignoreWhitespace: !0 | |
}); | |
return f.diff(e, n, r); | |
}; | |
var t, | |
i = (t = r) && t.__esModule ? t : { | |
default: t | |
}; | |
var f = n.lineDiff = new i.default(); | |
f.tokenize = function (e) { | |
var n = [], | |
t = e.split(/(\n|\r\n)/); | |
t[t.length - 1] || t.pop(); | |
for (var r = 0; r < t.length; r++) { | |
var i = t[r]; | |
r % 2 && !this.options.newlineIsToken ? n[n.length - 1] += i : (this.options.ignoreWhitespace && (i = i.trim()), n.push(i)); | |
} | |
return n; | |
}; | |
}); | |
n(s); | |
s.lineDiff, s.diffLines, s.diffTrimmedLines; | |
var a = t(function (e, n) { | |
n.__esModule = !0, n.sentenceDiff = void 0, n.diffSentences = function (e, n, t) { | |
return o.diff(e, n, t); | |
}; | |
var t, | |
i = (t = r) && t.__esModule ? t : { | |
default: t | |
}; | |
var o = n.sentenceDiff = new i.default(); | |
o.tokenize = function (e) { | |
return e.split(/(\S.+?[.!?])(?=\s+|$)/); | |
}; | |
}); | |
n(a); | |
a.sentenceDiff, a.diffSentences; | |
var u = t(function (e, n) { | |
n.__esModule = !0, n.cssDiff = void 0, n.diffCss = function (e, n, t) { | |
return o.diff(e, n, t); | |
}; | |
var t, | |
i = (t = r) && t.__esModule ? t : { | |
default: t | |
}; | |
var o = n.cssDiff = new i.default(); | |
o.tokenize = function (e) { | |
return e.split(/([{}:;,]|\s+)/); | |
}; | |
}); | |
n(u); | |
u.cssDiff, u.diffCss; | |
var c = t(function (e, n) { | |
n.__esModule = !0, n.jsonDiff = void 0; | |
var t = "function" == typeof Symbol && "symbol" == _typeof(Symbol.iterator) ? function (e) { | |
return _typeof(e); | |
} : function (e) { | |
return e && "function" == typeof Symbol && e.constructor === Symbol ? "symbol" : _typeof(e); | |
}; | |
n.diffJson = function (e, n, t) { | |
return a.diff(e, n, t); | |
}, n.canonicalize = u; | |
var i, | |
o = (i = r) && i.__esModule ? i : { | |
default: i | |
}; | |
var f = Object.prototype.toString, | |
a = n.jsonDiff = new o.default(); | |
function u(e, n, r) { | |
n = n || [], r = r || []; | |
var i = void 0; | |
for (i = 0; i < n.length; i += 1) { | |
if (n[i] === e) return r[i]; | |
} | |
var o = void 0; | |
if ("[object Array]" === f.call(e)) { | |
for (n.push(e), o = new Array(e.length), r.push(o), i = 0; i < e.length; i += 1) { | |
o[i] = u(e[i], n, r); | |
} | |
return n.pop(), r.pop(), o; | |
} | |
if (e && e.toJSON && (e = e.toJSON()), "object" === (void 0 === e ? "undefined" : t(e)) && null !== e) { | |
n.push(e), o = {}, r.push(o); | |
var s = [], | |
a = void 0; | |
for (a in e) { | |
e.hasOwnProperty(a) && s.push(a); | |
} | |
for (s.sort(), i = 0; i < s.length; i += 1) { | |
o[a = s[i]] = u(e[a], n, r); | |
} | |
n.pop(), r.pop(); | |
} else o = e; | |
return o; | |
} | |
a.useLongestToken = !0, a.tokenize = s.lineDiff.tokenize, a.castInput = function (e) { | |
return "string" == typeof e ? e : JSON.stringify(u(e), void 0, " "); | |
}, a.equals = function (e, n) { | |
return o.default.prototype.equals(e.replace(/,([\r\n])/g, "$1"), n.replace(/,([\r\n])/g, "$1")); | |
}; | |
}); | |
n(c); | |
c.jsonDiff, c.diffJson, c.canonicalize; | |
var l = t(function (e, n) { | |
n.__esModule = !0, n.parsePatch = function (e) { | |
var n = arguments.length <= 1 || void 0 === arguments[1] ? {} : arguments[1], | |
t = e.split("\n"), | |
r = [], | |
i = 0; | |
function o() { | |
var e = {}; | |
for (r.push(e); i < t.length;) { | |
var o = t[i]; | |
if (/^(\-\-\-|\+\+\+|@@)\s/.test(o)) break; | |
var a = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(o); | |
a && (e.index = a[1]), i++; | |
} | |
for (f(e), f(e), e.hunks = []; i < t.length;) { | |
var u = t[i]; | |
if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(u)) break; | |
if (/^@@/.test(u)) e.hunks.push(s());else { | |
if (u && n.strict) throw new Error("Unknown line " + (i + 1) + " " + JSON.stringify(u)); | |
i++; | |
} | |
} | |
} | |
function f(e) { | |
var n = /^(\-\-\-|\+\+\+)\s+(\S*)\s?(.*?)\s*$/.exec(t[i]); | |
if (n) { | |
var r = "---" === n[1] ? "old" : "new"; | |
e[r + "FileName"] = n[2], e[r + "Header"] = n[3], i++; | |
} | |
} | |
function s() { | |
for (var e = i, r = t[i++], o = r.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/), f = { | |
oldStart: +o[1], | |
oldLines: +o[2] || 1, | |
newStart: +o[3], | |
newLines: +o[4] || 1, | |
lines: [] | |
}, s = 0, a = 0; i < t.length; i++) { | |
var u = t[i][0]; | |
if ("+" !== u && "-" !== u && " " !== u && "\\" !== u) break; | |
f.lines.push(t[i]), "+" === u ? s++ : "-" === u ? a++ : " " === u && (s++, a++); | |
} | |
if (s || 1 !== f.newLines || (f.newLines = 0), a || 1 !== f.oldLines || (f.oldLines = 0), n.strict) { | |
if (s !== f.newLines) throw new Error("Added line count did not match for hunk at line " + (e + 1)); | |
if (a !== f.oldLines) throw new Error("Removed line count did not match for hunk at line " + (e + 1)); | |
} | |
return f; | |
} | |
for (; i < t.length;) { | |
o(); | |
} | |
return r; | |
}; | |
}); | |
n(l); | |
l.parsePatch; | |
var d = t(function (e, n) { | |
n.__esModule = !0, n.default = function (e, n, t) { | |
var r = !0, | |
i = !1, | |
o = !1, | |
f = 1; | |
return function s() { | |
if (r && !o) { | |
if (i ? f++ : r = !1, e + f <= t) return f; | |
o = !0; | |
} | |
if (!i) return o || (r = !0), n <= e - f ? -f++ : (i = !0, s()); | |
}; | |
}; | |
}); | |
n(d); | |
var h = t(function (e, n) { | |
n.__esModule = !0, n.applyPatch = i, n.applyPatches = function (e, n) { | |
"string" == typeof e && (e = (0, l.parsePatch)(e)); | |
var t = 0; | |
!function r() { | |
var o = e[t++]; | |
if (!o) return n.complete(); | |
n.loadFile(o, function (e, t) { | |
if (e) return n.complete(e); | |
var f = i(t, o, n); | |
n.patched(o, f), setTimeout(r, 0); | |
}); | |
}(); | |
}; | |
var t, | |
r = (t = d) && t.__esModule ? t : { | |
default: t | |
}; | |
function i(e, n) { | |
var t = arguments.length <= 2 || void 0 === arguments[2] ? {} : arguments[2]; | |
if ("string" == typeof n && (n = (0, l.parsePatch)(n)), Array.isArray(n)) { | |
if (n.length > 1) throw new Error("applyPatch only works with a single input."); | |
n = n[0]; | |
} | |
var i = e.split("\n"), | |
o = n.hunks, | |
f = t.compareLine || function (e, n, t, r) { | |
return n === r; | |
}, | |
s = 0, | |
a = t.fuzzFactor || 0, | |
u = 0, | |
c = 0, | |
d = void 0, | |
h = void 0; | |
function p(e, n) { | |
for (var t = 0; t < e.lines.length; t++) { | |
var r = e.lines[t], | |
o = r[0], | |
u = r.substr(1); | |
if (" " === o || "-" === o) { | |
if (!f(n + 1, i[n], o, u) && ++s > a) return !1; | |
n++; | |
} | |
} | |
return !0; | |
} | |
for (var v = 0; v < o.length; v++) { | |
for (var g = o[v], y = i.length - g.oldLines, m = 0, w = c + g.oldStart - 1, _ = (0, r.default)(w, u, y); void 0 !== m; m = _()) { | |
if (p(g, w + m)) { | |
g.offset = c += m; | |
break; | |
} | |
} | |
if (void 0 === m) return !1; | |
u = g.offset + g.oldStart + g.oldLines; | |
} | |
for (var P = 0; P < o.length; P++) { | |
var b = o[P], | |
x = b.offset + b.newStart - 1; | |
0 == b.newLines && x++; | |
for (var L = 0; L < b.lines.length; L++) { | |
var M = b.lines[L], | |
D = M[0], | |
k = M.substr(1); | |
if (" " === D) x++;else if ("-" === D) i.splice(x, 1);else if ("+" === D) i.splice(x, 0, k), x++;else if ("\\" === D) { | |
var S = b.lines[L - 1] ? b.lines[L - 1][0] : null; | |
"+" === S ? d = !0 : "-" === S && (h = !0); | |
} | |
} | |
} | |
if (d) for (; !i[i.length - 1];) { | |
i.pop(); | |
} else h && i.push(""); | |
return i.join("\n"); | |
} | |
}); | |
n(h); | |
h.applyPatch, h.applyPatches; | |
var p = t(function (e, n) { | |
function t(e) { | |
if (Array.isArray(e)) { | |
for (var n = 0, t = Array(e.length); n < e.length; n++) { | |
t[n] = e[n]; | |
} | |
return t; | |
} | |
return Array.from(e); | |
} | |
function r(e, n, r, i, o, f, a) { | |
a || (a = { | |
context: 4 | |
}); | |
var u = (0, s.diffLines)(r, i); | |
function c(e) { | |
return e.map(function (e) { | |
return " " + e; | |
}); | |
} | |
u.push({ | |
value: "", | |
lines: [] | |
}); | |
for (var l = [], d = 0, h = 0, p = [], v = 1, g = 1, y = function y(e) { | |
var n = u[e], | |
o = n.lines || n.value.replace(/\n$/, "").split("\n"); | |
if (n.lines = o, n.added || n.removed) { | |
var f; | |
if (!d) { | |
var s = u[e - 1]; | |
d = v, h = g, s && (p = a.context > 0 ? c(s.lines.slice(-a.context)) : [], d -= p.length, h -= p.length); | |
} | |
(f = p).push.apply(f, t(o.map(function (e) { | |
return (n.added ? "+" : "-") + e; | |
}))), n.added ? g += o.length : v += o.length; | |
} else { | |
if (d) if (o.length <= 2 * a.context && e < u.length - 2) { | |
var y; | |
(y = p).push.apply(y, t(c(o))); | |
} else { | |
var m, | |
w = Math.min(o.length, a.context); | |
(m = p).push.apply(m, t(c(o.slice(0, w)))); | |
var _ = { | |
oldStart: d, | |
oldLines: v - d + w, | |
newStart: h, | |
newLines: g - h + w, | |
lines: p | |
}; | |
if (e >= u.length - 2 && o.length <= a.context) { | |
var P = /\n$/.test(r), | |
b = /\n$/.test(i); | |
0 != o.length || P ? P && b || p.push("\\ No newline at end of file") : p.splice(_.oldLines, 0, "\\ No newline at end of file"); | |
} | |
l.push(_), d = 0, h = 0, p = []; | |
} | |
v += o.length, g += o.length; | |
} | |
}, m = 0; m < u.length; m++) { | |
y(m); | |
} | |
return { | |
oldFileName: e, | |
newFileName: n, | |
oldHeader: o, | |
newHeader: f, | |
hunks: l | |
}; | |
} | |
function i(e, n, t, i, o, f, s) { | |
var a = r(e, n, t, i, o, f, s), | |
u = []; | |
e == n && u.push("Index: " + e), u.push("==================================================================="), u.push("--- " + a.oldFileName + (void 0 === a.oldHeader ? "" : "\t" + a.oldHeader)), u.push("+++ " + a.newFileName + (void 0 === a.newHeader ? "" : "\t" + a.newHeader)); | |
for (var c = 0; c < a.hunks.length; c++) { | |
var l = a.hunks[c]; | |
u.push("@@ -" + l.oldStart + "," + l.oldLines + " +" + l.newStart + "," + l.newLines + " @@"), u.push.apply(u, l.lines); | |
} | |
return u.join("\n") + "\n"; | |
} | |
n.__esModule = !0, n.structuredPatch = r, n.createTwoFilesPatch = i, n.createPatch = function (e, n, t, r, o, f) { | |
return i(e, e, n, t, r, o, f); | |
}; | |
}); | |
n(p); | |
p.structuredPatch, p.createTwoFilesPatch, p.createPatch; | |
var v = t(function (e, n) { | |
n.__esModule = !0, n.convertChangesToDMP = function (e) { | |
for (var n = [], t = void 0, r = void 0, i = 0; i < e.length; i++) { | |
t = e[i], r = t.added ? 1 : t.removed ? -1 : 0, n.push([r, t.value]); | |
} | |
return n; | |
}; | |
}); | |
n(v); | |
v.convertChangesToDMP; | |
var g = t(function (e, n) { | |
function t(e) { | |
var n = e; | |
return n = (n = (n = (n = n.replace(/&/g, "&")).replace(/</g, "<")).replace(/>/g, ">")).replace(/"/g, """); | |
} | |
n.__esModule = !0, n.convertChangesToXML = function (e) { | |
for (var n = [], r = 0; r < e.length; r++) { | |
var i = e[r]; | |
i.added ? n.push("<ins>") : i.removed && n.push("<del>"), n.push(t(i.value)), i.added ? n.push("</ins>") : i.removed && n.push("</del>"); | |
} | |
return n.join(""); | |
}; | |
}); | |
n(g); | |
g.convertChangesToXML; | |
var y = t(function (e, n) { | |
n.__esModule = !0, n.canonicalize = n.convertChangesToXML = n.convertChangesToDMP = n.parsePatch = n.applyPatches = n.applyPatch = n.createPatch = n.createTwoFilesPatch = n.structuredPatch = n.diffJson = n.diffCss = n.diffSentences = n.diffTrimmedLines = n.diffLines = n.diffWordsWithSpace = n.diffWords = n.diffChars = n.Diff = void 0; | |
var t, | |
o = (t = r) && t.__esModule ? t : { | |
default: t | |
}; | |
n.Diff = o.default, n.diffChars = i.diffChars, n.diffWords = f.diffWords, n.diffWordsWithSpace = f.diffWordsWithSpace, n.diffLines = s.diffLines, n.diffTrimmedLines = s.diffTrimmedLines, n.diffSentences = a.diffSentences, n.diffCss = u.diffCss, n.diffJson = c.diffJson, n.structuredPatch = p.structuredPatch, n.createTwoFilesPatch = p.createTwoFilesPatch, n.createPatch = p.createPatch, n.applyPatch = h.applyPatch, n.applyPatches = h.applyPatches, n.parsePatch = l.parsePatch, n.convertChangesToDMP = v.convertChangesToDMP, n.convertChangesToXML = g.convertChangesToXML, n.canonicalize = c.canonicalize; | |
}); | |
n(y); | |
y.canonicalize, y.convertChangesToXML, y.convertChangesToDMP, y.parsePatch, y.applyPatches, y.applyPatch, y.createPatch, y.createTwoFilesPatch, y.structuredPatch, y.diffJson, y.diffCss, y.diffSentences, y.diffTrimmedLines, y.diffLines, y.diffWordsWithSpace, y.diffWords, y.diffChars, y.Diff; | |
function m(e, n) { | |
var t = 0; | |
for (var _r = 0; _r < e.length; _r++) { | |
switch (e[_r].type) { | |
case P: | |
t += n[0]; | |
break; | |
case _: | |
t += n[1]; | |
break; | |
case b: | |
t++; | |
break; | |
default: | |
throw Error("unknown change type: " + e[_r].type); | |
} | |
} | |
return t; | |
} | |
function w(e, n, t) { | |
this.changes = t, this.aoff = e, this.boff = n, this._alen = -1, this._blen = -1; | |
} | |
Object.defineProperty(w.prototype, "alen", { | |
get: function get() { | |
return -1 === this._alen ? this._alen = m(this.changes, [1, 0]) : this._alen; | |
} | |
}), Object.defineProperty(w.prototype, "blen", { | |
get: function get() { | |
return -1 === this._blen ? this._blen = m(this.changes, [0, 1]) : this._blen; | |
} | |
}), w.prototype.unified = function () { | |
var e = [this.unifiedHeader()]; | |
return this.changes.forEach(function (n) { | |
e.push(n.unified()); | |
}), e.join("\n"); | |
}, w.prototype.unifiedHeader = function () { | |
var e = 1 === this.alen ? "" : "," + this.alen, | |
n = 1 === this.blen ? "" : "," + this.blen, | |
t = 0 === this.alen ? 0 : 1, | |
r = 0 === this.blen ? 0 : 1; | |
return "@@ -" + (this.aoff + t) + e + " +" + (this.boff + r) + n + " @@"; | |
}, w.prototype.shorthand = function () { | |
return this.changes.reduce(function (e, n) { | |
return e + n.type; | |
}, ""); | |
}, w.prototype.toString = function () { | |
return "{" + this.shorthand() + "} " + this.unifiedHeader(); | |
}; | |
var _ = "+", | |
P = "-", | |
b = "s"; | |
function x(e) { | |
return "s" === e ? " " : e; | |
} | |
function L(e, n) { | |
this.type = e, this.text = n; | |
} | |
function M(e, n) { | |
if (0 === n) return []; | |
var t = [], | |
r = e.value; | |
if (void 0 === n) (t = r.split("\n"))[t.length - 1] || t.pop();else if (n > 0) { | |
var _e = k(r, "\n", 0, n, !1); | |
t = r.substring(0, _e).split("\n"); | |
} else { | |
var _e2 = "\n" === r[r.length - 1] ? r.length - 1 : r.length, | |
_i = k(r, "\n", _e2 - 1, -n, !0); | |
t = r.substring(_i + 1, _e2).split("\n"); | |
} | |
return t.map(function (n) { | |
return new L(e.type, n); | |
}); | |
} | |
function D(e, n) { | |
return Array.prototype.push.apply(n, e), n; | |
} | |
function k(e, n, t, r, i) { | |
var o = i ? -1 : 1; | |
t -= o; | |
for (var _f = 0; _f < r; _f++) { | |
t = i ? e.lastIndexOf(n, t + o) : e.indexOf(n, t + o); | |
} | |
return t; | |
} | |
L.prototype.unified = function () { | |
return x(this.type) + this.text; | |
}, L.prototype.toString = function () { | |
return this.unified(); | |
}; | |
var S = { | |
hunk: function hunk(e, n, t) { | |
return new w(e, n, t); | |
}, | |
linechange: function linechange(e, n) { | |
return new L(e, n); | |
}, | |
lineChanges: M, | |
change2string: function change2string(e, n) { | |
n = n || 60; | |
var t = e.count + ": " + x(e.type), | |
r = Math.min(n - t.length, e.value.length - 1); | |
return t + (e.value.substring(0, r).replace(/\n/g, ",") + (e.value.length > r + 1 ? "..." : "")); | |
}, | |
changes2shorthand: function changes2shorthand(e) { | |
return "{" + e.reduce(function (e, n) { | |
for (var _t = 0; _t < n.count; _t++) { | |
e += n.type; | |
} | |
return e; | |
}, "") + "}"; | |
}, | |
nthIndexOf: k, | |
makeHunks: function makeHunks(e, n, t) { | |
var r = [], | |
i = [], | |
o = 0; | |
function f() { | |
if (i.length) { | |
var _e3 = o, | |
_n = o; | |
if (r.length) { | |
var _t2 = r[r.length - 1]; | |
_e3 += _t2.aoff + _t2.alen, _n += _t2.boff + _t2.blen; | |
} | |
r.push(new w(_e3, _n, i)), i = [], o = 0; | |
} | |
} | |
for (var _r2 = 0; _r2 < e.length; _r2++) { | |
var _s = e[_r2]; | |
if (_s.type === b) { | |
var _a = _r2 > 0 ? t : 0, | |
_u = _r2 < e.length - 1 ? n : 0, | |
_c = Math.max(_s.count - (_a + _u), 0); | |
_c > 0 ? (D(M(_s, _a), i), f(), D(M(_s, -_u), i), o = _c) : D(M(_s), i); | |
} else D(M(_s), i); | |
} | |
return f(), r; | |
}, | |
ADDED: _, | |
REMOVED: P, | |
UNMODIFIED: b | |
}, | |
C = t(function (e, n) { | |
function t(e) { | |
return e.added ? S.ADDED : e.removed ? S.REMOVED : S.UNMODIFIED; | |
} | |
function r(e, n) { | |
!function (e) { | |
0 === e.length || (e[0].type = t(e[0]), e.reduce(function (e, n, r) { | |
if (n.type = t(n), e.type === n.type) throw Error("repeating change types are not handled: " + e.type + " (at " + (r - 1) + " and " + r + ")"); | |
return n; | |
})); | |
}(e), (n = n || {}).aname = n.aname || "a", n.bname = n.bname || "b"; | |
var r = n.context || 0 === n.context ? n.context : 0; | |
n.pre_context = n.pre_context || 0 === n.pre_context ? n.pre_context : r, n.post_context = n.post_context || 0 === n.post_context ? n.post_context : r; | |
var i = S.makeHunks(e, n.pre_context, n.post_context); | |
if (i.length) { | |
var _e4 = []; | |
return _e4.push("--- " + n.aname), _e4.push("+++ " + n.bname), i.forEach(function (n) { | |
_e4.push(n.unified()); | |
}), _e4.join("\n"); | |
} | |
return ""; | |
} | |
function i(e, n, t) { | |
e = Array.isArray(e) ? e.join("\n") + "\n" : e, n = Array.isArray(n) ? n.join("\n") + "\n" : n; | |
var r = y.diffLines(e, n, t); | |
return 1 !== r.length || r[0].added || r[0].removed ? r : []; | |
} | |
function o(e, n, t) { | |
return r(i(e, n), t); | |
} | |
n.assertEqual = function (e, n, t, r, i) { | |
i = i || console.log, t = t.ok || t; | |
var f = o(e, n, { | |
context: 3, | |
aname: r + " (actual)", | |
bname: r + " (expected)" | |
}); | |
t(!f, r), f && f.split("\n").forEach(function (e) { | |
i(" " + e); | |
}); | |
}, n.diffAsText = o, n.formatLines = r, n.diffLines = i, Object.keys(y).forEach(function (e) { | |
n[e] || (n[e] = y[e]); | |
}); | |
}), | |
T = C.assertEqual, | |
E = C.diffAsText, | |
O = C.formatLines, | |
j = C.diffLines; | |
e.default = C, e.assertEqual = T, e.diffAsText = E, e.formatLines = O, e.diffLines = j, Object.defineProperty(e, "__esModule", { | |
value: !0 | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment