UNPKG

@alessiofrittoli/web-utils

Version:
1 lines 987 B
'use strict';var dateUtils=require('@alessiofrittoli/date-utils'),mathUtils=require('@alessiofrittoli/math-utils');var o=t=>t instanceof Promise;var i=t=>typeof t=="string"||t instanceof String;var b=t=>t.trim().length>0,a=t=>!b(t);var g=t=>o(t)||typeof t=="function"?"":t instanceof Date&&dateUtils.isValidDate(t)?t.toISOString():t instanceof Map||t instanceof Headers?JSON.stringify(Array.from(t.entries())):typeof t=="object"?JSON.stringify(t):t?.toString()||"",p=t=>{if(t&&!(i(t)&&a(t))){if(mathUtils.isNumeric(t))return parseFloat(t);try{let e=new Date(t);return dateUtils.isValidDate(e)?e:JSON.parse(t)}catch{return t}}};var m=class t{static get(e){return p(localStorage.getItem(e)||void 0)}static set(e,r){let s=g(r);return r==null||!s?t.delete(e):localStorage.setItem(e,s)}static delete(e){return localStorage.removeItem(e)}static clear(){return localStorage.clear()}static key(e){return localStorage.key(e)}static getLength(){return localStorage.length}};exports.LocalStorage=m;