This project is part of the @thi.ng/umbrella monorepo.
Customizable diff implementations for arrays (sequential) & objects (associative), with or without linear edit logs.
STABLE - used in production
Search or submit any issues for this package
yarn add @thi.ng/diff
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/diff?module" crossorigin></script>
// UMD
<script src="https://unpkg.com/@thi.ng/diff/lib/index.umd.js" crossorigin></script>
Package sizes (gzipped, pre-treeshake): ESM: 1.15 KB / CJS: 1.21 KB / UMD: 1.24 KB
import { diffArray } from "@thi.ng/diff";
// diff w/ default diff mode
diffArray([1, 2, 3], [1, 2, 4], "full");
// {
// distance: 2,
// adds: { 2: 4 },
// dels: { 2: 3 },
// const: { 0: 1, 1: 2 },
// linear: [0, 0, 1, 0, 1, 2, -1, 2, 3, 1, 2, 4]
// }
Karsten Schmidt
If this project contributes to an academic publication, please cite it as:
@misc{thing-diff,
title = "@thi.ng/diff",
author = "Karsten Schmidt",
note = "https://thi.ng/diff",
year = 2016
}
© 2016 - 2021 Karsten Schmidt // Apache Software License 2.0