Skip to content

Commit

Permalink
support more types for equality
Browse files Browse the repository at this point in the history
  • Loading branch information
park-brian committed Dec 21, 2024
1 parent d70322a commit 600921f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ export function concat(aaa, bbb) {
*/
export function equals(a, b) {
if (a === b) return true
if (a instanceof Uint8Array && b instanceof Uint8Array) return equals(Array.from(a), Array.from(b))
if (!a || !b || typeof a !== typeof b) return false
return Array.isArray(a)
return Array.isArray(a) && Array.isArray(b)
? a.length === b.length && a.every((v, i) => equals(v, b[i]))
: Object.keys(a).length === Object.keys(b).length && Object.keys(a).every(k => equals(a[k], b[k]))
: typeof a === 'object' && Object.keys(a).length === Object.keys(b).length && Object.keys(a).every(k => equals(a[k], b[k]))
}

/**
Expand Down

0 comments on commit 600921f

Please sign in to comment.