Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

native-diff-match-patch

2.0.1 • Public • Published

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.

Build Status

Floobits Status

Dependencies

This is a native module that depends on Qt5.

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);

Keywords

none

Install

npm i native-diff-match-patch

DownloadsWeekly Downloads

10

Version

2.0.1

License

Apache-2.0

Unpacked Size

203 kB

Total Files

24

Last publish

Collaborators

  • avatar
  • avatar