blob: ed75d2fac6d7d049e0047f6b94fd9becc6304c9a (
plain)
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
|
import {type ClassValue, clsx} from "clsx"
import {twMerge} from "tailwind-merge"
import React from "react";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export function assert(condition: any, msg?: string): asserts condition {
if (!condition) {
throw new Error(msg);
}
}
export function formatSecondsVerbose(seconds: number): string {
const mins = Math.floor(seconds / 60)
const secs = seconds % 60
const parts = []
if (mins > 0) parts.push(`${mins} min`)
if (secs > 0 || mins === 0) parts.push(`${secs} sec`)
return parts.join(" ")
}
export function formatSeconds(seconds: number): string {
const mins = Math.floor(seconds / 60)
const secs = seconds % 60
const paddedSecs = secs.toString().padStart(2, '0')
return `${mins}:${paddedSecs}`
}
export function formatCentsToUSD(cents: number): string {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
}).format(cents / 100)
}
export function titleCase(str: string): string {
return str
.split(" ")
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(" ");
}
|