diff --git a/package.json b/package.json index 5a2d0a0..6907f8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@donedeal0/superdiff", - "version": "4.2.1", + "version": "4.2.2", "type": "module", "description": "Superdiff provides a rich and readable diff for arrays, objects, texts and coordinates. It supports stream and file inputs for handling large datasets efficiently, is battle-tested, has zero dependencies, and offers a top-tier performance.", "main": "dist/index.js", diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 39afd7c..04af0b5 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -14,10 +14,13 @@ export function isEqual( ): boolean { if (a === b) return true; if (typeof a !== typeof b) return false; + const aIsArray = Array.isArray(a); + const bIsArray = Array.isArray(b) + if (aIsArray !== bIsArray) return false; if (a === null || b === null) return a === b; if (typeof a !== "object") return a === b; - if (Array.isArray(a) && Array.isArray(b)) { + if (aIsArray && bIsArray) { if (a.length !== b.length) return false; if (!options.ignoreArrayOrder) { for (let i = 0; i < a.length; i++) { @@ -68,4 +71,4 @@ export function isEqual( */ export function isObject(value: unknown): value is Record { return typeof value === "object" && !!value && !Array.isArray(value); -} +} \ No newline at end of file diff --git a/src/lib/utils/utils.test.ts b/src/lib/utils/utils.test.ts index f719456..14c72c9 100644 --- a/src/lib/utils/utils.test.ts +++ b/src/lib/utils/utils.test.ts @@ -21,6 +21,7 @@ describe("isEqual", () => { ).toBeTruthy(); }); it("return false if data are different", () => { + expect(isEqual({}, [])).toBeFalsy() expect(isEqual(null, "hello")).toBeFalsy(); expect(isEqual("hello", undefined)).toBeFalsy(); expect(isEqual("hello", "howdy")).toBeFalsy();