- Added null check in getUserInitials function to return "??" for undefined names - Fixed logout button to handle undefined user.name when displaying first name - Prevents 500 errors when rendering components for users without names 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
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> = T extends { child?: any } ? Omit<T, "child"> : T;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export type WithoutChildren<T> = T extends { children?: any }
|
|
? Omit<T, "children">
|
|
: T;
|
|
export type WithoutChildrenOrChild<T> = WithoutChildren<WithoutChild<T>>;
|
|
export type WithElementRef<T, U extends HTMLElement = HTMLElement> = 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}`;
|
|
};
|