Files

41 lines
1.2 KiB
TypeScript

export function timeAgo(ts: number, active?: boolean): string {
if (active) return "now";
const now = Date.now() / 1000;
const diff = now - ts;
if (diff < 60) return "just now";
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
if (diff < 604800) return `${Math.floor(diff / 86400)}d ago`;
return new Date(ts * 1000).toLocaleDateString();
}
export function formatTokens(n: number): string {
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`;
return String(n);
}
export function platformColor(source: string): string {
const map: Record<string, string> = {
cli: "#f59e0b",
telegram: "#38bdf8",
discord: "#8b5cf6",
whatsapp: "#22c55e",
web: "#a78bfa",
webapi: "#a78bfa",
};
return map[source] || "#6b7280";
}
export function platformBadgeClass(source: string): string {
const map: Record<string, string> = {
cli: "badge-cli",
telegram: "badge-telegram",
discord: "badge-discord",
whatsapp: "badge-whatsapp",
web: "badge-web",
webapi: "badge-web",
};
return map[source] || "badge-cli";
}