mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-14 03:02:15 +01:00
add frontend format support for currencies, add currencies endpoint
This commit is contained in:
@@ -1,12 +1,52 @@
|
||||
function formatMoney(amount: number, currency: string) {
|
||||
return new Intl.NumberFormat('de-DE', {
|
||||
style: 'currency',
|
||||
currency: currency,
|
||||
}).format(amount);
|
||||
import { formatNumber, type NumberFormat } from './number';
|
||||
|
||||
export type CurrencyFormat =
|
||||
| 'iso-code-before-with-space'
|
||||
| 'iso-code-after-with-space'
|
||||
| 'symbol-before'
|
||||
| 'symbol-after'
|
||||
| 'symbol-before-with-space'
|
||||
| 'symbol-after-with-space';
|
||||
|
||||
function formatMoney(
|
||||
amount: number,
|
||||
currency?: string,
|
||||
format?: CurrencyFormat,
|
||||
currencySymbol?: string,
|
||||
numberFormat?: NumberFormat
|
||||
) {
|
||||
const formattedAmount = formatNumber(amount, numberFormat);
|
||||
|
||||
switch (format) {
|
||||
case 'iso-code-before-with-space':
|
||||
return `${currency} ${formattedAmount}`;
|
||||
case 'iso-code-after-with-space':
|
||||
return `${formattedAmount} ${currency}`;
|
||||
case 'symbol-before':
|
||||
return `${currencySymbol}${formattedAmount}`;
|
||||
case 'symbol-after':
|
||||
return `${formattedAmount}${currencySymbol}`;
|
||||
case 'symbol-before-with-space':
|
||||
return `${currencySymbol} ${formattedAmount}`;
|
||||
case 'symbol-after-with-space':
|
||||
return `${formattedAmount} ${currencySymbol}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatCents(amount: number, currency: string) {
|
||||
return formatMoney(amount / 100, currency);
|
||||
export function formatCents(
|
||||
amount: number,
|
||||
currency?: string,
|
||||
format?: CurrencyFormat,
|
||||
currencySymbol?: string,
|
||||
numberFormat?: NumberFormat
|
||||
) {
|
||||
return formatMoney(
|
||||
amount / 100,
|
||||
currency,
|
||||
format,
|
||||
currencySymbol,
|
||||
numberFormat
|
||||
);
|
||||
}
|
||||
|
||||
export function getOrganizationCurrencySymbol(currency: string) {
|
||||
|
||||
Reference in New Issue
Block a user