Skip to content

Commit 5f7d6c4

Browse files
authored
fix: isequal edgecase (#43)
1 parent 4862209 commit 5f7d6c4

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@donedeal0/superdiff",
3-
"version": "4.2.1",
3+
"version": "4.2.2",
44
"type": "module",
55
"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.",
66
"main": "dist/index.js",

src/lib/utils/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ export function isEqual(
1414
): boolean {
1515
if (a === b) return true;
1616
if (typeof a !== typeof b) return false;
17+
const aIsArray = Array.isArray(a);
18+
const bIsArray = Array.isArray(b)
19+
if (aIsArray !== bIsArray) return false;
1720
if (a === null || b === null) return a === b;
1821
if (typeof a !== "object") return a === b;
1922

20-
if (Array.isArray(a) && Array.isArray(b)) {
23+
if (aIsArray && bIsArray) {
2124
if (a.length !== b.length) return false;
2225
if (!options.ignoreArrayOrder) {
2326
for (let i = 0; i < a.length; i++) {
@@ -68,4 +71,4 @@ export function isEqual(
6871
*/
6972
export function isObject(value: unknown): value is Record<string, unknown> {
7073
return typeof value === "object" && !!value && !Array.isArray(value);
71-
}
74+
}

src/lib/utils/utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe("isEqual", () => {
2121
).toBeTruthy();
2222
});
2323
it("return false if data are different", () => {
24+
expect(isEqual({}, [])).toBeFalsy()
2425
expect(isEqual(null, "hello")).toBeFalsy();
2526
expect(isEqual("hello", undefined)).toBeFalsy();
2627
expect(isEqual("hello", "howdy")).toBeFalsy();

0 commit comments

Comments
 (0)