mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2025-09-24 06:10:18 +00:00
push all website files
This commit is contained in:
38
website/functions/node_modules/power-assert-renderer-comparison/lib/udiff.js
generated
vendored
Normal file
38
website/functions/node_modules/power-assert-renderer-comparison/lib/udiff.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
var DiffMatchPatch = require('diff-match-patch');
|
||||
var dmp = new DiffMatchPatch();
|
||||
|
||||
function udiff (config) {
|
||||
return function diff (text1, text2) {
|
||||
var patch;
|
||||
if (config && shouldUseLineLevelDiff(text1, config)) {
|
||||
patch = udiffLines(text1, text2);
|
||||
} else {
|
||||
patch = udiffChars(text1, text2);
|
||||
}
|
||||
return decodeURIComponent(patch);
|
||||
};
|
||||
}
|
||||
|
||||
function shouldUseLineLevelDiff (text, config) {
|
||||
return config.lineDiffThreshold < text.split(/\r\n|\r|\n/).length;
|
||||
}
|
||||
|
||||
function udiffLines(text1, text2) {
|
||||
/*jshint camelcase: false */
|
||||
var a = dmp.diff_linesToChars_(text1, text2);
|
||||
var diffs = dmp.diff_main(a.chars1, a.chars2, false);
|
||||
dmp.diff_charsToLines_(diffs, a.lineArray);
|
||||
dmp.diff_cleanupSemantic(diffs);
|
||||
return dmp.patch_toText(dmp.patch_make(text1, diffs));
|
||||
}
|
||||
|
||||
function udiffChars (text1, text2) {
|
||||
/*jshint camelcase: false */
|
||||
var diffs = dmp.diff_main(text1, text2, false);
|
||||
dmp.diff_cleanupSemantic(diffs);
|
||||
return dmp.patch_toText(dmp.patch_make(text1, diffs));
|
||||
}
|
||||
|
||||
module.exports = udiff;
|
Reference in New Issue
Block a user