* fix(currency): symbol fallback

* test(currency): add case for lang/locale pair without explicit symbol
This commit is contained in:
Kiril Peyanski 2024-01-08 09:24:19 +02:00 коммит произвёл GitHub
Родитель 64db9ef9f7
Коммит d2286da466
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -112,7 +112,7 @@ export function currencyDisplay(locale, options) {
let result;
if (currencyDisplay === SYMBOL) {
result = currencyInfo["symbol-alt-narrow"] || currencyInfo[SYMBOL];
result = currencyInfo["symbol-alt-narrow"] || currencyInfo[SYMBOL] || currency;
} else {
if (typeof value === "undefined" || value !== 1) {
result = currencyInfo["displayName-count-other"];

Просмотреть файл

@ -6,7 +6,10 @@ const numbers = require("cldr-numbers-full/main/bg/numbers.json");
const currencies = require("cldr-numbers-full/main/bg/currencies.json");
const currencyData = require("cldr-core/supplemental/currencyData.json");
load(likelySubtags, currencyData, numbers, currencies);
const localNumbers = require("cldr-numbers-full/main/de-CH/numbers.json");
const localCurrencies = require("cldr-numbers-full/main/de-CH/currencies.json");
load(likelySubtags, currencyData, numbers, currencies, localNumbers, localCurrencies);
function loadCustom(options) {
load({
@ -300,6 +303,10 @@ describe('standard currency formatting', () => {
expect(formatNumber(10, "c", "bg-BG")).toEqual("10,00 лв.");
});
it("should apply format when passing language and territory without symbol", () => {
expect(formatNumber(10, "c", "de-CH")).toEqual("CHF 10.00");
});
it("should apply format when passing object", () => {
expect(formatNumber(10, { style: "currency" })).toEqual("$10.00");
});