* Internal implementation with cycle detection to prevent infinite recursion
( a: any, b: any, visited: Map<object, object>, )
| 34 | * Internal implementation with cycle detection to prevent infinite recursion |
| 35 | */ |
| 36 | function deepEqualsInternal( |
| 37 | a: any, |
| 38 | b: any, |
| 39 | visited: Map<object, object>, |
| 40 | ): boolean { |
| 41 | // Handle strict equality (primitives, same reference) |
| 42 | if (a === b) return true |
| 43 | |
| 44 | // Handle null/undefined |
| 45 | if (a == null || b == null) return false |
| 46 | |
| 47 | // Handle different types |
| 48 | if (typeof a !== typeof b) return false |
| 49 | |
| 50 | // Handle Date objects |
| 51 | if (a instanceof Date) { |
| 52 | if (!(b instanceof Date)) return false |
| 53 | return a.getTime() === b.getTime() |
| 54 | } |
| 55 | // Symmetric check: if b is Date but a is not, they're not equal |
| 56 | if (b instanceof Date) return false |
| 57 | |
| 58 | // Handle RegExp objects |
| 59 | if (a instanceof RegExp) { |
| 60 | if (!(b instanceof RegExp)) return false |
| 61 | return a.source === b.source && a.flags === b.flags |
| 62 | } |
| 63 | // Symmetric check: if b is RegExp but a is not, they're not equal |
| 64 | if (b instanceof RegExp) return false |
| 65 | |
| 66 | // Handle Map objects - only if both are Maps |
| 67 | if (a instanceof Map) { |
| 68 | if (!(b instanceof Map)) return false |
| 69 | if (a.size !== b.size) return false |
| 70 | |
| 71 | // Check for circular references |
| 72 | if (visited.has(a)) { |
| 73 | return visited.get(a) === b |
| 74 | } |
| 75 | visited.set(a, b) |
| 76 | |
| 77 | const entries = Array.from(a.entries()) |
| 78 | const result = entries.every(([key, val]) => { |
| 79 | return b.has(key) && deepEqualsInternal(val, b.get(key), visited) |
| 80 | }) |
| 81 | |
| 82 | visited.delete(a) |
| 83 | return result |
| 84 | } |
| 85 | // Symmetric check: if b is Map but a is not, they're not equal |
| 86 | if (b instanceof Map) return false |
| 87 | |
| 88 | // Handle Set objects - only if both are Sets |
| 89 | if (a instanceof Set) { |
| 90 | if (!(b instanceof Set)) return false |
| 91 | if (a.size !== b.size) return false |
| 92 | |
| 93 | // Check for circular references |
no test coverage detected