1.1.0 β€’ Published 5 months ago

turbo-diff v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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 license mini zipped size dependents coverage tree-shaking support npm version

[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

  1. Install
npm i turbo-diff
  1. 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

Edit playground: turbo-diff

πŸš€ Benchmark

  • With small object
"name""ops""margin""percentSlower"
"diff"565620.5698.88
"deep-diff"4336940.3191.4
"deep-object-diff"11493950.3577.2
"jsdiff"576850.3698.86
"microdiff"44000200.412.73
"microdiff-without-cyclesFix"43822060.3913.08
"turbo-diff"50417253.060
  • With big object
"name""ops""margin""percentSlower"
"diff"0.092.27100
"deep-diff"3911.8850.388.24
"deep-object-diff"35.3050.3199.89
"jsdiff"0.0890.53100
"microdiff"28992.7080.5112.82
"microdiff-without-cyclesFix"29038.5950.3512.68
"turbo-diff"33256.9280.40
  • With big object(deep 4, property count 10)
"name""ops""margin""percentSlower"
"diff"0.02011.32100
"deep-diff"364.47730.468.82
"deep-object-diff"360.83540.4669.13
"jsdiff"0.022.02100
"microdiff"902.04450.3822.84
"microdiff-without-cyclesFix"1021.04410.3312.66
"turbo-diff"1169.03660.330
  • With deeply nested object
"name""ops""margin""percentSlower"
"diff"91920.3599.03
"deep-diff"1639210.2882.79
"deep-object-diff"3302960.4165.32
"jsdiff"90500.3299.05
"microdiff"6448670.3532.3
"microdiff-without-cyclesFix"8171690.4714.21
"turbo-diff"9525160.30
  • With simple array
"name""ops""margin""percentSlower"
"diff"376560.3798.71
"deep-diff"3372570.3688.43
"deep-object-diff"2784280.3990.44
"jsdiff"382660.2898.69
"microdiff"16109100.4444.71
"microdiff-without-cyclesFix"15851050.3845.6
"turbo-diff"29137080.370
  • With simple array(place short array as newObject)
"name""ops""margin""percentSlower"
"diff"386560.3198.54
"deep-diff"3401880.8187.15
"deep-object-diff"2899630.3489.05
"jsdiff"393850.9398.51
"microdiff"17847440.4832.58
"microdiff-without-cyclesFix"17867820.3132.51
"turbo-diff"26473320.370