UNPKG

@zootools/waitlist-js

Version:

Viral whitelists / waitlists for nfts and web3 projects

50 lines (41 loc) 955 B
const HAS_WINDOW = typeof window !== 'undefined' function LocalStorage() { let memoryStorage: any = {}; function hasLocalStorage() { return HAS_WINDOW && typeof window.localStorage !== "undefined"; } function clear() { if (hasLocalStorage()) { localStorage.clear(); } else { memoryStorage = {}; } } function setItem(key: string, value: any) { if (hasLocalStorage()) { localStorage.setItem(key, value); } else { memoryStorage[key] = value; } } function getItem(key: string) { if (hasLocalStorage()) { return localStorage.getItem(key); } return memoryStorage[key]; } function removeItem(key: string) { if (hasLocalStorage()) { return localStorage.removeItem(key); } else if (key in memoryStorage) { delete memoryStorage[key]; } } return { clear, setItem, getItem, removeItem, }; } export default LocalStorage();