Socket
Book a DemoInstallSign in
Socket

@purified-app/typed-storage

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@purified-app/typed-storage

A type-safe wrapper for localStorage and sessionStorage

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

@purified-app/typed-storage

A type-safe wrapper for localStorage and sessionStorage operations.

Installation

npm install @purified-app/typed-storage

Quick Start

Define Your Types

type MyStorage = {
  user: { id: number; name: string };
  settings: { theme: "light" | "dark" };
};

TypeScript Usage

import { LocalStorageService } from "@purified-app/typed-storage";

const storage = new LocalStorageService<MyStorage>();

// Store data
storage.set("user", { id: 1, name: "John" });

// Retrieve with type safety
const user = storage.get("user"); // { id: number; name: string } | null

// Retrieve with default
const theme = storage.get("settings", { theme: "light" }); // { theme: "light" | "dark" }

// Check existence
if (storage.has("user")) {
  /* ... */
}

// Use sessionStorage
const session = new LocalStorageService<MyStorage>(sessionStorage);

Angular Usage

import { Injectable } from "@angular/core";
import { LocalStorageService } from "@purified-app/typed-storage";

@Injectable({ providedIn: "root" })
export class AppStorageService extends LocalStorageService<MyStorage> {
  constructor() {
    super(localStorage);
  }
}

// In components
ngOnInit() {
  const storage = inject(AppStorageService);
  const user = storage.get("user");
  const settings = storage.get("settings", { theme: "light" });
}

API

Constructor

new LocalStorageService<T>(storage?: Storage)

Methods

  • get<K>(key: K): T[K] | null - Get value
  • get<K>(key: K, defaultValue: T[K]): T[K] - Get with default
  • set<K>(key: K, value: T[K]): void - Store value
  • has<K>(key: K): boolean - Check existence
  • remove<K>(key: K): void - Remove key
  • clear(): void - Clear all data

Features

  • ✅ Full TypeScript type safety
  • ✅ localStorage & sessionStorage support
  • ✅ Default values in get operations
  • ✅ Framework agnostic (works with React, Vue, Angular, etc.)
  • ✅ Automatic JSON serialization
  • ✅ Error handling for invalid data

License

MIT

Keywords

localStorage

FAQs

Package last updated on 06 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts