@telerik/kendo-intl
Advanced tools
Comparing version 1.2.1 to 1.2.2-dev.201709141443
import { localeInfo } from '../cldr'; | ||
import { CURRENCY, ACCOUNTING, DECIMAL, PERCENT, SCIENTIFIC, DEFAULT_LOCALE, NUMBER_PLACEHOLDER, EMPTY } from '../common/constants'; | ||
import isString from '../common/is-string'; | ||
import { DECIMAL, DEFAULT_LOCALE, NUMBER_PLACEHOLDER, EMPTY } from '../common/constants'; | ||
import standardNumberFormat from './standard-number-format'; | ||
import customNumberFormat from './custom-number-format'; | ||
import formatOptions from './format-options'; | ||
var standardFormatRegExp = /^(n|c|p|e|a)(\d*)$/i; | ||
function standardFormatOptions(format) { | ||
var formatAndPrecision = standardFormatRegExp.exec(format); | ||
if (formatAndPrecision) { | ||
var options = { | ||
style: DECIMAL | ||
}; | ||
var style = formatAndPrecision[1].toLowerCase(); | ||
if (style === "c") { | ||
options.style = CURRENCY; | ||
} else if (style === "a") { | ||
options.style = ACCOUNTING; | ||
} else if (style === "p") { | ||
options.style = PERCENT; | ||
} else if (style === "e") { | ||
options.style = SCIENTIFIC; | ||
} | ||
if (formatAndPrecision[2]) { | ||
options.minimumFractionDigits = options.maximumFractionDigits = parseInt(formatAndPrecision[2], 10); | ||
} | ||
return options; | ||
} | ||
} | ||
function getFormatOptions(format) { | ||
var formatOptions; | ||
if (isString(format)) { | ||
formatOptions = standardFormatOptions(format); | ||
} else { | ||
formatOptions = format; | ||
} | ||
return formatOptions; | ||
} | ||
export default function formatNumber(number, format, locale) { | ||
@@ -61,8 +20,8 @@ if ( format === void 0 ) format = NUMBER_PLACEHOLDER; | ||
var info = localeInfo(locale); | ||
var formatOptions = getFormatOptions(format); | ||
var options = formatOptions(format); | ||
var result; | ||
if (formatOptions) { | ||
var style = (formatOptions || {}).style || DECIMAL; | ||
result = standardNumberFormat(number, Object.assign({}, info.numbers[style], formatOptions), info); | ||
if (options) { | ||
var style = (options || {}).style || DECIMAL; | ||
result = standardNumberFormat(number, Object.assign({}, info.numbers[style], options), info); | ||
} else { | ||
@@ -69,0 +28,0 @@ result = customNumberFormat(number, format, info); |
@@ -5,2 +5,3 @@ import { localeInfo, localeCurrency, currencyDisplays } from '../cldr'; | ||
import isCurrencyStyle from './is-currency-style'; | ||
import formatOptions from './format-options'; | ||
@@ -10,8 +11,18 @@ var exponentRegExp = /[eE][\-+]?[0-9]+/; | ||
function cleanNegativePattern(number, patterns) { | ||
if (patterns.length > 1) { | ||
var parts = (patterns[1] || EMPTY).replace(CURRENCY_PLACEHOLDER, EMPTY).split(NUMBER_PLACEHOLDER); | ||
if (number.indexOf(parts[0]) > -1 && number.indexOf(parts[1]) > -1) { | ||
return number.replace(parts[0], EMPTY).replace(parts[1], EMPTY); | ||
} | ||
} | ||
} | ||
function cleanCurrencyNumber(value, info, format) { | ||
var isCurrency = isCurrencyStyle(format.style); | ||
var options = formatOptions(format) || {}; | ||
var isCurrency = isCurrencyStyle(options.style); | ||
var number = value; | ||
var negative; | ||
var currency = format.currency || localeCurrency(info, isCurrency); | ||
var currency = options.currency || localeCurrency(info, isCurrency); | ||
@@ -32,10 +43,10 @@ if (currency) { | ||
if (isCurrency) { | ||
var patterns = info.numbers.currency.patterns; | ||
if (patterns.length > 1) { | ||
var parts = (patterns[1] || EMPTY).replace(CURRENCY_PLACEHOLDER, EMPTY).split(NUMBER_PLACEHOLDER); | ||
if (number.indexOf(parts[0]) > -1 && number.indexOf(parts[1]) > -1) { | ||
number = number.replace(parts[0], EMPTY).replace(parts[1], EMPTY); | ||
negative = true; | ||
} | ||
var cleanNumber = cleanNegativePattern(number, info.numbers.currency.patterns) || | ||
cleanNegativePattern(number, info.numbers.accounting.patterns); | ||
if (cleanNumber) { | ||
negative = true; | ||
number = cleanNumber; | ||
} | ||
} | ||
@@ -42,0 +53,0 @@ } |
{ | ||
"name": "@telerik/kendo-intl", | ||
"description": "A package exporting functions for date and number parsing and formatting", | ||
"version": "1.2.1", | ||
"version": "1.2.2-dev.201709141443", | ||
"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 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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
605379
101
6033
2