/ src / lib / util / money.ts
money.ts
 1  import { isEmpty } from "./isEmpty"
 2  
 3  type ConvertToLocaleParams = {
 4    amount: number
 5    currency_code: string
 6    minimumFractionDigits?: number
 7    maximumFractionDigits?: number
 8    locale?: string
 9  }
10  
11  export const convertToLocale = ({
12    amount,
13    currency_code,
14    minimumFractionDigits,
15    maximumFractionDigits,
16    locale = "en-US",
17  }: ConvertToLocaleParams) => {
18    return currency_code && !isEmpty(currency_code)
19      ? new Intl.NumberFormat(locale, {
20          style: "currency",
21          currency: currency_code,
22          minimumFractionDigits,
23          maximumFractionDigits,
24        }).format(amount)
25      : amount.toString()
26  }