npm Package
store-guard
An open-source npm package that makes browser storage type-safe, validated and synced across tabs.
- < 3 kBminified + gzipped
- 0core dependencies
- MITopen source
01 The problem
Reading localStorage directly gives you no types and no validation: one missing field and the app crashes. store-guard wraps browser storage so every read is typed and checked against a schema.
02 What I built
I designed and published store-guard to npm: a framework-agnostic core with a React hook and a Vue composable on top.
You describe your data with a schema; every read is validated and typed, and stored data can be migrated between versions without being lost.
03 Highlights
- Strict TypeScript types end to end.
- Schema validation with Zod, Valibot or Yup.
- Version migrations, so the data shape can change without losing users' data.
- TTL support to expire old data automatically.
- Cross-tab synchronisation.
- Smart serialisation of Date, Map and Set.
- createStore with get, set, update, remove, has and onUpdate; useSafeStorage for React and Vue.
04 Under the hood
Got an idea like this?
I'm Nader Dweik, a software engineer in Jordan. I design the system, build it and ship it.