blob: 193a93b359fc128dba5aaf304e05b99d7c4115d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
export function byte_size(x: number): string {
if (x > 1000000000) return (x / 1000000000).toFixed(1) + "G"
if (x > 1000000) return (x / 1000000).toFixed(1) + "M"
if (x > 1000) return (x / 1000).toFixed(1) + "k"
return x.toString()
}
export function duration(t: number): string {
if (t < 0) return "-" + duration(-t)
let h = 0, m = 0, s = 0;
while (t > 3600) t -= 3600, h++;
while (t > 60) t -= 60, m++;
while (t > 1) t -= 1, s++;
return (h ? h + "h" : "") + (m ? m + "m" : "") + (s ? s + "s" : "")
}
|