36 lines
1012 B
TypeScript
36 lines
1012 B
TypeScript
import { clsx, type ClassValue } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function getCalendarNameFromUrl(icsUrl: string | null | undefined): string | null {
|
|
if (!icsUrl) return null;
|
|
try {
|
|
const url = new URL(icsUrl);
|
|
const pathname = url.pathname;
|
|
const filename = pathname.split('/').pop() || '';
|
|
// Decode URL encoding (e.g., %20 -> space) and remove .ics extension
|
|
const decoded = decodeURIComponent(filename).replace(/\.ics$/i, '');
|
|
return decoded || null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function getAvatarColor(name?: string): string {
|
|
const colors = [
|
|
'hsl(var(--tag-green))',
|
|
'hsl(var(--tag-blue))',
|
|
'hsl(var(--tag-orange))',
|
|
'hsl(var(--tag-purple))',
|
|
'hsl(var(--tag-brown))',
|
|
];
|
|
|
|
if (!name) return colors[0];
|
|
|
|
const hash = name.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
|
|
return colors[hash % colors.length];
|
|
}
|