27 lines
618 B
TypeScript
27 lines
618 B
TypeScript
import { isEmpty } from "./isEmpty"
|
|
|
|
type ConvertToLocaleParams = {
|
|
amount: number
|
|
currency_code: string
|
|
minimumFractionDigits?: number
|
|
maximumFractionDigits?: number
|
|
locale?: string
|
|
}
|
|
|
|
export const convertToLocale = ({
|
|
amount,
|
|
currency_code,
|
|
minimumFractionDigits,
|
|
maximumFractionDigits,
|
|
locale = "en-US",
|
|
}: ConvertToLocaleParams) => {
|
|
return currency_code && !isEmpty(currency_code)
|
|
? new Intl.NumberFormat(locale, {
|
|
style: "currency",
|
|
currency: currency_code,
|
|
minimumFractionDigits,
|
|
maximumFractionDigits,
|
|
}).format(amount)
|
|
: amount.toString()
|
|
}
|