feat: init
Some checks failed
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

This commit is contained in:
chuan
2025-11-11 01:56:44 +08:00
commit bba4bb40c8
4638 changed files with 447437 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import { isEmpty } from "lodash-es";
export const storage = {
set: (key: string, value: object | string | boolean): void => {
if (typeof window === undefined || typeof window === "undefined" || !key || !value) return undefined;
const tempValue: string | undefined = value
? ["string", "boolean"].includes(typeof value)
? value.toString()
: isEmpty(value)
? undefined
: JSON.stringify(value)
: undefined;
if (!tempValue) return undefined;
window.localStorage.setItem(key, tempValue);
},
get: (key: string): string | undefined => {
if (typeof window === undefined || typeof window === "undefined") return undefined;
const item = window.localStorage.getItem(key);
return item ? item : undefined;
},
remove: (key: string): void => {
if (typeof window === undefined || typeof window === "undefined" || !key) return undefined;
window.localStorage.removeItem(key);
},
};