diff --git a/javascript/.gitignore b/javascript/.gitignore new file mode 100644 index 0000000..0db216b --- /dev/null +++ b/javascript/.gitignore @@ -0,0 +1,2 @@ +npm-debug.log +node_modules diff --git a/javascript/.npmignore b/javascript/.npmignore new file mode 100644 index 0000000..2b29f27 --- /dev/null +++ b/javascript/.npmignore @@ -0,0 +1 @@ +tests diff --git a/javascript/diff_match_patch.js b/javascript/diff_match_patch.js deleted file mode 100644 index 4df161e..0000000 --- a/javascript/diff_match_patch.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict';var diff_match_patch=function(){this.Diff_Timeout=1;this.Diff_EditCost=4;this.Match_Threshold=.5;this.Match_Distance=1E3;this.Patch_DeleteThreshold=.5;this.Patch_Margin=4;this.Match_MaxBits=32},DIFF_DELETE=-1,DIFF_INSERT=1,DIFF_EQUAL=0;diff_match_patch.Diff=function(a,b){this[0]=a;this[1]=b};diff_match_patch.Diff.prototype.length=2;diff_match_patch.Diff.prototype.toString=function(){return this[0]+","+this[1]}; -diff_match_patch.Diff.prototype[Symbol.iterator]=function*(){yield this[0];yield this[1]}; -diff_match_patch.prototype.diff_main=function(a,b,d,c){"undefined"==typeof c&&(c=0>=this.Diff_Timeout?Number.MAX_VALUE:(new Date).getTime()+1E3*this.Diff_Timeout);if(null==a||null==b)throw Error("Null input. (diff_main)");if(a==b)return a?[new diff_match_patch.Diff(DIFF_EQUAL,a)]:[];"undefined"==typeof d&&(d=!0);var e=d,f=this.diff_commonPrefix(a,b);d=a.substring(0,f);a=a.substring(f);b=b.substring(f);f=this.diff_commonSuffix(a,b);var g=a.substring(a.length-f);a=a.substring(0,a.length-f);b=b.substring(0, -b.length-f);a=this.diff_compute_(a,b,e,c);d&&a.unshift(new diff_match_patch.Diff(DIFF_EQUAL,d));g&&a.push(new diff_match_patch.Diff(DIFF_EQUAL,g));this.diff_cleanupMerge(a);return a}; -diff_match_patch.prototype.diff_compute_=function(a,b,d,c){if(!a)return[new diff_match_patch.Diff(DIFF_INSERT,b)];if(!b)return[new diff_match_patch.Diff(DIFF_DELETE,a)];var e=a.length>b.length?a:b,f=a.length>b.length?b:a,g=e.indexOf(f);return-1!=g?(d=[new diff_match_patch.Diff(DIFF_INSERT,e.substring(0,g)),new diff_match_patch.Diff(DIFF_EQUAL,f),new diff_match_patch.Diff(DIFF_INSERT,e.substring(g+f.length))],a.length>b.length&&(d[0][0]=d[2][0]=DIFF_DELETE),d):1==f.length?[new diff_match_patch.Diff(DIFF_DELETE, -a),new diff_match_patch.Diff(DIFF_INSERT,b)]:(e=this.diff_halfMatch_(a,b))?(b=e[1],f=e[3],a=e[4],e=this.diff_main(e[0],e[2],d,c),d=this.diff_main(b,f,d,c),e.concat([new diff_match_patch.Diff(DIFF_EQUAL,a)],d)):d&&100d);u++){for(var t=-u+n;t<=u-w;t+=2){var p=f+t;var r=t==-u||t!=u&&h[p-1]c)w+=2;else if(y>e)n+=2;else if(m&&(p=f+k-t,0<=p&&p= -x)return this.diff_bisectSplit_(a,b,r,y,d)}}for(t=-u+v;t<=u-q;t+=2){p=f+t;x=t==-u||t!=u&&l[p-1]c)q+=2;else if(r>e)v+=2;else if(!m&&(p=f+k-t,0<=p&&p=x)))return this.diff_bisectSplit_(a,b,r,y,d)}}return[new diff_match_patch.Diff(DIFF_DELETE,a),new diff_match_patch.Diff(DIFF_INSERT,b)]}; -diff_match_patch.prototype.diff_bisectSplit_=function(a,b,d,c,e){var f=a.substring(0,d),g=b.substring(0,c);a=a.substring(d);b=b.substring(c);f=this.diff_main(f,g,!1,e);e=this.diff_main(a,b,!1,e);return f.concat(e)}; -diff_match_patch.prototype.diff_linesToChars_=function(a,b){function d(g){for(var h="",l=0,k=-1,m=c.length;kc?a=a.substring(d-c):d=h.length?[v,q,u,t,w]:null}if(0>=this.Diff_Timeout)return null; -var c=a.length>b.length?a:b,e=a.length>b.length?b:a;if(4>c.length||2*e.lengthc[4].length?g:c:c:g;else return null;a.length>b.length?(a=g[0],b=g[1],c=g[2],e=g[3]):(c=g[0],e=g[1],a=g[2],b=g[3]);return[a,b,c,e,g[4]]}; -diff_match_patch.prototype.diff_cleanupSemantic=function(a){for(var b=!1,d=[],c=0,e=null,f=0,g=0,h=0,l=0,k=0;f=e){if(c>=b.length/2||c>=d.length/2)a.splice(f,0,new diff_match_patch.Diff(DIFF_EQUAL,d.substring(0,c))),a[f-1][1]=b.substring(0,b.length-c),a[f+1][1]=d.substring(c),f++}else if(e>=b.length/2||e>=d.length/2)a.splice(f,0,new diff_match_patch.Diff(DIFF_EQUAL,b.substring(0,e))),a[f-1][0]=DIFF_INSERT,a[f-1][1]=d.substring(0,d.length-e),a[f+1][0]=DIFF_DELETE, -a[f+1][1]=b.substring(e),f++;f++}f++}}; -diff_match_patch.prototype.diff_cleanupSemanticLossless=function(a){function b(n,w){if(!n||!w)return 6;var v=n.charAt(n.length-1),q=w.charAt(0),u=v.match(diff_match_patch.nonAlphaNumericRegex_),t=q.match(diff_match_patch.nonAlphaNumericRegex_),p=u&&v.match(diff_match_patch.whitespaceRegex_),r=t&&q.match(diff_match_patch.whitespaceRegex_);v=p&&v.match(diff_match_patch.linebreakRegex_);q=r&&q.match(diff_match_patch.linebreakRegex_);n=v&&n.match(diff_match_patch.blanklineEndRegex_);w=q&&w.match(diff_match_patch.blanklineStartRegex_); -return n||w?5:v||q?4:u&&!p&&r?3:p||r?2:u||t?1:0}for(var d=1;d=k&&(k=m,g=c,h=e,l=f)}a[d-1][1]!=g&&(g?a[d-1][1]=g:(a.splice(d- -1,1),d--),a[d][1]=h,l?a[d+1][1]=l:(a.splice(d+1,1),d--))}d++}};diff_match_patch.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;diff_match_patch.whitespaceRegex_=/\s/;diff_match_patch.linebreakRegex_=/[\r\n]/;diff_match_patch.blanklineEndRegex_=/\n\r?\n$/;diff_match_patch.blanklineStartRegex_=/^\r?\n\r?\n/; -diff_match_patch.prototype.diff_cleanupEfficiency=function(a){for(var b=!1,d=[],c=0,e=null,f=0,g=!1,h=!1,l=!1,k=!1;f=a}; -diff_match_patch.prototype.isLowSurrogate=function(a){a=a.charCodeAt(0);return 56320<=a&&57343>=a}; -diff_match_patch.prototype.digit16=function(a){switch(a){case "0":return 0;case "1":return 1;case "2":return 2;case "3":return 3;case "4":return 4;case "5":return 5;case "6":return 6;case "7":return 7;case "8":return 8;case "9":return 9;case "A":case "a":return 10;case "B":case "b":return 11;case "C":case "c":return 12;case "D":case "d":return 13;case "E":case "e":return 14;case "F":case "f":return 15;default:throw Error("Invalid hex-code");}}; -diff_match_patch.prototype.decodeURI=function(a){try{return decodeURI(a)}catch(h){for(var b=0,d="";b=c)){d+=String.fromCharCode((c&65535)>>>10&1023|55296);d+=String.fromCharCode(56320|c&1023); -b+=12;continue}throw new URIError("URI malformed");}}}}return d}};diff_match_patch.prototype.diff_xIndex=function(a,b){var d=0,c=0,e=0,f=0,g;for(g=0;gb)break;e=d;f=c}return a.length!=g&&a[g][0]===DIFF_DELETE?f:f+(b-e)}; -diff_match_patch.prototype.diff_prettyHtml=function(a){a=this.diff_cleanupSplitSurrogates(a);for(var b=[],d=/&/g,c=//g,f=/\n/g,g=0;g");switch(h){case DIFF_INSERT:b[g]=''+l+"";break;case DIFF_DELETE:b[g]=''+l+"";break;case DIFF_EQUAL:b[g]=""+l+""}}return b.join("")}; -diff_match_patch.prototype.diff_text1=function(a){for(var b=[],d=0;dthis.Match_MaxBits)throw Error("Pattern too long for this browser.");var e=this.match_alphabet_(b),f=this,g=this.Match_Threshold,h=a.indexOf(b,d);-1!=h&&(g=Math.min(c(0,h),g),h=a.lastIndexOf(b,d+b.length),-1!=h&&(g=Math.min(c(0,h),g)));var l=1<=k;q--){var u=e[a.charAt(q-1)];m[q]=0===v?(m[q+1]<<1|1)&u:(m[q+1]<<1|1)&u|(w[q+1]|w[q])<<1|1|w[q+1];if(m[q]&l&&(u=c(v,q-1),u<=g))if(g=u,h=q-1,h>d)k=Math.max(1,2*d-h);else break}if(c(v+1,d)>g)break;w=m}return h}; -diff_match_patch.prototype.match_alphabet_=function(a){for(var b={},d=0;d=2*this.Patch_Margin&&e&&(this.patch_addContext_(a,h),d.push(a),a=new diff_match_patch.patch_obj,e=0,h=c,f=g)}k!==DIFF_INSERT&&(f+=m.length);k!==DIFF_DELETE&&(g+=m.length)}e&&(this.patch_addContext_(a,h),d.push(a));return d}; -diff_match_patch.prototype.patch_deepCopy=function(a){for(var b=[],d=0;dthis.Match_MaxBits){var k=this.match_main(b,h.substring(0,this.Match_MaxBits),g);-1!=k&&(l=this.match_main(b,h.substring(h.length-this.Match_MaxBits),g+h.length-this.Match_MaxBits),-1==l||k>=l)&&(k=-1)}else k=this.match_main(b,h, -g);if(-1==k)e[f]=!1,c-=a[f].length2-a[f].length1;else if(e[f]=!0,c=k-g,g=-1==l?b.substring(k,k+h.length):b.substring(k,l+this.Match_MaxBits),h==g)b=b.substring(0,k)+this.diff_text2(a[f].diffs)+b.substring(k+h.length);else if(g=this.diff_main(h,g,!1),h.length>this.Match_MaxBits&&this.diff_levenshtein(g)/h.length>this.Patch_DeleteThreshold)e[f]=!1;else{this.diff_cleanupSemanticLossless(g);h=0;var m;for(l=0;le[0][1].length){var f=b-e[0][1].length;e[0][1]=d.substring(e[0][1].length)+e[0][1];c.start1-=f;c.start2-=f;c.length1+=f;c.length2+=f}c=a[a.length-1];e=c.diffs; -0==e.length||e[e.length-1][0]!=DIFF_EQUAL?(e.push(new diff_match_patch.Diff(DIFF_EQUAL,d)),c.length1+=b,c.length2+=b):b>e[e.length-1][1].length&&(f=b-e[e.length-1][1].length,e[e.length-1][1]+=d.substring(0,f),c.length1+=f,c.length2+=f);return d}; -diff_match_patch.prototype.patch_splitMax=function(a){for(var b=this.Match_MaxBits,d=0;d2*b?(h.length1+=k.length,e+=k.length,l=!1,h.diffs.push(new diff_match_patch.Diff(g,k)),c.diffs.shift()):(k=k.substring(0,b-h.length1-this.Patch_Margin),h.length1+=k.length,e+=k.length,g===DIFF_EQUAL?(h.length2+=k.length,f+=k.length):l=!1,h.diffs.push(new diff_match_patch.Diff(g,k)),k==c.diffs[0][1]?c.diffs.shift():c.diffs[0][1]=c.diffs[0][1].substring(k.length))}g=this.diff_text2(h.diffs); -g=g.substring(g.length-this.Patch_Margin);k=this.diff_text1(c.diffs).substring(0,this.Patch_Margin);""!==k&&(h.length1+=k.length,h.length2+=k.length,0!==h.diffs.length&&h.diffs[h.diffs.length-1][0]===DIFF_EQUAL?h.diffs[h.diffs.length-1][1]+=k:h.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,k)));l||a.splice(++d,0,h)}}};diff_match_patch.prototype.patch_toText=function(a){for(var b=[],d=0;d} Array of diff tuples. */ diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines, - opt_deadline) { + opt_deadline) { // Set a deadline by which time the diff must be complete. if (typeof opt_deadline == 'undefined') { if (this.Diff_Timeout <= 0) { @@ -187,7 +187,7 @@ diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines, * @private */ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, - deadline) { + deadline) { var diffs; if (!text1) { @@ -206,9 +206,9 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, if (i != -1) { // Shorter text is inside the longer text (speedup). diffs = [new diff_match_patch.Diff(DIFF_INSERT, longtext.substring(0, i)), - new diff_match_patch.Diff(DIFF_EQUAL, shorttext), - new diff_match_patch.Diff(DIFF_INSERT, - longtext.substring(i + shorttext.length))]; + new diff_match_patch.Diff(DIFF_EQUAL, shorttext), + new diff_match_patch.Diff(DIFF_INSERT, + longtext.substring(i + shorttext.length))]; // Swap insertions for deletions if diff is reversed. if (text1.length > text2.length) { diffs[0][0] = diffs[2][0] = DIFF_DELETE; @@ -220,7 +220,7 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, // Single character string. // After the previous speedup, the character can't be an equality. return [new diff_match_patch.Diff(DIFF_DELETE, text1), - new diff_match_patch.Diff(DIFF_INSERT, text2)]; + new diff_match_patch.Diff(DIFF_INSERT, text2)]; } // Check to see if the problem can be split in two. @@ -237,7 +237,7 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, var diffs_b = this.diff_main(text1_b, text2_b, checklines, deadline); // Merge the results. return diffs_a.concat([new diff_match_patch.Diff(DIFF_EQUAL, mid_common)], - diffs_b); + diffs_b); } if (checklines && text1.length > 100 && text2.length > 100) { @@ -295,7 +295,7 @@ diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) { if (count_delete >= 1 && count_insert >= 1) { // Delete the offending records and add the merged ones. diffs.splice(pointer - count_delete - count_insert, - count_delete + count_insert); + count_delete + count_insert); pointer = pointer - count_delete - count_insert; var subDiff = this.diff_main(text_delete, text_insert, false, deadline); @@ -372,7 +372,7 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { } var y1 = x1 - k1; while (x1 < text1_length && y1 < text2_length && - text1.charAt(x1) == text2.charAt(y1)) { + text1.charAt(x1) == text2.charAt(y1)) { x1++; y1++; } @@ -407,8 +407,8 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { } var y2 = x2 - k2; while (x2 < text1_length && y2 < text2_length && - text1.charAt(text1_length - x2 - 1) == - text2.charAt(text2_length - y2 - 1)) { + text1.charAt(text1_length - x2 - 1) == + text2.charAt(text2_length - y2 - 1)) { x2++; y2++; } @@ -437,7 +437,7 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { // Diff took too long and hit the deadline or // number of diffs equals number of characters, no commonality at all. return [new diff_match_patch.Diff(DIFF_DELETE, text1), - new diff_match_patch.Diff(DIFF_INSERT, text2)]; + new diff_match_patch.Diff(DIFF_INSERT, text2)]; }; @@ -453,7 +453,7 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { * @private */ diff_match_patch.prototype.diff_bisectSplit_ = function(text1, text2, x, y, - deadline) { + deadline) { var text1a = text1.substring(0, x); var text2a = text2.substring(0, y); var text1b = text1.substring(x); @@ -712,9 +712,9 @@ diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { var best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b; while ((j = shorttext.indexOf(seed, j + 1)) != -1) { var prefixLength = dmp.diff_commonPrefix(longtext.substring(i), - shorttext.substring(j)); + shorttext.substring(j)); var suffixLength = dmp.diff_commonSuffix(longtext.substring(0, i), - shorttext.substring(0, j)); + shorttext.substring(0, j)); if (best_common.length < suffixLength + prefixLength) { best_common = shorttext.substring(j - suffixLength, j) + shorttext.substring(j, j + prefixLength); @@ -726,7 +726,7 @@ diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { } if (best_common.length * 2 >= longtext.length) { return [best_longtext_a, best_longtext_b, - best_shorttext_a, best_shorttext_b, best_common]; + best_shorttext_a, best_shorttext_b, best_common]; } else { return null; } @@ -734,10 +734,10 @@ diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { // First check if the second quarter is the seed for a half-match. var hm1 = diff_halfMatchI_(longtext, shorttext, - Math.ceil(longtext.length / 4)); + Math.ceil(longtext.length / 4)); // Check again based on the third quarter. var hm2 = diff_halfMatchI_(longtext, shorttext, - Math.ceil(longtext.length / 2)); + Math.ceil(longtext.length / 2)); var hm; if (!hm1 && !hm2) { return null; @@ -803,12 +803,12 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { // Eliminate an equality that is smaller or equal to the edits on both // sides of it. if (lastEquality && (lastEquality.length <= - Math.max(length_insertions1, length_deletions1)) && + Math.max(length_insertions1, length_deletions1)) && (lastEquality.length <= Math.max(length_insertions2, - length_deletions2))) { + length_deletions2))) { // Duplicate record. diffs.splice(equalities[equalitiesLength - 1], 0, - new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); + new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); // Change second copy to insert. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; // Throw away the equality we just deleted. @@ -1063,11 +1063,11 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { * ABXC */ if (lastEquality && ((pre_ins && pre_del && post_ins && post_del) || - ((lastEquality.length < this.Diff_EditCost / 2) && - (pre_ins + pre_del + post_ins + post_del) == 3))) { + ((lastEquality.length < this.Diff_EditCost / 2) && + (pre_ins + pre_del + post_ins + post_del) == 3))) { // Duplicate record. diffs.splice(equalities[equalitiesLength - 1], 0, - new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); + new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); // Change second copy to insert. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; equalitiesLength--; // Throw away the equality we just deleted; @@ -1198,7 +1198,7 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { // Shift the edit over the previous equality. diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - - diffs[pointer - 1][1].length); + diffs[pointer - 1][1].length); diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1]; diffs.splice(pointer - 1, 1); changes = true; @@ -1223,7 +1223,7 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { /** * Rearrange diff boundaries that split Unicode surrogate pairs. - * + * * @param {!Array.} diffs Array of diff tuples. */ diff_match_patch.prototype.diff_cleanupSplitSurrogates = function(diffs) { @@ -1290,17 +1290,17 @@ diff_match_patch.prototype.digit16 = function(c) { /** * Decode URI-encoded string but allow for encoded surrogate halves - * + * * diff_match_patch needs this relaxation of the requirements because * not all libraries and versions produce valid URI strings in toDelta * and we don't want to crash this code when the input is valid input * but at the same time invalid utf-8 - * + * * @example: decodeURI( 'abcd%3A %F0%9F%85%B0' ) = 'abcd: \ud83c\udd70' * @example: decodeURI( 'abcd%3A %ED%A0%BC' ) = 'abcd: \ud83c' - * + * * @cite: @mathiasbynens utf8.js at https://github.com/mathiasbynens/utf8.js - * + * * @param {String} text input string encoded by encodeURI() or equivalent * @return {String} */ @@ -1590,7 +1590,7 @@ diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { // Anything else is an error. if (tokens[x]) { throw new Error('Invalid diff operation in diff_fromDelta: ' + - tokens[x]); + tokens[x]); } } } @@ -1722,8 +1722,8 @@ diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) { rd[j] = ((rd[j + 1] << 1) | 1) & charMatch; } else { // Subsequent passes: fuzzy match. rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) | - (((last_rd[j + 1] | last_rd[j]) << 1) | 1) | - last_rd[j + 1]; + (((last_rd[j + 1] | last_rd[j]) << 1) | 1) | + last_rd[j + 1]; } if (rd[j] & matchmask) { var score = match_bitapScore_(d, j - 1); @@ -1794,19 +1794,19 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { // Look for the first and last matches of pattern in text. If two different // matches are found, increase the pattern length. while (text.indexOf(pattern) != text.lastIndexOf(pattern) && - pattern.length < this.Match_MaxBits - this.Patch_Margin - - this.Patch_Margin) { + pattern.length < this.Match_MaxBits - this.Patch_Margin - + this.Patch_Margin) { padding += this.Patch_Margin; pattern = text.substring(patch.start2 - padding, - patch.start2 + patch.length1 + padding); + patch.start2 + patch.length1 + padding); } // Add one chunk for good luck. padding += this.Patch_Margin; // Add the prefix. if ( - patch.start2 - padding > 0 && - diff_match_patch.prototype.isLowSurrogate(text[patch.start2 - padding]) + patch.start2 - padding > 0 && + diff_match_patch.prototype.isLowSurrogate(text[patch.start2 - padding]) ) { padding++; } @@ -1816,13 +1816,13 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { } // Add the suffix. if ( - patch.start2 + patch.length1 + padding < text.length && - diff_match_patch.prototype.isHighSurrogate(text[patch.start2 + patch.length1 + padding]) + patch.start2 + patch.length1 + padding < text.length && + diff_match_patch.prototype.isHighSurrogate(text[patch.start2 + patch.length1 + padding]) ) { padding++; } var suffix = text.substring(patch.start2 + patch.length1, - patch.start2 + patch.length1 + padding); + patch.start2 + patch.length1 + padding); if (suffix) { patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, suffix)); } @@ -1920,14 +1920,14 @@ diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) { patch.diffs[patchDiffLength++] = diffs[x]; patch.length2 += diff_text.length; postpatch_text = postpatch_text.substring(0, char_count2) + diff_text + - postpatch_text.substring(char_count2); + postpatch_text.substring(char_count2); break; case DIFF_DELETE: patch.length1 += diff_text.length; patch.diffs[patchDiffLength++] = diffs[x]; postpatch_text = postpatch_text.substring(0, char_count2) + - postpatch_text.substring(char_count2 + - diff_text.length); + postpatch_text.substring(char_count2 + + diff_text.length); break; case DIFF_EQUAL: if (diff_text.length <= 2 * this.Patch_Margin && @@ -2033,7 +2033,7 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { // patch_splitMax will only provide an oversized pattern in the case of // a monster delete. start_loc = this.match_main(text, text1.substring(0, this.Match_MaxBits), - expected_loc); + expected_loc); if (start_loc != -1) { end_loc = this.match_main(text, text1.substring(text1.length - this.Match_MaxBits), @@ -2064,8 +2064,8 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { if (text1 == text2) { // Perfect match, just shove the replacement text in. text = text.substring(0, start_loc) + - this.diff_text2(patches[x].diffs) + - text.substring(start_loc + text1.length); + this.diff_text2(patches[x].diffs) + + text.substring(start_loc + text1.length); } else { // Imperfect match. Run a diff to get a framework of equivalent // indices. @@ -2086,11 +2086,11 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { } if (mod[0] === DIFF_INSERT) { // Insertion text = text.substring(0, start_loc + index2) + mod[1] + - text.substring(start_loc + index2); + text.substring(start_loc + index2); } else if (mod[0] === DIFF_DELETE) { // Deletion text = text.substring(0, start_loc + index2) + - text.substring(start_loc + this.diff_xIndex(diffs, - index1 + mod[1].length)); + text.substring(start_loc + this.diff_xIndex(diffs, + index1 + mod[1].length)); } if (mod[0] !== DIFF_DELETE) { index1 += mod[1].length; @@ -2194,7 +2194,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, precontext)); } while (bigpatch.diffs.length !== 0 && - patch.length1 < patch_size - this.Patch_Margin) { + patch.length1 < patch_size - this.Patch_Margin) { var diff_type = bigpatch.diffs[0][0]; var diff_text = bigpatch.diffs[0][1]; if (diff_type === DIFF_INSERT) { @@ -2204,8 +2204,8 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { patch.diffs.push(bigpatch.diffs.shift()); empty = false; } else if (diff_type === DIFF_DELETE && patch.diffs.length == 1 && - patch.diffs[0][0] == DIFF_EQUAL && - diff_text.length > 2 * patch_size) { + patch.diffs[0][0] == DIFF_EQUAL && + diff_text.length > 2 * patch_size) { // This is a large deletion. Let it pass in one chunk. patch.length1 += diff_text.length; start1 += diff_text.length; @@ -2239,7 +2239,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { precontext.substring(precontext.length - this.Patch_Margin); // Append the end context for this patch. var postcontext = this.diff_text1(bigpatch.diffs) - .substring(0, this.Patch_Margin); + .substring(0, this.Patch_Margin); if (postcontext !== '') { patch.length1 += postcontext.length; patch.length2 += postcontext.length; @@ -2408,20 +2408,4 @@ diff_match_patch.patch_obj.prototype.toString = function() { text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n'; } return text.join('').replace(/%20/g, ' '); -}; - -// CLOSURE:begin_strip -// Lines below here will not be included in the Closure-compatible library. - -// Export these global variables so that they survive Google's JS compiler. -// In a browser, 'this' will be 'window'. -// Users of node.js should 'require' the uncompressed version since Google's -// JS compiler may break the following exports for non-browser environments. -/** @suppress {globalThis} */ -this['diff_match_patch'] = diff_match_patch; -/** @suppress {globalThis} */ -this['DIFF_DELETE'] = DIFF_DELETE; -/** @suppress {globalThis} */ -this['DIFF_INSERT'] = DIFF_INSERT; -/** @suppress {globalThis} */ -this['DIFF_EQUAL'] = DIFF_EQUAL; +}; \ No newline at end of file diff --git a/javascript/package-lock.json b/javascript/package-lock.json new file mode 100644 index 0000000..e803b0a --- /dev/null +++ b/javascript/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "@dmsnell/diff-match-patch", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@dmsnell/diff-match-patch", + "version": "1.0.0", + "license": "Apache-2.0" + } + } +} diff --git a/javascript/package.json b/javascript/package.json new file mode 100644 index 0000000..e5c3efb --- /dev/null +++ b/javascript/package.json @@ -0,0 +1,17 @@ +{ + "name": "@dmsnell/diff-match-patch", + "version": "1.0.0", + "license": "Apache-2.0", + "description": "Efficient and human-readable text diffs with helpers", + "keywords": [ + "diff", + "diff-match-patch", + "google-diff-match-patch" + ], + "type": "module", + "main": "./index.mjs", + "repository": { + "type": "git", + "url": "https://github.com/dmsnell/diff-match-patch" + } +}