@alzalabany/storage
v0.1.1
Published
Very small library add expiry and promise to localstorage
Downloads
6
Maintainers
Readme
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
- [X] Promise based
- [x] throw error if key is missing
- [x] throw error if key expired
- [x] Works with Browser SessionStorage, LocaStorage
- [x] Works with node Storage
- [x] 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)