You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@telerik/kendo-intl

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@telerik/kendo-intl - npm Package Compare versions

Comparing version

to
1.2.2-dev.201709141443

dist/es/numbers/format-options.js

53

dist/es/numbers/format-number.js
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