Client Web Storage
Browser storage interface for IndexedDB, WebSQL, LocalStorage, and in memory data with basic Schema and data validation.
Installation
In Node Projects:
npm install client-web-storage
import {Schema, ClientStore} from "client-web-storage";
In the Browser
<!-- use the latest version -->
<script src="https://unpkg.com/client-web-storage/dist/client-web-storage.min.js"></script>
<!-- use a specific version -->
<script src="https://unpkg.com/[email protected]/dist/client-web-storage.min.js"></script>
const {Schema, ClientStore} = window;
Get Started
The library is very small but super powerful. There are only few things to interact with:
- Schema : Determines how the data looks like;
- SchemaValue : Creates a single value in the schema;
- ClientStore : Manages the data (CRUD);
// Define schema TS type
import {ClientStore, Schema} from "client-web-storage";
interface ToDo extends Schema.DefaultValue {
name: string;
description: string;
complete: boolean;
}
// create and define schema
const todoShema = new Schema<ToDo>("todo");
todoShema.defineField("name", String, {required: true});
todoShema.defineField("description", String, "No Description");
todoShema.defineField("complete", Boolean);
// create and use the store
const todoStore = new ClientStore("todos", todoShema);
todoStore.createItem({
name: "Go to Gym" // only name is required
});
/* Creates item in the store
{
id: "123e4567-e89b-12d3-a456-426614174000", // generated id
name: "Go to Gym",
description: "No Description",
complete: false,
createdDate: "January, 4th 2022",
lastUpdatedDate: "January, 4th 2022",
}
*/