2.2.0 • Published 1 year ago

@kolabuk/localstorage v2.2.0

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

@kolabuk/localstorage

Simple local storage

Installation

npm i @kolabuk/localstorage

Importing

import { LocalStorage } from "@kolabuk/localstorage";

Usage

type AccountStorage = {
  account: {
    email: string;
    password: string;
  };
  info?: string;
};
type SessionStorage = {
  session?: { id: string; token: string };
  timestamp?: number;
};
const accountStorage = new LocalStorage<AccountStorage>({
  initObj: {
    account: { email: "email@example.com", password: "password" },
  },
  storageFileName: "account",
});
console.log("accountStorage", accountStorage.storage);
accountStorage.load();
console.log("accountStorage", accountStorage.storage);
accountStorage.storage.account = { email: "email", password: "password" };
console.log("accountStorage", accountStorage.storage);
accountStorage.save();
const sessionStorage = new LocalStorage<SessionStorage>({
  initObj: {},
  storageFileName: "session",
});
console.log("sessionStorage", sessionStorage.storage);
sessionStorage.load();
console.log("sessionStorage", sessionStorage.storage);
sessionStorage.storage = {
  session: { id: "UUIDv4", token: "token" },
  timestamp: new Date().getTime(),
};
console.log("sessionStorage", sessionStorage.storage);
sessionStorage.save();
sessionStorage.backup();
2.2.0

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.0.0

2 years ago