Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Native Node.js module for diff-match-patch
C++ JavaScript Python Shell
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib OK, I think this will work as an npm module now.
src Use new v8 and node native module API stuff. Now this compiles agains…
test
.floo New url in .floo
.gitignore Add a failing test case. Ignore some nodejs cruft that often gets lef…
LICENSE Apache 2.0 License
NOTICE Add NOTICE
README.md Update README with usage example.
binding.gyp Fix build on linux.
jslint.sh
package.json Fix build on linux.

README.md

Native Diff-Match-Patch

C++ version of diff-match-patch exposed as a node module. This uses a heavily-modified version of the C++ diff-match-patch. It is binary safe.

Development status: Working. We use it in production.

Floobits Status

Usage

Here is an example of applying a patch:

var buffer,
  DMP,
  result,
  patch_text;

DMP = require("native-diff-match-patch");

// If you like, you can change DMP's thresholds
DMP.set_Patch_DeleteThreshold(0.375);
DMP.set_Match_Threshold(0.375);
DMP.set_Match_Distance(100);

buffer = "abc";
patch_text = "@@ -1,3 +1,2 @@\n" +
             " ab\n" +
             "-c";

result = DMP.patch_apply(patch_text, buffer);

for (i = 0; i < result[1].length; i++) {
  if (result[1][i] !== true) {
    throw new Error("Patch not applied cleanly.");
  }
}

buffer = result[0];

// This prints "ab"
console.log(buffer);
Something went wrong with that request. Please try again.