This library is a JS-only fork of Google's diff-match-patch library. Please view the documentation there to learn more. I created this fork mainly to make the library easily installable via NPM. Please consult the NOTICE
file for more information about the ways I changed the library from its original version.
npm install --save https://github.com/jrc03c/diff-match-patch
Import in Node or bundlers:
const { DiffMatchPatch } = require("@jrc03c/diff-match-patch")
Or import in the browser:
<!-- This defines `DiffMatchPatch` as a global variable -->
<script src="path/to/dist/diff-match-patch.js"></script>
Then:
const text1 = "Help!"
const text2 = "Hello!"
const dmp = new DiffMatchPatch()
const diff = dmp.diffMain(text1, text2)
console.log(dmp.diffLevenshtein(diff)) // 2
Eventually, I'd like to convert the tests into Jest format. But for now, you can run them with:
# unit tests
node tests/index.test.js
# speed tests
node tests/speed.test.js