@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
27 lines (25 loc) • 932 B
JavaScript
import { CachedIntl } from "../utils/intl.mjs";
import configuration from "@intlayer/config/built";
//#region src/formatters/currency.ts
/**
* Formats a numeric or string value into a localized currency string using the Intl API.
*
* @example
* currency({ value: 1234.5, currency: 'EUR' });
* // "€1,234.50"
*
* @example
* currency({ value: "5000", locale: Locales.FRENCH, currency: "CAD", currencyDisplay: "code" });
* // "5 000,00 CAD"
*/
const currency = (value, options) => new CachedIntl.NumberFormat(options?.locale ?? configuration?.internationalization?.defaultLocale, {
style: "currency",
currency: options?.currency ?? "USD",
currencyDisplay: options?.currencyDisplay ?? "symbol",
minimumFractionDigits: options?.minimumFractionDigits ?? 2,
maximumFractionDigits: options?.maximumFractionDigits ?? 2,
...options
}).format(Number(value));
//#endregion
export { currency };
//# sourceMappingURL=currency.mjs.map