@telerik/kendo-intl
Advanced tools
Comparing version 0.12.1 to 0.12.2
import { cldr, getLocaleInfo } from './info'; | ||
import { errors } from '../errors'; | ||
import localeTerritory from './territory'; | ||
import { errors } from '../errors'; | ||
import parseRangeDate from './parse-range-date'; | ||
@@ -9,5 +10,7 @@ var NoCurrency = errors.NoCurrency; | ||
var NoCurrencyRegion = errors.NoCurrencyRegion; | ||
var NoValidCurrency = errors.NoValidCurrency; | ||
var DEFAULT_CURRENCY_FRACTIONS = 2; | ||
var SYMBOL = "symbol"; | ||
var INVALID_CURRENCY_CODE = 'XXX'; | ||
@@ -34,2 +37,34 @@ function getCurrencyInfo(locale, currency) { | ||
function regionCurrency(regionCurrencies) { | ||
var latestValidUntil, latestValidUntilRange; | ||
var latestStillValid, latestStillValidDate; | ||
for (var idx = 0; idx < regionCurrencies.length; idx++) { | ||
var currency = regionCurrencies[idx]; | ||
var code = Object.keys(currency)[0]; | ||
var info = currency[code]; | ||
if (code !== INVALID_CURRENCY_CODE && info._tender !== 'false' && info._from) { | ||
if (!info._to) { | ||
var stillValidDate = parseRangeDate(info._from); | ||
if (!latestStillValidDate || latestStillValidDate < stillValidDate) { | ||
latestStillValid = code; | ||
latestStillValidDate = stillValidDate; | ||
} | ||
} else if (!latestStillValid) { | ||
var validFrom = parseRangeDate(info._from); | ||
var validTo = parseRangeDate(info._to); | ||
if (!latestValidUntilRange || latestValidUntilRange.to < validTo || latestValidUntilRange.from < validFrom) { | ||
latestValidUntil = code; | ||
latestValidUntilRange = { | ||
from: validFrom, | ||
to: validTo | ||
}; | ||
} | ||
} | ||
} | ||
} | ||
return latestStillValid || latestValidUntil; | ||
} | ||
export function currencyDisplays(locale, currency) { | ||
@@ -97,16 +132,26 @@ var currencyInfo = getCurrencyInfo(locale, currency); | ||
var regionCurrencies = currencyData.region[territory]; | ||
if (!regionCurrencies) { | ||
throw NoCurrencyRegion.error(); | ||
throw NoCurrencyRegion.error(territory); | ||
} | ||
var currencyCode = Object.keys(regionCurrencies[regionCurrencies.length - 1])[0]; | ||
var currencyCode = regionCurrency(regionCurrencies); | ||
return currencyCode; | ||
} | ||
export function localeCurrency(locale) { | ||
export function localeCurrency(locale, throwIfNoValid) { | ||
var info = getLocaleInfo(locale); | ||
var numbers = info.numbers; | ||
if (!numbers.localeCurrency) { | ||
numbers.localeCurrency = territoryCurrencyCode(localeTerritory(info)); | ||
var currency = territoryCurrencyCode(localeTerritory(info)); | ||
if (!currency && throwIfNoValid) { | ||
throw NoValidCurrency.error(info.name); | ||
} | ||
numbers.localeCurrency = currency; | ||
} | ||
return numbers.localeCurrency; | ||
@@ -113,0 +158,0 @@ } |
@@ -12,5 +12,6 @@ //The error is represented by unique name and corresponding message | ||
"NoWeekData": "Cannot determine locale first day of week. Please load the supplemental weekData.", | ||
"NoFirstDay": "Cannot determine locale first day of week. Please load the supplemental weekData. The default culture includes only the 'en-US' first day info." | ||
"NoFirstDay": "Cannot determine locale first day of week. Please load the supplemental weekData. The default culture includes only the 'en-US' first day info.", | ||
"NoValidCurrency": "Cannot determine a default currency for the {0} locale. Please specify explicitly the currency with the format options." | ||
}; | ||
//# sourceMappingURL=error-details.js.map |
@@ -7,3 +7,3 @@ import { currencyDisplay, localeCurrency } from '../cldr'; | ||
if (!options.currency) { | ||
options.currency = localeCurrency(info); | ||
options.currency = localeCurrency(info, true); | ||
} | ||
@@ -10,0 +10,0 @@ |
@@ -7,4 +7,2 @@ import { localeInfo, localeCurrency, currencyDisplays } from '../cldr'; | ||
function cleanCurrencyNumber(value, info, format) { | ||
var currency = format.currency || localeCurrency(info); | ||
var displays = currencyDisplays(info, currency); | ||
var isCurrency = format.style === "currency"; | ||
@@ -14,19 +12,23 @@ var number = value; | ||
var currency = format.currency || localeCurrency(info, isCurrency); | ||
for (var idx = 0; idx < displays.length; idx++) { | ||
var display = displays[idx]; | ||
if (number.includes(display)) { | ||
number = number.replace(display, ""); | ||
isCurrency = true; | ||
break; | ||
if (currency) { | ||
var displays = currencyDisplays(info, currency); | ||
for (var idx = 0; idx < displays.length; idx++) { | ||
var display = displays[idx]; | ||
if (number.includes(display)) { | ||
number = number.replace(display, ""); | ||
isCurrency = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (isCurrency) { | ||
var patterns = info.numbers.currency.patterns; | ||
if (patterns.length > 1) { | ||
var parts = (patterns[1] || "").replace("$", "").split("n"); | ||
if (number.indexOf(parts[0]) > -1 && number.indexOf(parts[1]) > -1) { | ||
number = number.replace(parts[0], "").replace(parts[1], ""); | ||
negative = true; | ||
if (isCurrency) { | ||
var patterns = info.numbers.currency.patterns; | ||
if (patterns.length > 1) { | ||
var parts = (patterns[1] || "").replace("$", "").split("n"); | ||
if (number.indexOf(parts[0]) > -1 && number.indexOf(parts[1]) > -1) { | ||
number = number.replace(parts[0], "").replace(parts[1], ""); | ||
negative = true; | ||
} | ||
} | ||
@@ -33,0 +35,0 @@ } |
{ | ||
"name": "@telerik/kendo-intl", | ||
"description": "A package exporting functions for date and number parsing and formatting", | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
544338
81
5388