Skip to content

Commit

Permalink
add deep equality utility
Browse files Browse the repository at this point in the history
  • Loading branch information
park-brian committed Dec 21, 2024
1 parent cc93ad7 commit f1ee025
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ export function concat(aaa, bbb) {
}
}

/**
* Deep equality comparison
*
* @param {any} a
* @param {any} b
* @returns {boolean}
*/
export function equals(a, b) {
if (a === b) return true;
if (!a || !b || typeof a !== typeof b) return false;
return Array.isArray(a)
? 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]));
}

/**
* Get the byte length of a URL using a HEAD request.
* If requestInit is provided, it will be passed to fetch.
Expand Down

0 comments on commit f1ee025

Please sign in to comment.