Welcome to Storagefy

Storagefy is a unified adapter system for syncing your state management libraries (like Pinia, Zustand, Redux, Svelte stores, and more) with browser storage mechanisms like localStorage, sessionStorage, or IndexedDB.

It’s built to be framework-agnostic, lightweight, and highly composable — empowering you to persist your state across reloads and sessions in a clean, plug-and-play way.

Installation

npm install storagefy

Or with yarn:

yarn add storagefy

The package ships its TypeScript declarations.

What's new in 1.4.0

  • Every write has a revision: a store applies another tab's state only when it is newer than its own. A change in one tab is never undone by an older state from another — two tabs changing a store at once end with the same state, the one stored (with localStorage, the tab of the newer change writes it again: localStorage may save the older one last).
  • A change of an ignoreKeys key alone writes nothing (and no longer renews thetimeout expiration); setInStorage does not write a state already stored.
  • With IndexedDB and localStorage, a tab shown again (back from the background or the page cache) reads storage again.

Values stay readable both ways between 1.3.0 and 1.4.0. See thechangelog.

What's new in 1.3.0

  • keyDerivation: "hkdf" (the new default, fast) or "pbkdf2" (slow on purpose, for a password the person types). Values written by 1.2.x are still read.
  • onError on reads: tell "nothing stored" from "stored but unreadable".
  • Writes of a key land in the order they were made; IndexedDB reports a write saved only once its transaction is; a burst of changes to a store is one write.
  • Fixed: Svelte stores now sync between tabs; several stores can share one storage adapter's channel;list(prefix) and getAll(table) filter; large values encrypt.

Read thechangelog before upgrading: values written by 1.3.0 cannot be read by older versions.

About encryption

encrypt: true makes the stored values hard to read in the browser's tools. It does not keep a secret: everything needed to decrypt ships with your app. Never store tokens, passwords or personal data you must protect — keep Storagefy for preferences, carts, drafts and the like.

Adapters Overview

LocalStorageAdapter

Persists your state using the browser’s localStorage. Data survives across tabs and sessions. Great for most use cases that need durable client-side persistence.

SessionStorageAdapter

Uses sessionStorage for persistence that lasts only for the duration of the browser tab — for temporary state. It is gone when the tab closes, but it does not protect anything while the tab is open.

IndexedDBAdapter

Stores large and complex state structures asynchronously using IndexedDB — the default adapter. A write is reported saved only once its transaction is; the service worker of a PWA can read it too.

Stores Overview

React Store Adapter

Seamlessly syncs state from React-based stores like Redux, Zustand, Jotai, or custom hooks to any supported storage adapter. Built for flexibility, supporting both controlled and uncontrolled stores.

Svelte Store Adapter

Persists Svelte writable stores with minimal setup and keeps reactivity intact. Load what was kept with getFromStorage, then keep every change with setInStorage.

Vue (Pinia) Store Adapter

Integrates with Pinia (Vue 3’s store library) to persist state across sessions. Easy to plug into existing Pinia stores, enabling persistence without side effects.