MCPcopy Index your code
hub / github.com/Effect-TS/effect / compareBoth

Function compareBoth

packages/effect/src/Equal.ts:36–89  ·  view source on GitHub ↗
(self: unknown, that: unknown)

Source from the content-addressed store, hash-verified

34}
35
36function compareBoth(self: unknown, that: unknown): boolean {
37 if (self === that) {
38 return true
39 }
40 const selfType = typeof self
41 if (selfType !== typeof that) {
42 return false
43 }
44 if (selfType === "object" || selfType === "function") {
45 if (self !== null && that !== null) {
46 if (isEqual(self) && isEqual(that)) {
47 if (Hash.hash(self) === Hash.hash(that) && self[symbol](that)) {
48 return true
49 } else {
50 return structuralRegionState.enabled && structuralRegionState.tester
51 ? structuralRegionState.tester(self, that)
52 : false
53 }
54 } else if (self instanceof Date && that instanceof Date) {
55 const t1 = self.getTime()
56 const t2 = that.getTime()
57 return t1 === t2 || (Number.isNaN(t1) && Number.isNaN(t2))
58 } else if (self instanceof URL && that instanceof URL) {
59 return self.href === that.href
60 }
61 }
62 if (structuralRegionState.enabled) {
63 if (self === null || that === null) {
64 return false
65 }
66 if (Array.isArray(self) && Array.isArray(that)) {
67 return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))
68 }
69 if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(that) === Object.prototype) {
70 const keysSelf = Object.keys(self as any)
71 const keysThat = Object.keys(that as any)
72 if (keysSelf.length === keysThat.length) {
73 for (const key of keysSelf) {
74 // @ts-expect-error
75 if (!(key in that && compareBoth(self[key], that[key]))) {
76 return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false
77 }
78 }
79 return true
80 }
81 }
82 return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false
83 }
84 }
85
86 return structuralRegionState.enabled && structuralRegionState.tester
87 ? structuralRegionState.tester(self, that)
88 : false
89}
90
91/**
92 * @since 2.0.0

Callers 1

equalsFunction · 0.85

Calls 2

isEqualFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected