MCPcopy Index your code
hub / github.com/TanStack/db / deepEqualsInternal

Function deepEqualsInternal

packages/db/src/utils.ts:36–212  ·  view source on GitHub ↗

* Internal implementation with cycle detection to prevent infinite recursion

(
  a: any,
  b: any,
  visited: Map<object, object>,
)

Source from the content-addressed store, hash-verified

34 * Internal implementation with cycle detection to prevent infinite recursion
35 */
36function 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

Callers 1

deepEqualsFunction · 0.85

Calls 9

fromMethod · 0.80
isTemporalFunction · 0.70
hasMethod · 0.45
getMethod · 0.45
setMethod · 0.45
entriesMethod · 0.45
deleteMethod · 0.45
toStringMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected