All Projects → AsyncBanana → microdiff

AsyncBanana / microdiff

Licence: MIT license
A fast, zero dependency object and array comparison library. Significantly faster than most other deep comparison libraries and has full TypeScript support.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to microdiff

Sirix
SirixDB is a temporal, evolutionary database system, which uses an accumulate only approach. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach called sliding snapshot.
Stars: ✭ 638 (-79.67%)
Mutual labels:  diff, comparison
ncdu-diff
ncdu fork that can compare and diff results
Stars: ✭ 21 (-99.33%)
Mutual labels:  diff, comparison
differ
Electron application to compare two directories
Stars: ✭ 48 (-98.47%)
Mutual labels:  diff, comparison
speech-recognition-evaluation
Evaluate results from ASR/Speech-to-Text quickly
Stars: ✭ 25 (-99.2%)
Mutual labels:  diff, comparison
Deepdiff
Deep Difference and search of any Python object/data.
Stars: ✭ 985 (-68.61%)
Mutual labels:  diff, comparison
Pandiff
Prose diffs for any document format supported by Pandoc
Stars: ✭ 110 (-96.49%)
Mutual labels:  diff, comparison
React Gh Like Diff
➕➖ The react component to generate pretty HTML for comparing commits or text.
Stars: ✭ 97 (-96.91%)
Mutual labels:  diff, comparison
Sitediff
SiteDiff makes it easy to see differences between two versions of a website.
Stars: ✭ 139 (-95.57%)
Mutual labels:  diff, comparison
deno registry2
The backend for the deno.land/x service
Stars: ✭ 79 (-97.48%)
Mutual labels:  deno
spotdiff.vim
A range and area selectable diffthis to compare partially
Stars: ✭ 29 (-99.08%)
Mutual labels:  diff
won
A new way to see HTML Web Pages
Stars: ✭ 15 (-99.52%)
Mutual labels:  comparison
duff
Pure OCaml implementation of libXdiff (Rabin's fingerprint)
Stars: ✭ 20 (-99.36%)
Mutual labels:  diff
xdem
Analysis of digital elevation models (DEMs)
Stars: ✭ 50 (-98.41%)
Mutual labels:  comparison
lightline-gitdiff
Show added, deleted and modified lines (`git diff`) in your statusline or lightline
Stars: ✭ 27 (-99.14%)
Mutual labels:  diff
deno-pokemon
a simple api to create and explore pokemons - made with oak deno framework
Stars: ✭ 20 (-99.36%)
Mutual labels:  deno
http4ts
Server as a Function http toolkit for TypeScript & JavaScript
Stars: ✭ 30 (-99.04%)
Mutual labels:  deno
dataStructure
Implement different Data Structures using TypeScript and JavaScript. Deno Third-party Module.
Stars: ✭ 24 (-99.24%)
Mutual labels:  deno
snatchblock
A strictly typed utility library.
Stars: ✭ 1,059 (-66.25%)
Mutual labels:  deno
elm-javascript-haskell-equivalents
Comparison of similar functions across Elm, Javascript, and Haskell
Stars: ✭ 31 (-99.01%)
Mutual labels:  comparison
json-path-comparison
Comparison of the different implementations of JSONPath and language agnostic test suite.
Stars: ✭ 64 (-97.96%)
Mutual labels:  comparison

Microdiff Logo

Microdiff is a tiny (currently <1kb), fast, zero dependency object and array comparison library. It is significantly faster than most other deep comparison libraries, and has full TypeScript support.

💡 I recommend reading this blog post:

Building the fastest object and array differ for an explanation of how Microdiff achieves its size and speed.

Minizipped Size (from Bundlephobia) License dependency Count

Features

  • 🚀 More than double the speed of other object diff libraries
  • 📦 Extremely lightweight, <1kb minified
  • 🌎 Supports Deno, Node, the web, and even service workers. Also comes with built-in Typescript types
  • 🔰 Very easy to use, having just a single diff() function
  • 📅 Full support for objects like new Date() and new RegExp()

Get started

First, install Microdiff

npm i microdiff

If you are using Deno, you can import it from Deno.land with the link https://deno.land/x/microdiff@VERSION/index.ts (remember to change @VERSION to the version you want to use).

After you install it, import it and run it on two objects.

import diff from "microdiff";

const obj1 = {
	originalProperty: true,
};
const obj2 = {
	originalProperty: true,
	newProperty: "new",
};

console.log(diff(obj1, obj2));
// [{type: "CREATE", path: ["newProperty"], value: "new"}]

If you are using CommonJS, you can import it like this:

const diff = require("microdiff").default;

There are three different types of changes: CREATE, REMOVE, and CHANGE. The path property gives a path to the property in the new object (or the old object in the case of REMOVE). Each element in the paths is a key to the next property a level deeper until you get to the property changed, and it is a string or a number, depending on whether the object is an Array or Object (Objects with number keys will still be strings). The value property exists in types CREATE and CHANGE, and it contains the value of the property added/changed/deleted. The oldValue property exists in the type CHANGE and REMOVE, and it contains the old value of the property.

Cycles support

By default, Microdiff supports cyclical references, but if you are sure that the object has no cycles like parsed JSON, you can disable cycles using the cyclesFix option.

diff(obj1, obj2, { cyclesFix: false });

Benchmarks

Benchmarks: Small object
deep-diff: 17929ns - 409% slower
deep-object-diff: 10763ns - 206% slower
jsdiff: 79700ns - 2164% slower
microdiff: 3520ns - Fastest

Benchmarks: Large Object
deep-diff: 272887ns - 259% slower
deep-object-diff: 160019ns - 111% slower
jsdiff: 1688294ns - 2123% slower
microdiff: 75934ns - Fastest

These benchmarks are currently only for one small object and a very large object, so they might not be accurate. I will be working on creating benchmarks with more varying types.

Contributing

Thanks for helping the project out! Contributing is pretty simple. Fork the repository (if you need more information on how to do this, check out this GitHub guide), clone it to your computer, and start programming! To compile the program, run npm run build (replace npm with pnpm or yarn if you are using one of those). This will create CommonJS and ESM modules in /dist.

To benchmark microdiff, you can run npm run bench. This will automatically build Microdiff and run a benchmarking program comparing microdiff to other common diffing libraries.

Finally, Microdiff has an extensive test suite which you should take advantage of. To make sure everything is working correctly, you can run npm run test. npm run test builds the project and then runs the entire test suite on the new version. If you are fixing a bug, be sure to add a test for that. Also, make sure you read the Code of Conduct before contributing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].