Skip to content
v0.4.2

Storage

@jayoncode/storage

Namespace it. Expire it. Upgrade it — without localStorage glue.

A small policy layer for browser persistence — namespaces, envelopes, TTL, migrations — on adapters you choose: memory, localStorage, sessionStorage, and IndexedDB.

Theme prefs that last — cache that doesn’t

import { createStorage, createLocalStorageAdapter } from "@jayoncode/storage";

const storage = createStorage({
  namespace: "app",
  adapter: createLocalStorageAdapter(),
  policies: {
    preferences: { ttl: { days: 365 } },
    cache: { ttl: { minutes: 15 } },
  },
});

storage.set("theme", "dark", { policy: "preferences" });
storage.get("theme"); // "dark" | null
storage.peek("theme"); // envelope with expiresAt
Read the overview

Why it stands out

createStorage()

Namespace + adapter + optional TTL / schema version in one place.

Explicit adapters

Memory · localStorage · sessionStorage · IndexedDB — the library never auto-picks a backend.

Peek & TTL

peek() shows when something was saved, when it expires, and which version it is.

Migrations

Schema upgrades without ad-hoc key rewrites across releases.

Extra tools (opt-in)

Soft quota, transforms hooks, cleanup, backup, and watchers — only when you import them.

An ecosystem of independent, headless TypeScript libraries engineered for modern web development. Every package includes interactive playgrounds and documentation that evolves alongside the code.