npm.io
3.0.0 • Published 4 months ago

@springtree/eva-sdk-core-storage

Licence
UNLICENSED
Version
3.0.0
Deps
0
Size
12 kB
Vulns
0
Weekly
0

@springtree/eva-sdk-core-storage

Provides a wrapper around browser localStorage. If localStorage is unvailable (private mode browsing) it will fallback to memory storage solution. This will allow your app and other packages form the SDK to use a consistent API. It will also allow for normal storage functionality within a private browsing session.

Usage

import { EvaStorage } from "@springtree/eva-sdk-core-storage";

// Declare your own storage keys
//
export interface IMyAppStorage {
  key1?: string;
  key2?: string;
}

// Instatiate with out storage shape for type completion on get/set methods
//
const evaStorage = new EvaStorage<IMyAppStorage>();

// Provides methods as found on browser localStorage
//
evaStorage.getItem("key2");

evaStorage.setItem("key1", "my value");

evaStorage.removeItem("key2");

evaStorage.clear();