Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -68,4 +71,4 @@ export function isEqual(
*/
export function isObject(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && !!value && !Array.isArray(value);
}
}
1 change: 1 addition & 0 deletions src/lib/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down