Files
jh-monitor/src/lib/utils.ts
2025-09-27 10:37:27 +08:00

17 lines
532 B
TypeScript

import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
// 合并 className
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
// 取数组第一个元素,支持映射
export function first<T>(array: T[]): T | undefined
export function first<T, I>(array: T[], select: (item: T) => I): I | undefined
export function first<T, I>(array: T[], select?: (item: T) => I) {
const item = array.length > 0 ? array[0] : undefined
return select && item ? select(item) : item
}