codenuk_frontend_mine/src/lib/utils.ts

34 lines
950 B
TypeScript

import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
// Safe redirect function that works in both client and server environments
export const safeRedirect = (url: string) => {
if (typeof window !== 'undefined') {
window.location.href = url;
}
};
// Safe localStorage functions
export const safeLocalStorage = {
getItem: (key: string): string | null => {
if (typeof window !== 'undefined' && window.localStorage) {
return window.localStorage.getItem(key);
}
return null;
},
setItem: (key: string, value: string): void => {
if (typeof window !== 'undefined' && window.localStorage) {
window.localStorage.setItem(key, value);
}
},
removeItem: (key: string): void => {
if (typeof window !== 'undefined' && window.localStorage) {
window.localStorage.removeItem(key);
}
}
};