Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

localgeneric

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localgeneric

Local Storage wrapper with TypeScript generics support.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

localgeneric

localgeneric is a type-safe wrapper for localStorage which provides support for TypeScript generics.

Unit Tests

Installation

npm install localgeneric

Examples

This example shows getting and setting a string value in localStorage under the key stringStore. TypeScript will error if an attempt to set a non-string value is made.

import { Store } from "localgeneric";

const myStore = new Store<string>("stringStore", "J. Doe");
console.log(myStore.get()); // output: "J. Doe"

myStore.set("B. Ross");
console.log(myStore.get()); // output: "B. Ross"

Objects can be stored with their types enforced, with direct access to an object's properties on the store itself:

import { Store } from "localgeneric";

interface StoreProps {
  foo: string;
  bar: number;
  baz?: boolean;
}

const myStore = new Store<StoreProps>({ foo: "bar", bar: 1 });

console.log(myStore.foo); // Output: "bar"
console.log(myStore.bar); // Output: 1
console.log(myStore.baz); // Output: undefined

Keywords

FAQs

Package last updated on 10 Apr 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc