27

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

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

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

3

6 Answers 6

14

Maybe this will help you — jsdiff

1
  • 2
    Upstream is ahead again, so I updated the link. I suspect at the time you posted this that upstream had fallen behind. Here's the one it was linked to previously: github.com/NV/jsdiff Feb 23, 2013 at 23:32
6

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

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.

1
  • I like this one because it's available in Java, JavaScript, Dart, C++, C#, Objective C, Lua and Python. Regardless of language, each library features the same API and the same functionality.
    – elwarren
    Feb 21, 2014 at 15:12
3

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

https://github.com/cubicdaiya/onp

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

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

You can install this with npm.

$ npm install -g dtl

2

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

https://github.com/dominictarr/adiff

1

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/demo for testing different settings and to look at the internal data structures. The library's code is fully commented.

-1

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.