# turbo-diff

> A fast and small diff library for js/json data

Latest version **1.1.0** (published 2023-12-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install turbo-diff
pnpm add turbo-diff
yarn add turbo-diff
bun add turbo-diff
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-12-25 |
| First published | 2022-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | ZxBing0066 |
| Maintainers | zxbing0066 |
| Keywords | diff, comparison, compare, javascript, typescript |

## Links

- npm: https://www.npmjs.com/package/turbo-diff
- Repository: https://github.com/ZxBing0066/zlib
- Homepage: https://github.com/ZxBing0066/zlib/tree/master/packages/diff#readme
- Issues: https://github.com/ZxBing0066/zlib/issues
- npm.io page: https://npm.io/package/turbo-diff

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-12-25
- 1.0.6 — 2022-03-12
- 1.0.5 — 2022-01-14
- 1.0.4 — 2022-01-14
- 1.0.3 — 2022-01-14

## README

<div align='center'>

<img src='./logo.png' width='500px'/>

A diff library for deep diff js/json object/array.

With 🚀 very fast diff speed (especially in array diff), 📦 tiny size (< 500b), 0 dependents, typescript support.

![ts](https://badgen.net/badge/-/TypeScript/blue?icon=typescript&label)
![license](https://badgen.net/github/license/ZxBing0066/zlib)
![mini zipped size](https://img.shields.io/bundlephobia/minzip/turbo-diff)
![dependents](https://badgen.net/npm/dependents/turbo-diff) ![coverage](https://badgen.net/badge/coverage/100%25/green)
![tree-shaking support](https://badgen.net/bundlephobia/tree-shaking/turbo-diff)
[![npm version](https://badgen.net/npm/v/turbo-diff)](https://www.npmjs.com/package/turbo-diff)

</div>

<hr/>

<div align='right'>

[English / [中文](README.zh-cn.md)]

</div>

## ✨ Features

-   🚀 Faster then other object diff libs, and the amazing array diff speed
-   🛡 Build with typescript, fully support types
-   🌐 Support all special type object deep diff
-   📦 Lightweight and tree shaking support
-   🌎 Support web, Node and workers

## 🎬 Quick start

1. Install

```sh
npm i turbo-diff
```

2. Usage

Import the lib and call with your objects you want to do diff.

```js
import diff from 'turbo-diff';

console.log(diff({ foo: 'bar' }, { foo: 'bar', newKey: 'value' }));
```

## 🪞 Interface

Generic support.

```ts
interface Diff<T = any> {
    type: 'ADD' | 'REMOVE' | 'CHANGE';
    path: (string | number)[];
    old?: T;
    new?: T;
}
declare const diff: <T = any, TObj = Record<string, T> | T[]>(oldObj: TObj, newObj: TObj) => Diff<any>[];
```

## 😼 Playground

[![Edit playground: turbo-diff](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/playground-turbo-diff-yeno0?fontsize=14&hidenavigation=1&theme=dark)

## 🚀 Benchmark

-   With small object

| "name"                        | "ops"   | "margin" | "percentSlower" |
| ----------------------------- | ------- | -------- | --------------- |
| "diff"                        | 56562   | 0.56     | 98.88           |
| "deep-diff"                   | 433694  | 0.31     | 91.4            |
| "deep-object-diff"            | 1149395 | 0.35     | 77.2            |
| "jsdiff"                      | 57685   | 0.36     | 98.86           |
| "microdiff"                   | 4400020 | 0.4      | 12.73           |
| "microdiff-without-cyclesFix" | 4382206 | 0.39     | 13.08           |
| "turbo-diff"                  | 5041725 | 3.06     | 0               |

-   With big object

| "name"                        | "ops"     | "margin" | "percentSlower" |
| ----------------------------- | --------- | -------- | --------------- |
| "diff"                        | 0.09      | 2.27     | 100             |
| "deep-diff"                   | 3911.885  | 0.3      | 88.24           |
| "deep-object-diff"            | 35.305    | 0.31     | 99.89           |
| "jsdiff"                      | 0.089     | 0.53     | 100             |
| "microdiff"                   | 28992.708 | 0.51     | 12.82           |
| "microdiff-without-cyclesFix" | 29038.595 | 0.35     | 12.68           |
| "turbo-diff"                  | 33256.928 | 0.4      | 0               |

-   With big object(deep 4, property count 10)

| "name"                        | "ops"     | "margin" | "percentSlower" |
| ----------------------------- | --------- | -------- | --------------- |
| "diff"                        | 0.0201    | 1.32     | 100             |
| "deep-diff"                   | 364.4773  | 0.4      | 68.82           |
| "deep-object-diff"            | 360.8354  | 0.46     | 69.13           |
| "jsdiff"                      | 0.02      | 2.02     | 100             |
| "microdiff"                   | 902.0445  | 0.38     | 22.84           |
| "microdiff-without-cyclesFix" | 1021.0441 | 0.33     | 12.66           |
| "turbo-diff"                  | 1169.0366 | 0.33     | 0               |

-   With deeply nested object

| "name"                        | "ops"  | "margin" | "percentSlower" |
| ----------------------------- | ------ | -------- | --------------- |
| "diff"                        | 9192   | 0.35     | 99.03           |
| "deep-diff"                   | 163921 | 0.28     | 82.79           |
| "deep-object-diff"            | 330296 | 0.41     | 65.32           |
| "jsdiff"                      | 9050   | 0.32     | 99.05           |
| "microdiff"                   | 644867 | 0.35     | 32.3            |
| "microdiff-without-cyclesFix" | 817169 | 0.47     | 14.21           |
| "turbo-diff"                  | 952516 | 0.3      | 0               |

-   With simple array

| "name"                        | "ops"   | "margin" | "percentSlower" |
| ----------------------------- | ------- | -------- | --------------- |
| "diff"                        | 37656   | 0.37     | 98.71           |
| "deep-diff"                   | 337257  | 0.36     | 88.43           |
| "deep-object-diff"            | 278428  | 0.39     | 90.44           |
| "jsdiff"                      | 38266   | 0.28     | 98.69           |
| "microdiff"                   | 1610910 | 0.44     | 44.71           |
| "microdiff-without-cyclesFix" | 1585105 | 0.38     | 45.6            |
| "turbo-diff"                  | 2913708 | 0.37     | 0               |

-   With simple array(place short array as newObject)

| "name"                        | "ops"   | "margin" | "percentSlower" |
| ----------------------------- | ------- | -------- | --------------- |
| "diff"                        | 38656   | 0.31     | 98.54           |
| "deep-diff"                   | 340188  | 0.81     | 87.15           |
| "deep-object-diff"            | 289963  | 0.34     | 89.05           |
| "jsdiff"                      | 39385   | 0.93     | 98.51           |
| "microdiff"                   | 1784744 | 0.48     | 32.58           |
| "microdiff-without-cyclesFix" | 1786782 | 0.31     | 32.51           |
| "turbo-diff"                  | 2647332 | 0.37     | 0               |

---
_Source: https://npm.io/package/turbo-diff · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
