MCPcopy Create free account
hub / github.com/effect-app/libs / hash

Function hash

repos/effect/packages/effect/src/Hash.ts:110–162  ·  view source on GitHub ↗
(self: A)

Source from the content-addressed store, hash-verified

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**

Callers 2

structureKeysFunction · 0.70
Hash.tsFile · 0.70

Calls 12

randomFunction · 0.85
isHashFunction · 0.85
arrayFunction · 0.85
structureFunction · 0.85
numberFunction · 0.70
stringFunction · 0.70
StringInterface · 0.70
withVisitedTrackingFunction · 0.70
toStringMethod · 0.65
getMethod · 0.65
setMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…