jira/apps/web/core/lib/local-storage.ts
vickytechkey 03c6c3d479
All checks were successful
Deploy Plane Project Tracker / Deploy to cisystem (push) Successful in 35s
feat: Add bulk import functionality for issues and run pnpm fix
2026-09-19 21:11:08 +05:30

33 lines
1.1 KiB
TypeScript

/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/
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);
},
};