import { browser } from "$app/environment"; import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } // eslint-disable-next-line @typescript-eslint/no-explicit-any export type WithoutChild = T extends { child?: any } ? Omit : T; // eslint-disable-next-line @typescript-eslint/no-explicit-any export type WithoutChildren = T extends { children?: any } ? Omit : T; export type WithoutChildrenOrChild = WithoutChildren>; export type WithElementRef = T & { ref?: U | null; }; export const calcReadingTime = (text: string) => { const wordsPerMinute = 200; // Average case. const textLength = text.split(" ").length; // Split by words if (textLength > 0) { return Math.ceil(textLength / wordsPerMinute); } return 0; }; export const getUserInitials = (name: string) => { if (!name) return "??"; return name .split(" ") .map((word) => word.charAt(0)) .join("") .toUpperCase() .slice(0, 2); }; export const formatVideoDuration = (duration: number) => { const hours = Math.floor(duration / 3600); const minutes = Math.floor((duration - hours * 3600) / 60); const seconds = duration - hours * 3600 - minutes * 60; return `${hours < 10 ? "0" + hours : hours}:${minutes < 10 ? "0" + minutes : minutes}:${seconds < 10 ? "0" + seconds : seconds}`; };