/** * @example * numberFormat(1234); * // Returns '1,234' * * @example * numberFormat(1234, "usd"); * // Returns '$1,234.00' */ export default function numberFormat( input: number | bigint | string, locales: string | string[] | undefined = "en-us", options: Intl.NumberFormatOptions | undefined = undefined ) { let number: number | bigint; if (typeof input === "string") { number = parseFloat(input); } else { number = input; } if (locales === "usd" && options === undefined) { locales = "en-us"; options = { style: "currency", currency: "USD", }; } return new Intl.NumberFormat(locales, options).format(number); }