| 1 |
node module for: |
| 2 |
http://code.google.com/p/google-diff-match-patch/ by Neil Fraser and contributors. |
| 3 |
|
| 4 |
drop in the original code form svn of Neil Fraser's diff_match_patch. |
| 5 |
uses jsinc and a simple index.js file and thus it is easily updatable |
| 6 |
|
| 7 |
to update just copy in here the 'demos' and 'javascript' folders |
| 8 |
|
| 9 |
this module is also awesome because you can use exactrly the same code on the serverside |
| 10 |
and on the client side. |
| 11 |
|
| 12 |
this module is built using https://github.com/shimondoodkin/jsinc |
| 13 |
|
| 14 |
the test tests just that the modue is usable. |
| 15 |
|
| 16 |
see demos to learn how it works. |
| 17 |
|
| 18 |
by Shimon Dookdin |
| 19 |
|
| 20 |
may be intalled with npm: |
| 21 |
|
| 22 |
npm install googlediff |
| 23 |
|
| 24 |
demo: |
| 25 |
var diff_match_patch=require('googlediff'); |
| 26 |
|
| 27 |
var dmp =new diff_match_patch(); |
| 28 |
function launch() { |
| 29 |
var text1 = "this is some test. blah blah blah"; |
| 30 |
var text2 = "this is other text. blah blah blah"; |
| 31 |
//dmp.Diff_Timeout = 1; // set 0 for no timeout |
| 32 |
|
| 33 |
var ms_start = (new Date()).getTime(); |
| 34 |
var d = dmp.diff_main(text1, text2); |
| 35 |
var ms_end = (new Date()).getTime(); |
| 36 |
|
| 37 |
if (true) { |
| 38 |
dmp.diff_cleanupSemantic(d); |
| 39 |
} |
| 40 |
if (false) { |
| 41 |
dmp.Diff_EditCost = 4; |
| 42 |
dmp.diff_cleanupEfficiency(d); |
| 43 |
} |
| 44 |
//var ds = dmp.diff_prettyHtml(d); |
| 45 |
//console.log(ds + '<br/>Time: ' + (ms_end - ms_start) / 1000 + 's'); |
| 46 |
console.log(d) |
| 47 |
} |
| 48 |
launch() |
| 49 |
|
| 50 |
output: |
| 51 |
[ [ 0, 'this is ' ], |
| 52 |
[ -1, 'some' ], |
| 53 |
[ 1, 'other' ], |
| 54 |
[ 0, ' te' ], |
| 55 |
[ -1, 's' ], |
| 56 |
[ 1, 'x' ], |
| 57 |
[ 0, 't. blah blah blah' ] ] |