-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6153ec4
commit 7777d5e
Showing
2 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const LocalStorage = { | ||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
set: (key: string, value: any) => { | ||
if (typeof window === "undefined") return; | ||
|
||
try { | ||
const serializedValue = JSON.stringify(value); | ||
localStorage.setItem(key, serializedValue); | ||
} catch (e) { | ||
console.error("LocalStorage set error:", e); | ||
} | ||
}, | ||
|
||
get: (key: string) => { | ||
if (typeof window === "undefined") return null; | ||
|
||
try { | ||
const serializedValue = localStorage.getItem(key); | ||
if (serializedValue === null) return null; | ||
return JSON.parse(serializedValue); | ||
} catch (e) { | ||
console.error("LocalStorage get error:", e); | ||
return null; | ||
} | ||
}, | ||
|
||
remove: (key: string) => { | ||
if (typeof window === "undefined") return; | ||
|
||
try { | ||
localStorage.removeItem(key); | ||
} catch (e) { | ||
console.error("LocalStorage remove error:", e); | ||
} | ||
}, | ||
|
||
clear: () => { | ||
if (typeof window === "undefined") return; | ||
|
||
try { | ||
localStorage.clear(); | ||
} catch (e) { | ||
console.error("LocalStorage clear error:", e); | ||
} | ||
}, | ||
}; | ||
|
||
export default LocalStorage; |