Skip to main content

Quick Start

Your first set() needs an available adapter. The exported storage instance registers the standard web adapters and initialises on first use. You don't construct or initialise it.

📦 Install #​

yarn add strata-storage

The package is ESM-only and requires Node 24.13 or later in your toolchain. It has no runtime dependencies. React, Vue, Angular, Firebase and Capacitor integrations are optional sub-path imports with their own peer requirements.

🛠️ Write and read a value #​

import { storage } from 'strata-storage';

await storage.set('draft', { title: 'First pass' });
const draft = await storage.get<{ title: string }>('draft');

console.log(draft?.title); // First pass

await storage.remove('draft');
console.log(await storage.has('draft')); // false

The default preference order is localStorage, indexedDB, sessionStorage, then memory. The instance also registers cookies and cache; keys(), clear() and size() without a storage option span all registered adapters. subscribe() listens to registered adapters that support change events. The URL adapter is exported but must be registered explicitly. See storage selection before calling a broad clear().

get<T>() returns T | null when you supply T; without it the result is unknown | null. The type parameter describes your data to TypeScript. It does not validate stored data at runtime.

⚙️ Configure one instance for your app #​

Use defineStorage() when you need a different adapter preference or feature set. It registers the standard web adapters and initialises lazily, just like storage.

import { defineStorage } from 'strata-storage';

export const appStorage = defineStorage({
defaultStorages: ['indexedDB', 'localStorage', 'memory'],
});

await appStorage.set('theme', 'dark');
const theme = await appStorage.get<string>('theme');

defaultStorages sets preference order; it does not limit which adapters are registered. To exclude an adapter, use adapters: { <name>: false } in the configuration. Configuration explains adapter options and the strata: key prefix used by localStorage and sessionStorage since 3.0.

📱 Choose a framework or native guide #​

The core API works without a provider. For a framework, create an instance with defineStorage() and bind it:

  • React: bind hooks with createStrataHooks().
  • Vue: bind composables with createStrataComposables().
  • Angular: provide an instance through provideStrata().

On iOS and Android, register the Capacitor adapters, run yarn cap sync, and verify reads and writes on a device. A browser test does not exercise Keychain, EncryptedSharedPreferences, SQLite or the native filesystem. Follow the device verification guide.

🎛️ Explore feature guides and limits #​

  • Encryption and compression are opt-in and use the asynchronous API.
  • Expiry supports absolute or sliding TTL.
  • Queries filter stored values; Strata Storage remains client-side key-value storage, not a multi-user database.
  • Key-prefix migration moves qualifying 2.x localStorage and sessionStorage keys on read, not in a bulk sweep.
  • If one browser app only needs localStorage, use it directly.

➡️ API reference #​

Open the API reference for method and option contracts, or try the basic usage examples for another round-trip.