feat: add i18n and avatar upload
This commit is contained in:
@@ -1,21 +1,25 @@
|
||||
export function formatPrice(price: string | null | undefined, currency: string): string | null {
|
||||
export function formatPrice(
|
||||
price: string | null | undefined,
|
||||
currency: string,
|
||||
locale?: string,
|
||||
): string | null {
|
||||
if (!price) return null;
|
||||
const n = Number(price);
|
||||
if (Number.isNaN(n)) return `${price} ${currency}`;
|
||||
try {
|
||||
return new Intl.NumberFormat(undefined, {
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(n);
|
||||
} catch {
|
||||
return `${n.toLocaleString()} ${currency}`;
|
||||
return `${n.toLocaleString(locale)} ${currency}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatDate(iso: string | Date): string {
|
||||
export function formatDate(iso: string | Date, locale?: string): string {
|
||||
const d = typeof iso === 'string' ? new Date(iso) : iso;
|
||||
return d.toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' });
|
||||
return d.toLocaleDateString(locale, { day: 'numeric', month: 'short', year: 'numeric' });
|
||||
}
|
||||
|
||||
export function daysLeftUntil(iso: string | Date, retentionDays: number): number {
|
||||
|
||||
Reference in New Issue
Block a user