AsyncBanana / microdiff

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How about having index path for array be a number instead of a string?

98mux opened this issue · comments

import diff from "microdiff";

const array1 = [1];
const array2 = [2];
const obj1 = {0:1};
const obj2 = {0:2};



Both diffs give the same result, which could be problematic:



My proposal is to differenciate between object and array by having array indexes be a number instead of a string, so that the result would be this instead:


So the path array will have this type:

 Array<string | number>

This would make it easier to create a patching function too

Good idea! I was planning on adding patching, and this would prevent accidental transformations between an object and an array. I will work on adding this and will hopefully release it in the next release.

In v1.2.0, array paths should be numbers instead of strings. If this does not work, let me know.