0.1.0 • Published 2 years ago

lagring v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

lagring

Why it is called "lagring"

What is it

It is a wrapper for the localStorage, except that it

  • do not throws
  • has types

Usage

import { createStorageService } from "lagring";

const schema = {
  code: 'print("Hewwo")' as string,
  plugins: [] as string[],
} as const;

const StorageService = createStorageService(schema);

StorageService.set("code", "print('Hello')"); // <-- Save to the localStorage
StorageService.set("plugins", ["typescript"]); // <-- Save an array. It will be stringified

const plugins = StorageService.get("plugins");

// Can be null
if (plugins !== null) {
  plugins.push("markdown"); // <-- Automatically runs JSON.parse
  StorageService.set("plugins", plugins);
}

StorageService.remove("code"); // <-- Remove from the localStorage

StorageService.set("cide", 'throw "no way"'); // Get an error in compile-time