0.2.7 • Published 9 months ago

km-storage v0.2.7

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

km-storage

km-storage is a Typescript library for use Local Storage.

Installation

Use the package manager npm to install km-storage.

npm install km-storage

Usage

import storage from "km-storage";
import { z } from "zod";

let schema = z.object({
  gender: z.union([z.literal("F"), z.literal("M")]),
  isDark: z.boolean(),
  userInfo: z.object({
    name: z.string(),
    age: z.number(),
    email: z.string().email(),
  }),
});
let localDB = storage.install(schema, { prefix: "db", mode: "sessionStorage" });

// unions examples
// ----------------------------
localDB.create("gender", "M"); // validator trow error if entry is not equal with "M" or "F"
localDB.use("gender"); // return "M" // return string
localStorage.getItem("db:gender"); // return "M" // return string
// -----------------------------

// boolean examples
// ----------------------------
localDB.create("isDark", true);
localDB.use("isDark"); // return true ( type is boolean )
localStorage.getItem("db:isDark"); // return "true" ( type is string )
// -----------------------------

// object examples
// ----------------------------
localDB.create("userInfo", { name: "Komeil", age: 26, email: "komeilmohammadian1376.web@gmail.com" });
localDB.use("userInfo"); // return { ... } ( type is Object )
localStorage.getItem("db:isDark"); // return "{ ... }" ( type is string )
// -----------------------------

dependensies

Required Dependensies is ZOD

License

MIT

0.2.7

9 months ago

0.2.5

11 months ago

0.2.4

11 months ago

0.2.3

11 months ago

0.2.2

11 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.11

11 months ago

0.1.10

11 months ago

0.1.9

11 months ago

0.1.8

11 months ago

0.1.7

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago

0.0.0

11 months ago