import { type ClassValue, clsx } from 'clsx'; import { twMerge } from 'tailwind-merge'; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } export function toArray(input?: T | T[] | null): T[] { if (!input) return []; return Array.isArray(input) ? input : [input]; } export function toTitleCase(str?: string) { if (!str) return ''; return str.replace( /\w\S*/g, (text: string) => text.charAt(0).toUpperCase() + text.substring(1).toLowerCase(), ); } export function sortByDate(a: T[] | undefined, key: keyof T): T[] | undefined { return a?.sort((a, b) => { if (!a[key] || !b[key]) { return 0; } return new Date(b[key] as string).getTime() - new Date(a[key] as string).getTime(); }); }