(self: A)
| 108 | return string(self.toString(10)) |
| 109 | case "boolean": |
| 110 | return string(String(self)) |
| 111 | case "symbol": |
| 112 | return string(String(self)) |
| 113 | case "string": |
| 114 | return string(self) |
| 115 | case "undefined": |
| 116 | return string("undefined") |
| 117 | case "function": |
| 118 | case "object": { |
| 119 | if (self === null) { |
| 120 | return string("null") |
| 121 | } else if (self instanceof Date) { |
| 122 | if (Number.isNaN(self.getTime())) { |
| 123 | return string("Invalid Date") |
| 124 | } |
| 125 | return string(self.toISOString()) |
| 126 | } else if (self instanceof RegExp) { |
| 127 | return string(self.toString()) |
| 128 | } else { |
| 129 | if (byReferenceInstances.has(self)) { |
| 130 | return random(self) |
| 131 | } |
| 132 | if (hashCache.has(self)) { |
| 133 | return hashCache.get(self)! |
| 134 | } |
| 135 | const h = withVisitedTracking(self, () => { |
| 136 | if (isHash(self)) { |
| 137 | return self[symbol]() |
| 138 | } else if (typeof self === "function") { |
| 139 | return random(self) |
| 140 | } else if (self instanceof DataView) { |
| 141 | return array(new Uint8Array(self.buffer, self.byteOffset, self.byteLength)) |
| 142 | } else if (Array.isArray(self) || ArrayBuffer.isView(self)) { |
| 143 | return array(self as any) |
| 144 | } else if (self instanceof Map) { |
| 145 | return hashMap(self) |
| 146 | } else if (self instanceof Set) { |
| 147 | return hashSet(self) |
| 148 | } |
| 149 | return structure(self) |
| 150 | }) |
| 151 | hashCache.set(self, h) |
| 152 | return h |
| 153 | } |
| 154 | } |
| 155 | default: |
| 156 | throw new Error( |
| 157 | `BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues` |
| 158 | ) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Generates a random hash value for an object and caches it. |
| 164 | * |
| 165 | * **When to use** |
no test coverage detected
searching dependent graphs…