@alessiofrittoli/web-utils
Version:
Common TypeScript web utilities
1 lines • 951 B
JavaScript
import {isValidDate}from'@alessiofrittoli/date-utils';import {isNumeric}from'@alessiofrittoli/math-utils';var i=t=>t instanceof Promise;var a=t=>typeof t=="string"||t instanceof String;var f=t=>t.trim().length>0,c=t=>!f(t);var p=t=>i(t)||typeof t=="function"?"":t instanceof Date&&isValidDate(t)?t.toISOString():t instanceof Map||t instanceof Headers?JSON.stringify(Array.from(t.entries())):typeof t=="object"?JSON.stringify(t):t?.toString()||"",m=t=>{if(t&&!(a(t)&&c(t))){if(isNumeric(t))return parseFloat(t);try{let e=new Date(t);return isValidDate(e)?e:JSON.parse(t)}catch{return t}}};var b=class t{static get(e){return m(localStorage.getItem(e)||void 0)}static set(e,s){let o=p(s);return s==null||!o?t.delete(e):localStorage.setItem(e,o)}static delete(e){return localStorage.removeItem(e)}static clear(){return localStorage.clear()}static key(e){return localStorage.key(e)}static getLength(){return localStorage.length}};export{b as LocalStorage};