An extension module that adds line-mode and word-mode on google-diff-match-patch, hosted as diff-patch-merge at NPM, originally by Neil Fraser.
Implementation is from Wiki.
TypeScript is also supported.
Execute diff_main line-by-line.
Parameter | Type | Description |
---|---|---|
text1 | string | Old text to compare. |
text2 | string | New text to compare. |
Type | Description |
---|---|
Array of diff_patch_merge.Diff | result diff tuples. |
Execute diff_main word-by-word.
The signature is same.
Just import after node-diff-patch-merge.
import { diff_match_patch } from 'diff-match-patch';
import 'diff-match-patch-line-and-word'; // import globally to enhanse the class.
const dmp = new diff_match_patch();
const oldText = 'He writes the letter.';
const newText = 'She wrote the letters.';
const diffs = dmp.diff_lineMode(oldText, newText);
const html = dmp.diff_prettyHtml(diffs));
document.write(html);