// @ts-nocheck import { mutateStorageKey, safeParseJson } from '../' const _inNode = () => typeof window === 'undefined' && typeof process !== 'undefined' const _get = async (storageType: string, key: string): Promise => { if (_inNode()) return null const res = window[storageType].getItem(mutateStorageKey(key)) return safeParseJson(res) } const _set = async ( storageType: string, key: string, value: any ): Promise => { if (_inNode()) return null if (typeof value === 'object') { value = JSON.stringify(value) } window[storageType].setItem(mutateStorageKey(key), value) } const _remove = async (storageType: string, key: string): Promise => { if (_inNode()) return null return window[storageType].removeItem(mutateStorageKey(key)) } export const localStorage = { getItem: (key: string): Promise => _get('localStorage', key), setItem: (key: string, value: any): Promise => _set('localStorage', key, value), removeItem: (key: string): Promise => _remove('localStorage', key), } export const sessionStorage = { getItem: (key: string): Promise => _get('sessionStorage', key), setItem: (key: string, value: any): Promise => _set('sessionStorage', key, value), removeItem: (key: string): Promise => _remove('sessionStorage', key), }