Jsdiff是一款实现javascript文本差分的软件。
安装:
npm install diff
或者
bower install jsdiff
API
JsDiff.diffChars(oldStr, newStr[, options])
Returns a list of change objects (See below).
JsDiff.diffWords(oldStr, newStr[, options])
JsDiff.diffWordsWithSpace(oldStr, newStr[, options])
JsDiff.diffLines(oldStr, newStr[, options])
选择:
ignoreWhitespace: true to ignore leading and trailing whitespace. This is the same as diffTrimmedLines
ignoreWhitespace
true
diffTrimmedLines
newlineIsToken: true to 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 human
newlineIsToken
dly form of diffLines and diffLines is better suited for patches and other computer friendly output.
diffLines
兼容性:
Jsdiff支持所有ES3环境和IE8以下一些已知问题。这些浏览器存在一些差异算法,如文字diff和其他可能由于缺乏拆分操作捕获组支持的失败操作。