MCPcopy Index your code
hub / github.com/TanStack/db / normalizeValue

Function normalizeValue

packages/db/src/utils/comparison.ts:187–214  ·  view source on GitHub ↗
(value: any)

Source from the content-addressed store, hash-verified

185 * for BTree index operations that need to distinguish undefined values.
186 */
187export 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.

Callers 12

normalizeForBTreeFunction · 0.85
processJoinFunction · 0.85
compileFunctionFunction · 0.85
addMethod · 0.85
removeMethod · 0.85
buildMethod · 0.85
equalityLookupMethod · 0.85
rangeQueryMethod · 0.85
takeMethod · 0.85
takeReversedMethod · 0.85
inArrayLookupMethod · 0.85

Calls 4

isTemporalFunction · 0.90
fromMethod · 0.80
toStringMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected