-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
30 lines (26 loc) · 827 Bytes
/
utils.ts
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
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { formatDistanceToNowStrict } from "date-fns";
import { User } from "@clerk/nextjs/server";
import { UserResource } from "@clerk/types";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatCurrency(amount: number, currency = "USD") {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(amount);
}
export function formatDate(from: Date) {
return formatDistanceToNowStrict(from, { addSuffix: true });
}
export function toSlug(str: string) {
return str
.toLowerCase()
.replace(/ /g, "-")
.replace(/[^\w-]+/g, "");
}
export function isAdmin(user: UserResource | User) {
return user.publicMetadata?.role === "admin";
}