A JavaScript text differencing implementation. Try it out in the online demo.
Based on the algorithm proposed in "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
npm install diff --saveIn an environment where you can use imports, everything you need can be imported directly from diff. e.g.
ESM:
import {diffChars, createPatch} from 'diff';
CommonJS
const {diffChars, createPatch} = require('diff');
If you want to serve jsdiff to a web page without using a module system, you can use dist/diff.js or dist/diff.min.js. These create a global called Diff that contains the entire JsDiff API as its properties.
jsdiff's diff functions all take an old text and a new text and perform three steps:
-
Split both texts into arrays of "tokens". What constitutes a token varies; in
diffChars, each character is a token, while indiffLines, each line is a token. -
Find the smallest set of single-token insertions and