29 أسطر
722 B
TypeScript
29 أسطر
722 B
TypeScript
export function formatDateTime(value?: string | null) {
|
|
if (!value) return "-";
|
|
try {
|
|
return new Intl.DateTimeFormat("ar-SA", {
|
|
dateStyle: "medium",
|
|
timeStyle: "short",
|
|
}).format(new Date(value));
|
|
} catch {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
export function formatCurrency(value?: number | null, currency = "SAR") {
|
|
if (typeof value !== "number") return "-";
|
|
try {
|
|
return new Intl.NumberFormat("en-US", {
|
|
style: "currency",
|
|
currency,
|
|
maximumFractionDigits: 0,
|
|
}).format(value);
|
|
} catch {
|
|
return `${value} ${currency}`;
|
|
}
|
|
}
|
|
|
|
export function formatCount(value?: number | null) {
|
|
return typeof value === "number" ? new Intl.NumberFormat("en-US").format(value) : "0";
|
|
}
|