(hasher: Hasher, input: unknown)
| 152 | } |
| 153 | |
| 154 | function updateHasher(hasher: Hasher, input: unknown): void { |
| 155 | if (input === null) { |
| 156 | hasher.update(NULL) |
| 157 | return |
| 158 | } |
| 159 | switch (typeof input) { |
| 160 | case `undefined`: |
| 161 | hasher.update(UNDEFINED) |
| 162 | return |
| 163 | case `boolean`: |
| 164 | hasher.update(input ? TRUE : FALSE) |
| 165 | return |
| 166 | case `number`: |
| 167 | // Normalize NaNs and -0 |
| 168 | hasher.update(isNaN(input) ? NaN : input === 0 ? 0 : input) |
| 169 | return |
| 170 | case `bigint`: |
| 171 | case `string`: |
| 172 | case `symbol`: |
| 173 | hasher.update(input) |
| 174 | return |
| 175 | case `object`: |
| 176 | hasher.update(getCachedHash(input)) |
| 177 | return |
| 178 | case `function`: |
| 179 | // Functions are assigned a globally unique ID |
| 180 | // and that ID is cached in the weak map |
| 181 | hasher.update(cachedReferenceHash(input)) |
| 182 | return |
| 183 | default: |
| 184 | console.warn( |
| 185 | `Ignored input during hashing because it is of type ${typeof input} which is not supported`, |
| 186 | ) |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | function getCachedHash(input: object): number { |
| 191 | let valueHash = hashCache.get(input) |
no test coverage detected