* 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)
| 166 | * @returns Type-prefixed string that is safe for storage |
| 167 | */ |
| 168 | function 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. |