22 lines
695 B
TypeScript
22 lines
695 B
TypeScript
/** Join conditional class names. */
|
|
export function cn(...parts: Array<string | false | null | undefined>): string {
|
|
return parts.filter(Boolean).join(' ');
|
|
}
|
|
|
|
export function formatCurrency(amount: number, currency = 'USD'): string {
|
|
return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount);
|
|
}
|
|
|
|
export function formatDate(value: Date | string): string {
|
|
const d = typeof value === 'string' ? new Date(value) : value;
|
|
return new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' }).format(d);
|
|
}
|
|
|
|
export function slugify(value: string): string {
|
|
return value
|
|
.toLowerCase()
|
|
.trim()
|
|
.replace(/[^a-z0-9]+/g, '-')
|
|
.replace(/^-+|-+$/g, '');
|
|
}
|