(value: any)
| 185 | * for BTree index operations that need to distinguish undefined values. |
| 186 | */ |
| 187 | export function normalizeValue(value: any): any { |
| 188 | if (value instanceof Date) { |
| 189 | return value.getTime() |
| 190 | } |
| 191 | |
| 192 | if (isTemporal(value)) { |
| 193 | return `__temporal__${value[Symbol.toStringTag]}__${value.toString()}` |
| 194 | } |
| 195 | |
| 196 | // Normalize Uint8Arrays/Buffers to a string representation for Map key usage |
| 197 | // This enables content-based equality for binary data like ULIDs |
| 198 | const isUint8Array = |
| 199 | (typeof Buffer !== `undefined` && value instanceof Buffer) || |
| 200 | value instanceof Uint8Array |
| 201 | |
| 202 | if (isUint8Array) { |
| 203 | // Only normalize small arrays to avoid memory overhead for large binary data |
| 204 | if (value.byteLength <= UINT8ARRAY_NORMALIZE_THRESHOLD) { |
| 205 | // Convert to a string representation that can be used as a Map key |
| 206 | // Use a special prefix to avoid collisions with user strings |
| 207 | return `__u8__${Array.from(value).join(`,`)}` |
| 208 | } |
| 209 | // For large arrays, fall back to reference equality |
| 210 | // Users working with large binary data should use a derived key if needed |
| 211 | } |
| 212 | |
| 213 | return value |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Normalize a value for BTree index usage. |
no test coverage detected