| 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', |
| }) |
| } |
|
|