utils.ts17 lines · main
| 1 | import { clsx, type ClassValue } from 'clsx'; |
| 2 | import { twMerge } from 'tailwind-merge'; |
| 3 | |
| 4 | export function cn(...inputs: ClassValue[]): string { |
| 5 | return twMerge(clsx(inputs)); |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * Parse a date-ish value (ISO string, epoch number, Date) into a valid |
| 10 | * Date, or null when missing/unparseable — so callers can render '—' |
| 11 | * instead of crashing on an "Invalid Date". |
| 12 | */ |
| 13 | export function toValidDate(value: unknown): Date | null { |
| 14 | if (value == null) return null; |
| 15 | const d = value instanceof Date ? value : new Date(value as string | number); |
| 16 | return Number.isNaN(d.getTime()) ? null : d; |
| 17 | } |