plane/web/lib/local-storage.ts
sriram veeraghanta 3d09a69d58
fix: eslint issues and reconfiguring (#3891)
* fix: eslint fixes

---------

Co-authored-by: gurusainath <gurusainath007@gmail.com>
2024-03-06 18:39:14 +05:30

28 lines
964 B
TypeScript

import isEmpty from "lodash/isEmpty";
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);
},
};