npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@marcelrsoub/l-storage

v0.0.3

Published

Type-safe wrapper around browser's localStorage API using Zod

Downloads

37

Readme

Features

  • Type-safe get/set operations using Zod schemas
  • Complete access to all native localStorage methods
  • Automatic key tracking and management
  • TypeScript type inference for stored values
  • Runtime validation using Zod
  • Configurable key prefixing
  • Strict/lenient validation modes

Installation

npm install @marcelrsoub/l-storage zod
pnpm add @marcelrsoub/l-storage zod
yarn add @marcelrsoub/l-storage zod
bun add @marcelrsoub/l-storage zod

Note: Zod is a peer dependency and must be installed alongside l-storage.

Usage

import { createTypedStorage } from '@marcelrsoub/l-storage';
import { z } from 'zod';

// Define your storage schema
const storage = createTypedStorage({
  user: z.object({
    name: z.string(),
    age: z.number()
  }),
  theme: z.enum(['light', 'dark']),
  settings: z.record(z.any())
}, {
  prefix: 'app', // optional prefix for all keys
  strict: true   // throw on validation errors
});

// Type-safe operations
storage.set('user', { name: 'John', age: 30 }); // ✅ Valid
storage.set('user', { name: 'John' }); // ❌ TypeScript error
storage.set('theme', 'light'); // ✅ Valid
storage.set('theme', 'blue'); // ❌ TypeScript error

// Get values with correct types
const user = storage.get('user'); // type: { name: string, age: number } | null
const theme = storage.get('theme'); // type: 'light' | 'dark' | null

// Manage keys
storage.remove('user');
storage.clear();
const keys = storage.getRegisteredKeys();
const hasUser = storage.has('user');

Default Values

You can specify default values using Zod's .default() method:

const storage = createTypedStorage({
  theme: z.enum(['light', 'dark']).default('light'),
  user: z.object({
    name: z.string(),
    age: z.number()
  }).default({ name: 'Guest', age: 0 })
});

// Now get() will return the default instead of null when key doesn't exist
const theme = storage.get('theme'); // 'light' instead of null if not set
const user = storage.get('user');   // { name: 'Guest', age: 0 } instead of null if not set

API Reference

createTypedStorage(schemas, options?)

Creates a new typed storage instance.

Parameters

  • schemas: Record of Zod schemas defining the structure of stored data
  • options: (optional) Configuration options
    • prefix: String prefix for all storage keys
    • strict: Whether to throw on validation errors (default: true)

Methods

  • get(key): Get a value by key (returns the default value if schema has one, otherwise null)
  • set(key, value): Set a value for a key
  • remove(key): Remove a value by key
  • clear(): Clear all registered keys
  • getRegisteredKeys(): Get array of all registered keys
  • has(key): Check if a key exists

Error Handling

In strict mode (default), the library throws typed errors for:

  • Invalid data validation
  • JSON parsing failures
  • Storage quota exceeded

Each error includes:

  • key: The storage key that caused the error
  • value: The value that failed
  • type: Error type ('validation' | 'parsing' | 'storage')

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT © Marcel Soubkovsky