File size: 2,809 Bytes
f31cfe8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | export function formatCurrency(amount: number): string {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(amount);
}
export function formatPercentage(value: number): string {
return `${(value * 100).toFixed(1)}%`;
}
export function formatDate(date: string | Date | null): string {
if (!date) return "N/A";
return new Intl.DateTimeFormat("en-US", {
month: "short",
day: "numeric",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
}).format(new Date(date));
}
export function formatDuration(seconds: number): string {
if (seconds < 60) return `${seconds}s`;
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return `${hours}h ${minutes}m`;
}
export function getConfidenceColor(confidence: number): string {
if (confidence >= 0.8) return "text-[#14F195]";
if (confidence >= 0.5) return "text-[#00F5FF]";
if (confidence >= 0.3) return "text-[#B87333]";
return "text-red-400";
}
export function getStatusColor(status: string): string {
const colors: Record<string, string> = {
pending: "text-yellow-400",
analyzing: "text-[#00F5FF]",
negotiating: "text-[#9945FF]",
approved: "text-[#14F195]",
rejected: "text-red-400",
transacting: "text-[#B87333]",
completed: "text-[#14F195]",
failed: "text-red-400",
queued: "text-yellow-400",
running: "text-[#00F5FF]",
cancelled: "text-gray-400",
};
return colors[status] || "text-gray-400";
}
export function getStatusBg(status: string): string {
const colors: Record<string, string> = {
pending: "bg-yellow-400/10",
analyzing: "bg-[#00F5FF]/10",
negotiating: "bg-[#9945FF]/10",
approved: "bg-[#14F195]/10",
rejected: "bg-red-400/10",
transacting: "bg-[#B87333]/10",
completed: "bg-[#14F195]/10",
failed: "bg-red-400/10",
queued: "bg-yellow-400/10",
running: "bg-[#00F5FF]/10",
cancelled: "bg-gray-400/10",
};
return colors[status] || "bg-gray-400/10";
}
export function truncate(str: string, length: number): string {
if (str.length <= length) return str;
return str.slice(0, length) + "...";
}
export function extractDomain(url: string): string {
try {
return new URL(url).hostname.replace("www.", "");
} catch {
return url;
}
}
export function cn(...classes: (string | false | undefined | null)[]): string {
return classes.filter(Boolean).join(" ");
}
export function calculateROI(buyPrice: number, sellPrice: number): number {
if (buyPrice === 0) return 0;
return (sellPrice - buyPrice) / buyPrice;
}
export function generateId(): string {
return Math.random().toString(36).substring(2) + Date.now().toString(36);
}
|