Files
pargar/frontend/src/lib/utils.ts
T
ahp 22d92c133d feat: release v0.2.0 profiles, chat, freeze, and bots
Ship the product pass on the v0.1.3 schema with additive migrations, a replica migration lock, and bot accounts kept out of people lists.
2026-10-10 16:42:35 +03:30

41 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatWinHWin(v: number, digits = 0) {
return new Intl.NumberFormat("fa-IR", { maximumFractionDigits: digits }).format(v);
}
export function formatFaNumber(value: number, digits = 0) {
return new Intl.NumberFormat("fa-IR", { maximumFractionDigits: digits }).format(value);
}
/** Streak label — never use a hyphen (۰-روزه looks like a negative). */
export function formatStreakLabel(days: number) {
const n = Number.isFinite(days) ? Math.max(0, Math.floor(days)) : 0;
return `${formatFaNumber(n)} روز`;
}
/** Quiz option letters: الف، ب، ج، د، … */
const FA_OPTION_LETTERS = ["الف", "ب", "ج", "د", "ه", "و"] as const;
/** Jalali day plus clock, for conversation rows. */
export function formatJalaliStamp(iso: string): string {
const d = new Date(iso);
if (Number.isNaN(d.getTime())) {
return "";
}
const day = new Intl.DateTimeFormat("fa-IR", { day: "numeric", month: "short" }).format(d);
const time = new Intl.DateTimeFormat("fa-IR", { hour: "2-digit", minute: "2-digit" }).format(d);
return `${day} · ${time}`;
}
export function formatOptionLetter(index: number): string {
if (index >= 0 && index < FA_OPTION_LETTERS.length) {
return FA_OPTION_LETTERS[index];
}
return formatFaNumber(index + 1);
}