1.1.0 β’ Published 5 months ago
turbo-diff v1.1.0
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.
[English / δΈζ]
β¨ 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
- Install
npm i turbo-diff
- Usage
Import the lib and call with your objects you want to do diff.
import diff from 'turbo-diff';
console.log(diff({ foo: 'bar' }, { foo: 'bar', newKey: 'value' }));
πͺ Interface
Generic support.
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
π 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 |