mirror of
https://github.com/1Panel-dev/CordysCRM.git
synced 2026-05-19 15:58:11 +08:00
31 lines
635 B
TypeScript
31 lines
635 B
TypeScript
export const getLocalStorage = <T = string>(name: string, isJson?: boolean): T | null => {
|
|
try {
|
|
const value = localStorage.getItem(name);
|
|
if (value && isJson) {
|
|
return JSON.parse(value) as T;
|
|
}
|
|
return value as T;
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
export const setLocalStorage = (name: string, value: any): void => {
|
|
try {
|
|
if (typeof value !== 'string') {
|
|
value = JSON.stringify(value);
|
|
}
|
|
localStorage.setItem(name, value);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
};
|
|
|
|
export const removeLocalStorage = (name: string) => {
|
|
try {
|
|
localStorage.removeItem(name);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
};
|