55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import type { OrgRole } from "@reviq/db-schema";
|
|
import { DurationFormat } from "@formatjs/intl-durationformat";
|
|
|
|
export function buildUrl(
|
|
baseUrl: string,
|
|
path: string,
|
|
params: Record<string, string>,
|
|
): string {
|
|
const url = new URL(path, baseUrl);
|
|
for (const [key, value] of Object.entries(params)) {
|
|
url.searchParams.set(key, value);
|
|
}
|
|
return url.toString();
|
|
}
|
|
|
|
export function escapeHtml(unsafe: string): string {
|
|
return unsafe
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """)
|
|
.replace(/'/g, "'");
|
|
}
|
|
|
|
const durationFormatter = new DurationFormat("en", { style: "long" });
|
|
|
|
export function formatExpiryHours(hours: number): string {
|
|
return durationFormatter.format({ hours });
|
|
}
|
|
|
|
export function formatExpiryMinutes(minutes: number): string {
|
|
return durationFormatter.format({ minutes });
|
|
}
|
|
|
|
export function formatExpiryDays(days: number): string {
|
|
return durationFormatter.format({ days });
|
|
}
|
|
|
|
const roleLabels: Record<OrgRole, string> = {
|
|
owner: "Owner",
|
|
admin: "Admin",
|
|
member: "Member",
|
|
};
|
|
|
|
export function formatRoleDisplay(role: OrgRole): string {
|
|
return roleLabels[role];
|
|
}
|
|
|
|
export function getArticleForRole(role: OrgRole): string {
|
|
if (role === "owner" || role === "admin") {
|
|
return "an";
|
|
}
|
|
return "a";
|
|
}
|