1.2.0 • Published 1 year ago

localgeneric v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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
1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago