Browser storage, ultra-enhanced
Store rich values, expire stale data, validate reads, subscribe to changes, and use it from React through a familiar Storage API.
Compare with localStorage
Objects
JSON.stringify({ name: "Ada" })Serialize the user before saving itsetItem("user", { name: "Ada" })Store and read the user as an objectExpiration
setItem("otp", "4821")Remove the OTP yourself after five minutessetItem("otp", 4821, { ttl: 3e5 })Expire the OTP automatically after five minutesValidation
User.parse(JSON.parse(storedUser))Parse and validate the saved usergetItem("user", { schema: User })Validate the saved user while reading itSubscriptions
event.key === "cart" && syncCart()Listen to every storage event and filter for cartsubscribe("cart", syncCart)React only when the cart changesCreate a storage instance
Create one shared instance, then read and write real JavaScript values without manual serialization. Add expiration and subscriptions only where you need them.
import { createStorage } from 'ultrastorage';
const storage = createStorage({ prefix: 'editor' });
storage.setItem(
'draft:post-42',
{
title: 'Introducing ultrastorage',
updatedAt: new Date(),
tags: new Set(['release', 'docs']),
},
{ ttl: 86_400_000 },
);
storage.subscribe('draft:post-42', refreshPreview);
Features
Store JavaScript, not strings
Keep Dates, Maps, Sets, BigInts, RegExps, circular references, and more. Skip the
JSON.stringify dance.
Expire stored values
Give each write a TTL or absolute expiration time. Expired values behave like missing keys and can be swept in one call.
Trust what you read
Validate persisted data with any synchronous Standard Schema library, including Zod, Valibot, and ArkType.
Stay synchronized
Subscribe to individual keys and react to writes from the same page, other instances, or other browser tabs.
Give keys their own space
Group related keys with a prefix and clear entries within that namespace.
Connect React without plumbing
Use typed hooks, functional updates, stable snapshots, and server-rendering defaults with React 18 or 19.