Skip to main content

Import

What it does

StorageManager provides a unified key-value storage API that works in the browser (localStorage / sessionStorage) and falls back to an in-memory store in Node.js or environments where the Web Storage API is unavailable. Keys are automatically namespaced with a configurable prefix.
In Node.js the in-memory fallback behaves identically to the browser API, so your code can run isomorphically without conditional imports.

Constructor

StorageManagerConfig

Methods

get<T>(key)

Returns the deserialized value for key, or null if the key does not exist.

set<T>(key, value)

Serializes and stores value under key.

remove(key)

Deletes the entry for key.

clear()

Removes all entries managed by this StorageManager instance (scoped by prefix).

has(key)

Returns true if key exists in storage.

keys()

Returns an array of all keys (without the prefix) stored by this instance.

getAll()

Returns a record of every key-value pair managed by this instance.

size()

Returns the number of entries.

Examples

Basic session storage

Custom serializer for dates

Node.js in-memory usage

Use a unique prefix per feature or module to avoid key collisions when multiple parts of your application share the same storage backend.
Browser storage is limited to roughly 5 MB per origin. For larger datasets consider CacheManager or IndexedDB.