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

Function encodeStorageKey

packages/db/src/local-storage.ts:168–173  ·  view source on GitHub ↗

* Encodes a key (string or number) into a storage-safe string format. * This prevents collisions between numeric and string keys by prefixing with type information. * * Examples: * - number 1 → "n:1" * - string "1" → "s:1" * - string "n:1" → "s:n:1" * * @param key - The key to encode (

(key: string | number)

Source from the content-addressed store, hash-verified

166 * @returns Type-prefixed string that is safe for storage
167 */
168function encodeStorageKey(key: string | number): string {
169 if (typeof key === `number`) {
170 return `n:${key}`
171 }
172 return `s:${key}`
173}
174
175/**
176 * Decodes a storage key back to its original form.

Callers 1

saveToStorageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected