File size: 871 Bytes
820c67c
 
 
 
 
de40b1a
 
 
 
820c67c
 
 
de40b1a
 
820c67c
 
de40b1a
 
820c67c
 
de40b1a
 
 
 
 
 
820c67c
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
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'
}