Download src/utils/localStorage.js from TA-PangandaranAI/PangandaranAI_FE: direct link, hf CLI and curl.
- Browser
- Download file 860 Bytes
-
https://huggingface.co/spaces/TA-PangandaranAI/PangandaranAI_FE/resolve/main/src/utils/localStorage.js
- Command line
-
hf download hf://spaces/TA-PangandaranAI/PangandaranAI_FE/src/utils/localStorage.js
-
curl -L -o localStorage.js https://huggingface.co/spaces/TA-PangandaranAI/PangandaranAI_FE/resolve/main/src/utils/localStorage.js
860 Bytes
| /** | |
| * localStorage utility helpers | |
| * Safe wrappers that handle SSR (server-side) and errors gracefully | |
| */ | |
| export function loadFromStorage(key, fallback = null) { | |
| if (typeof window === 'undefined') return fallback; | |
| try { | |
| const stored = localStorage.getItem(key); | |
| return stored ? JSON.parse(stored) : fallback; | |
| } catch { | |
| return fallback; | |
| } | |
| } | |
| export function saveToStorage(key, value) { | |
| if (typeof window === 'undefined') return; | |
| try { | |
| localStorage.setItem(key, JSON.stringify(value)); | |
| } catch { | |
| console.warn(`Failed to save to localStorage key: ${key}`); | |
| } | |
| } | |
| export function removeFromStorage(key) { | |
| if (typeof window === 'undefined') return; | |
| try { | |
| localStorage.removeItem(key); | |
| } catch { | |
| console.warn(`Failed to remove localStorage key: ${key}`); | |
| } | |
| } | |