JsdiffJS文本差分
Jsdiff是一款實(shí)現(xiàn)javascript文本差分的軟件。
安裝:
npm install diff
或者
bower install jsdiff
API
-
JsDiff.diffChars(oldStr, newStr[, options])- diffs two blocks of text, comparing character by character.Returns a list of change objects (See below).
-
JsDiff.diffWords(oldStr, newStr[, options])- diffs two blocks of text, comparing word by word, ignoring whitespace.Returns a list of change objects (See below).
-
JsDiff.diffWordsWithSpace(oldStr, newStr[, options])- diffs two blocks of text, comparing word by word, treating whitespace as significant.Returns a list of change objects (See below).
JsDiff.diffLines(oldStr, newStr[, options])- diffs two blocks of text, comparing line by line.
選擇:
ignoreWhitespace:trueto ignore leading and trailing whitespace. This is the same asdiffTrimmedLinesnewlineIsToken:trueto treat newline characters as separate tokens. This allows for changes to the newline structure to occur independently of the line content and to be treated as such. In general this is the more humandly form of
diffLinesanddiffLinesis better suited for patches and other computer friendly output.
兼容性:
Jsdiff支持所有ES3環(huán)境和IE8以下一些已知問(wèn)題。這些瀏覽器存在一些差異算法,如文字diff和其他可能由于缺乏拆分操作捕獲組支持的失敗操作。
