Add layout shells, desktop views, module-level page caches, and UI fixes for auth, home, wallet, transactions, address, and related pages. Co-authored-by: Cursor <cursoragent@cursor.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
const PERSIAN_DIGITS = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'] as const
|
||
|
||
export function toPersianDigits(value: string | number | null | undefined): string {
|
||
if (value === null || value === undefined) return ''
|
||
return String(value).replace(/\d/g, (digit) => PERSIAN_DIGITS[Number(digit)] ?? digit)
|
||
}
|
||
|
||
export function toEnglishDigits(value: string): string {
|
||
return value.replace(/[۰-۹]/g, (digit) => {
|
||
const index = PERSIAN_DIGITS.indexOf(digit as (typeof PERSIAN_DIGITS)[number])
|
||
return index >= 0 ? String(index) : digit
|
||
})
|
||
}
|
||
|
||
export function formatFixed(value: string | number | null | undefined, decimals = 2): string {
|
||
const num = Number(value)
|
||
if (!Number.isFinite(num)) return toPersianDigits(String(value ?? ''))
|
||
return toPersianDigits(num.toFixed(decimals))
|
||
}
|
||
|
||
export function formatPercent(
|
||
value: number,
|
||
decimals = 2,
|
||
options: { showSign?: boolean; suffix?: string } = {},
|
||
): string {
|
||
const { showSign = false, suffix = '%' } = options
|
||
const prefix = showSign && value > 0 ? '+' : value < 0 ? '-' : showSign ? '+' : ''
|
||
return `${prefix}${formatFixed(Math.abs(value), decimals)}${suffix}`
|
||
}
|