Skip to main content

Vali-Storages

TypeScript library for browser storage management with AES-GCM encryption, TTL expiration, namespacing, cross-tab sync, and a fully typed API.

npm version license


Why Vali-Storages?

Native localStorage and sessionStorage are untyped, unencrypted, and have no built-in expiration. Vali-Storages wraps them with a clean, async API that adds:

  • Security — AES-GCM 128/192/256-bit encryption via Web Crypto API
  • Reliability — automatic TTL expiration with sliding window support
  • Isolation — prefix-based namespacing to prevent key collisions
  • Reactivity — cross-tab synchronization with a callback API
  • Type safety — fully typed createTypedStorage<Schema>() factory

Key Features

FeatureDescription
🔐 AES-GCM encryptionAES-128 / 192 / 256 via Web Crypto API
TTL expirationSeconds, minutes, hours, or days
🔄 Sliding expirationTTL resets on every successful read
🏷 NamespacingIsolate keys between instances with prefix
📡 Cross-tab syncReact to changes from other browser tabs
🧩 Batch operationssetItems / getItems / getAll
🛡 Error handlingthrow, silent, or custom handler
🔒 Type-safe APIcreateTypedStorage<Schema>()
🖥 SSR guardClear error when used outside browser

Quick example

import { ValiStorages, AES, TimeUnit } from 'vali-storages';

const storage = new ValiStorages({
isEncrypt: true,
predefinedKey: 'my-secret-key',
keySize: AES.AES_256,
timeExpiration: 2,
timeUnit: TimeUnit.HOURS,
prefix: 'myapp',
});

await storage.setItem('user', { name: 'Felipe', role: 'admin' });
const user = await storage.getItem<{ name: string; role: string }>('user');

Next steps