javascript nodejs 是否有可用的差异库或算法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9833009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:57:47  来源:igfitidea点击:

Does nodejs have a working diff library or algorithm?

javascriptnode.jsdiff

提问by blueberryfields

I'm looking for a javascript diff algorithm implementation or library, which has been tested on and works with arbitrary utf8 text files.

我正在寻找一个 javascript diff 算法实现或库,它已经过测试并适用于任意 utf8 文本文件。

All of the ones I found so far (say for example, http://ejohn.org/projects/javascript-diff-algorithm/) fail on corner cases

到目前为止我发现的所有那些(例如,http://ejohn.org/projects/javascript-diff-algorithm/)在极端情况下都失败了

(Try using a file which contains the string '__proto__'in my example library.)

(尝试使用包含'__proto__'示例库中字符串的文件。)

采纳答案by anton_byrna

Maybe this will help you — jsdiff

也许这会帮助你——jsdiff

回答by TimE

I'm a fan of google diff match patch. You can try out an example here.

我是google diff match patch的粉丝。您可以在此处尝试一个示例。

There are different cleanup option to tweak the level of commonality between the diffs. I don't like the semantic cleanup option as I find it's too aggressive, but the efficiency cleanup with a value of 10 works well for me.

有不同的清理选项来调整差异之间的共性水平。我不喜欢语义清理选项,因为我发现它过于激进,但值为 10 的效率清理对我来说效果很好。

回答by cubicdaiya

There is an diff algorithm implementation that I wrote with javascript in the following page.

我在下一页中用 javascript 编写了一个差异算法实现。

https://github.com/cubicdaiya/onp

https://github.com/cubicdaiya/onp

This runs with node.js. Forthermore there is a C++ addon version for node.js in following page.

这与 node.js 一起运行。此外,在下一页中有 node.js 的 C++ 插件版本。

https://github.com/cubicdaiya/node-dtl

https://github.com/cubicdaiya/node-dtl

You can install this with npm.

你可以用 npm 安装它。

$ npm install -g dtl

$ npm install -g dtl

回答by Ryan McCarvill

There is also adiff which is a diff/patch library written in Javascript.

还有 adiff,它是一个用 Javascript 编写的 diff/patch 库。

https://github.com/dominictarr/adiff

https://github.com/dominctarr/adiff

回答by Cacycle

Have a look at the JavaScript library wikEd diff. It has Unicode and multilingual support. It also detects and highlights block moves and is word/character based. You can also use the online too/demofor testing different settings and to look at the internal data structures. The library's code is fully commented.

查看 JavaScript 库wikEd diff。它具有 Unicode 和多语言支持。它还检测并突出显示块移动并且基于单词/字符。您还可以使用在线太/演示来测试不同的设置并查看内部数据结构。该库的代码已完全注释。

回答by Peter Mounce

Yes, somewhere inside of the Mocha test tool- see TJ Holowaychuk's blog post about it.

是的,在Mocha 测试工具内部的某个地方- 请参阅TJ Holowaychuk 的博客文章