0.1.1 • Published 3 years ago

@alzalabany/storage v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

app-storage, Promise based Local Storage for Web, Node, & React-Native

Very small library that makes working localstorage/sessionstorage on web/node/react-native easier by unifying api.

Features

  • Promise based
  • throw error if key is missing
  • throw error if key expired
  • Works with Browser SessionStorage, LocaStorage
  • Works with node Storage
  • Works with React-Native AsyncStorage
import { webStorage } from '@alzalabany/@alzalabany/storage';

const KEY = 'Hello';
const VAL = 'World';
const EXPIRY = 100;  // expiry is set in ms.

webStorage.setItem(KEY,VAL, EXPIRY)

setTimeout(()=>{
  // this will run after item has expired
  webStorage.getItem(KEY)
    .then(console.log) // will not resolve
    .catch(console.warn) // Expired error will be caught here
},110)