createNativeStore
Creates a named store with the selected storage type, or returns it when reuse is enabled.
Table of contents
Category
Value
Import
jsimport { createNativeStore } from "valyrian.js/native-store";Public signature
tscreateNativeStore<T>(id: string, definition?: Record<string, unknown>, storageType?: StorageType, reuseIfExist?: boolean): NativeStorageInterface & TAPI form
createNativeStore is a factory. It creates a named object backed by local storage by default or session storage when StorageType.Session is selected.
Returned surface
tsstate: Record<string, unknown>
set(key: string, value: unknown): void
get(key: string): unknown
delete(key: string): void
load(): void
clear(): void
cleanup(): voidReuse
A duplicate id throws unless reuseIfExist is true. With reuse enabled, the factory returns the existing named store.
Errors
Throws when a store with the same identifier already exists and reuse is not enabled. In Node.js, import valyrian.js/node before creating a store so localStorage and sessionStorage exist.