first commit
This commit is contained in:
54
apps/web/src/constants/currencies.ts
Normal file
54
apps/web/src/constants/currencies.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
export const CURRENCIES = [
|
||||
{ code: 'IDR', name: 'Indonesian Rupiah', symbol: 'Rp' },
|
||||
{ code: 'USD', name: 'US Dollar', symbol: '$' },
|
||||
{ code: 'EUR', name: 'Euro', symbol: '€' },
|
||||
{ code: 'GBP', name: 'British Pound', symbol: '£' },
|
||||
{ code: 'JPY', name: 'Japanese Yen', symbol: '¥' },
|
||||
{ code: 'AUD', name: 'Australian Dollar', symbol: 'A$' },
|
||||
{ code: 'CAD', name: 'Canadian Dollar', symbol: 'C$' },
|
||||
{ code: 'CHF', name: 'Swiss Franc', symbol: 'CHF' },
|
||||
{ code: 'CNY', name: 'Chinese Yuan', symbol: '¥' },
|
||||
{ code: 'SGD', name: 'Singapore Dollar', symbol: 'S$' },
|
||||
{ code: 'HKD', name: 'Hong Kong Dollar', symbol: 'HK$' },
|
||||
{ code: 'MYR', name: 'Malaysian Ringgit', symbol: 'RM' },
|
||||
{ code: 'THB', name: 'Thai Baht', symbol: '฿' },
|
||||
{ code: 'KRW', name: 'South Korean Won', symbol: '₩' },
|
||||
{ code: 'INR', name: 'Indian Rupee', symbol: '₹' },
|
||||
{ code: 'PHP', name: 'Philippine Peso', symbol: '₱' },
|
||||
{ code: 'NZD', name: 'New Zealand Dollar', symbol: 'NZ$' },
|
||||
{ code: 'NOK', name: 'Norwegian Krone', symbol: 'kr' },
|
||||
{ code: 'SEK', name: 'Swedish Krona', symbol: 'kr' },
|
||||
{ code: 'DKK', name: 'Danish Krone', symbol: 'kr' },
|
||||
{ code: 'PLN', name: 'Polish Zloty', symbol: 'zł' },
|
||||
{ code: 'CZK', name: 'Czech Koruna', symbol: 'Kč' },
|
||||
{ code: 'HUF', name: 'Hungarian Forint', symbol: 'Ft' },
|
||||
{ code: 'BGN', name: 'Bulgarian Lev', symbol: 'лв' },
|
||||
{ code: 'RON', name: 'Romanian Leu', symbol: 'lei' },
|
||||
{ code: 'HRK', name: 'Croatian Kuna', symbol: 'kn' },
|
||||
{ code: 'RUB', name: 'Russian Ruble', symbol: '₽' },
|
||||
{ code: 'TRY', name: 'Turkish Lira', symbol: '₺' },
|
||||
{ code: 'BRL', name: 'Brazilian Real', symbol: 'R$' },
|
||||
{ code: 'MXN', name: 'Mexican Peso', symbol: '$' },
|
||||
{ code: 'ZAR', name: 'South African Rand', symbol: 'R' },
|
||||
{ code: 'ILS', name: 'Israeli Shekel', symbol: '₪' },
|
||||
{ code: 'ISK', name: 'Icelandic Krona', symbol: 'kr' },
|
||||
] as const;
|
||||
|
||||
export type CurrencyCode = typeof CURRENCIES[number]['code'];
|
||||
|
||||
export const getCurrencyByCode = (code: string) => {
|
||||
return CURRENCIES.find(currency => currency.code === code);
|
||||
};
|
||||
|
||||
export const formatCurrency = (amount: number, currencyCode: string) => {
|
||||
const currency = getCurrencyByCode(currencyCode);
|
||||
if (!currency) return `${amount} ${(amount === 1) ? currencyCode : currencyCode + 's'}`;
|
||||
|
||||
// For IDR, format without decimals
|
||||
if (currencyCode === 'IDR') {
|
||||
return `${currency.symbol} ${amount.toLocaleString('id-ID', { maximumFractionDigits: 0 })}`;
|
||||
}
|
||||
|
||||
// For other currencies, use 2 decimal places
|
||||
return `${currency.symbol} ${amount.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
||||
};
|
||||
Reference in New Issue
Block a user