Files
ARTEX/web/src/lib/utils.ts
T
Autumn-27andClaude Opus 4.8 0ef8561411 chore: ARTEX 初始化
ARTEX — AI 自主渗透测试系统(Go 后端 + Next.js 前端,单二进制内嵌)。

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-07-26 04:27:45 -04:00

43 lines
1.0 KiB
TypeScript

import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const getInitials = (str: string): string => {
if (typeof str !== "string" || !str.trim()) return "?";
return (
str
.trim()
.split(/\s+/)
.filter(Boolean)
.map((word) => word[0])
.join("")
.toUpperCase() || "?"
);
};
export function formatCurrency(
amount: number,
opts?: {
currency?: string;
locale?: string;
minimumFractionDigits?: number;
maximumFractionDigits?: number;
noDecimals?: boolean;
},
) {
const { currency = "USD", locale = "en-US", minimumFractionDigits, maximumFractionDigits, noDecimals } = opts ?? {};
const formatOptions: Intl.NumberFormatOptions = {
style: "currency",
currency,
minimumFractionDigits: noDecimals ? 0 : minimumFractionDigits,
maximumFractionDigits: noDecimals ? 0 : maximumFractionDigits,
};
return new Intl.NumberFormat(locale, formatOptions).format(amount);
}