A fast Javascript string diff
Switch branches/tags
Nothing to show
Clone or download
dgreensp Merge pull request #4 from jhchen/dg-cursor-and-unicode
Improve cursor logic, emoji handling, canonicality, and tests
Latest commit bc1e462 Oct 8, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore initial commit Oct 1, 2014
.travis.yml add travis Oct 3, 2014
README.md bump version Oct 19, 2016
diff.d.ts version bump and TS types Oct 8, 2018
diff.js take code review feedback Oct 8, 2018
package-lock.json version bump and TS types Oct 8, 2018
package.json version bump and TS types Oct 8, 2018
test.js take code review feedback Oct 8, 2018

README.md

Fast Diff Build Status

This is a simplified import of the excellent diff-match-patch library by Neil Fraser into the Node.js environment. The match and patch parts are removed, as well as all the extra diff options. What remains is incredibly fast diffing between two strings.

The diff function is an implementation of "An O(ND) Difference Algorithm and its Variations" (Myers, 1986) with the suggested divide and conquer strategy along with several optimizations Neil added.

var diff = require('fast-diff');

var good = 'Good dog';
var bad = 'Bad dog';

var result = diff(good, bad);
// [[-1, "Goo"], [1, "Ba"], [0, "d dog"]]

// Respect suggested edit location (cursor position), added in v1.1
diff('aaa', 'aaaa', 1)
// [[0, "a"], [1, "a"], [0, "aa"]]

// For convenience
diff.INSERT === 1;
diff.EQUAL === 0;
diff.DELETE === -1;