diff --git a/src/utils.js b/src/utils.js index 10c65a2..3acf1b1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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.