/**
 * A formatter to format to double decimal
 */
// Formats numbers as currency
export const currencyNumberFormatter = new Intl.NumberFormat("pt-BR", {
    minimumFractionDigits: 2,
    maximumFractionDigits: 2,
}).format;
/**
 * Instanciate a currency formatter
 */
// Creates a currency formatter for a specific language
export const currencyFormatterFactory = (langCode, currency) => {
    try {
        return new Intl.NumberFormat(langCode, {
            style: "currency",
            currency: currency,
        });
    }
    catch (e) {
        const f = new Intl.NumberFormat(langCode, {
            minimumFractionDigits: 2,
            maximumFractionDigits: 2,
        });
        return {
            format: (num) => `${currency} ${currencyNumberFormatter(num)}`,
            formatToParts: (num) => [
                { type: "currency", value: currency },
                { type: "literal", value: " " },
                ...f.formatToParts(num),
            ],
        };
    }
};
// Creates a decimal formatter for a specific language
export const decimalFormatterFactory = (langCode) => {
    try {
        return new Intl.NumberFormat(langCode, {
            style: "decimal",
        });
    }
    catch (e) {
        const f = new Intl.NumberFormat(langCode, {
            minimumFractionDigits: 2,
            maximumFractionDigits: 2,
        });
        return {
            format: (num) => `${currencyNumberFormatter(num)}`,
            formatToParts: (num) => [...f.formatToParts(num)],
        };
    }
};
//# sourceMappingURL=formatters.js.map