@createnextapp/async-local-storage
Version:
AsyncLocalStorage is an unencrypted, asynchronous, persistent, key-value storage system that is global to the app in web browser. It should be used instead of LocalStorage.
2 lines (1 loc) • 968 B
JavaScript
const t=(t,e)=>new Promise((r,o)=>{try{const o=t();e&&e(null,o),r(o)}catch(t){e&&e(t),o(t)}}),e=(t,e,r)=>Promise.all(t).then(t=>{const o=r?r(t):null;return e&&e(null,o),Promise.resolve(o)},t=>(e&&e(t),Promise.reject(t)));class r{static setItem(e,r,o){return t(()=>{window.localStorage.setItem(e,r)},o)}static getItem(e,r){return t(()=>window.localStorage.getItem(e),r)}static removeItem(e,r){return t(()=>window.localStorage.removeItem(e),r)}static clearStorage(e){return t(()=>{window.localStorage.clear()},e)}static getKeys(e){return t(()=>{const t=window.localStorage.length,e=[];for(let r=0;r<t;r+=1){const t=window.localStorage.key(r);e.push(t)}return e},e)}static setMultiple(t,o){const n=t.map(t=>{for(const e in t)r.setItem(e,t[e])});return e(n,o)}static getMultiple(t,o){const n=t.map(t=>r.getItem(t));return e(n,o,e=>e.map((e,r)=>{const o={};return o[t[r]]=e,o}))}static removeMultiple(t,o){const n=t.map(t=>r.removeItem(t));return e(n,o)}}export default r;