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
yarn add @thi.ng/diff
Package sizes (gzipped): ESM: 1.2KB / CJS: 1.3KB / UMD: 1.3KB
import { diffArray, DiffMode } from "@thi.ng/diff";
diffArray([1, 2, 3], [1, 2, 4], DiffMode.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]
// }
The linear edit logs of both diffArray
and diffObject
are now
returned as flat arrays, with each log entry consisting of 3 or 2
successive array items. This is to avoid allocation of various small
arrays.
The order of optional args to both functions has been swapped to:
diffArray(old, new, mode?, equiv?)
diffObject(old, new, mode?, equiv?)
Karsten Schmidt
© 2016 - 2020 Karsten Schmidt // Apache Software License 2.0