flowstate / src /lib /utils.ts
muthuk1's picture
Complete FlowState project - 6 pages, 3 API routes, all components, build verified
de40b1a verified
raw
history blame contribute delete
871 Bytes
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) }
export function fmtNum(n: number): string {
if (n >= 1e9) return (n / 1e9).toFixed(2) + 'B'
if (n >= 1e6) return (n / 1e6).toFixed(2) + 'M'
if (n >= 1e3) return (n / 1e3).toFixed(1) + 'K'
return n.toFixed(0)
}
export function fmtUsd(n: number): string {
return '$' + n.toLocaleString('en-US')
}
export function shortAddr(a: string): string {
return a.length < 10 ? a : a.slice(0, 4) + '...' + a.slice(-4)
}
export function timeAgo(d: Date): string {
const s = Math.floor((Date.now() - d.getTime()) / 1000)
if (s < 60) return s + 's ago'
if (s < 3600) return Math.floor(s / 60) + 'm ago'
if (s < 86400) return Math.floor(s / 3600) + 'h ago'
return Math.floor(s / 86400) + 'd ago'
}