UNPKG

@techsio/storefront-data

Version:

Medusa-first storefront data layer built on TanStack Query.

40 lines (39 loc) • 1.18 kB
const resolveLocalStorage = (storage)=>{ try { if (storage) return storage; if ("undefined" == typeof window) return null; return window.localStorage; } catch { return null; } }; const getStorageItem = (storage, key)=>{ if (!storage) return null; try { return storage.getItem(key); } catch { return null; } }; const setStorageItem = (storage, key, value)=>{ if (!storage) return false; try { storage.setItem(key, value); return true; } catch { return false; } }; const removeStorageItem = (storage, key)=>{ if (!storage) return false; try { storage.removeItem(key); return true; } catch { return false; } }; const getLocalStorageItem = (key, storage)=>getStorageItem(resolveLocalStorage(storage), key) ?? null; const setLocalStorageItem = (key, value, storage)=>setStorageItem(resolveLocalStorage(storage), key, value); const removeLocalStorageItem = (key, storage)=>removeStorageItem(resolveLocalStorage(storage), key); export { getLocalStorageItem, removeLocalStorageItem, resolveLocalStorage, setLocalStorageItem };