Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @thi.ng/diff with all npm packages installed. Try it out:

var diff = require("@thi.ng/diff")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@thi.ng/diff v3.1.0

Array & object Diff

@thi.ng/diff

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Customizable diff implementations for JS arrays (sequential) & objects (associative), with or without linear edit logs.

Installation

yarn add @thi.ng/diff

Dependencies

Usage examples

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]
// }

Breaking changes

2.0.0

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

Authors

  • Karsten Schmidt

License

© 2018 Karsten Schmidt // Apache Software License 2.0

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free