lagring
v0.1.0
Published
Storage Service based on localStorage
Downloads
1
Readme
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