fix(module): remove fast-deep-equal in favor of custom isEqual

This commit is contained in:
Benjamin Canac
2024-11-07 21:56:56 +01:00
parent 557e0c92a4
commit 37a359701f
7 changed files with 33 additions and 13 deletions

View File

@@ -55,6 +55,34 @@ export function set(object: Record<string, any>, path: (string | number)[] | str
}, object)
}
export function isEqual(a: any, b: any): boolean {
// Handle primitive types and referential equality
if (a === b) return true
// Handle null/undefined cases
if (a == null || b == null) return a === b
// Handle different types
if (typeof a !== typeof b) return false
// Handle arrays
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length) return false
return a.every((item, index) => isEqual(item, b[index]))
}
// Handle objects
if (typeof a === 'object') {
const keysA = Object.keys(a)
const keysB = Object.keys(b)
if (keysA.length !== keysB.length) return false
return keysA.every(key => key in b && isEqual(a[key], b[key]))
}
return false
}
export function looseToNumber(val: any): any {
const n = Number.parseFloat(val)
return Number.isNaN(n) ? val : n