@yehonadav/safestorage
v1.0.10
Published
Replace JSON.stringify with safeStringify to stringify circular objects
Downloads
53
Maintainers
Readme
safestorage
Safe implementation for localStorage and sessionStorage.
Fallback to in-memory implementation if default browser implementations aren't available.
install
npm i @yehonadav/safestorage
usage
import {persistLocal} from "safesstorage"
// set items
persistLocal.setItem('book', {name:"Book", author:"John Blue"});
// get items
const book = persistLocal.getItem<string>('name');
console.log(book);
// delete items
persistLocal.delItem('name');
// safely get items
const {value, error} = persistLocal.tryToGetItem<string>('name');
console.log({value, error});
enjoy =)