File size: 1,320 Bytes
1a3a0b4 20f3b43 1a3a0b4 20f3b43 1a3a0b4 20f3b43 1a3a0b4 20f3b43 1a3a0b4 20f3b43 1a3a0b4 20f3b43 1a3a0b4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import { ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export type MarketType = 'bist' | 'us'
function localeFor(market: MarketType = 'bist') {
return market === 'us' ? 'en-US' : 'tr-TR'
}
function currencyFor(market: MarketType = 'bist') {
return market === 'us' ? 'USD' : 'TRY'
}
export function formatCurrency(value: number, market: MarketType = 'bist'): string {
return new Intl.NumberFormat(localeFor(market), {
style: 'currency',
currency: currencyFor(market),
minimumFractionDigits: 2,
}).format(value)
}
export function formatPercent(value: number, market: MarketType = 'bist'): string {
return new Intl.NumberFormat(localeFor(market), {
style: 'percent',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(value / 100)
}
export function formatNumber(value: number, market: MarketType = 'bist'): string {
return new Intl.NumberFormat(localeFor(market)).format(value)
}
export function formatDate(date: string | Date, market: MarketType = 'bist'): string {
const dateObj = typeof date === 'string' ? new Date(date) : date
return dateObj.toLocaleDateString(localeFor(market), {
day: '2-digit',
month: '2-digit',
year: 'numeric',
})
}
|