MCPcopy Create free account
hub / github.com/TanStack/db / getPrefix

Function getPrefix

packages/db-ivm/src/indexes.ts:481–494  ·  view source on GitHub ↗

* This function extracts the prefix from a value. * @param value - The value to extract the prefix from. * @returns The prefix and the suffix.

(value: TValue)

Source from the content-addressed store, hash-verified

479 * @returns The prefix and the suffix.
480 */
481function getPrefix<TValue, TPrefix>(value: TValue): TPrefix | NO_PREFIX {
482 // If the value is an array and the first element is a string or number, then the
483 // first element is the prefix. This is used to distinguish between values without
484 // the need for hashing unless there are multiple values for the same prefix.
485 if (
486 Array.isArray(value) &&
487 (typeof value[0] === `string` ||
488 typeof value[0] === `number` ||
489 typeof value[0] === `bigint`)
490 ) {
491 return value[0] as TPrefix
492 }
493 return NO_PREFIX
494}
495
496/**
497 * This function checks if a value is a single value.

Callers 3

addValueMethod · 0.85
addValueMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected