intl-number-input
Advanced tools
Comparing version 1.1.0 to 1.1.1
/** | ||
* Intl Number Input 1.1.0 | ||
* Intl Number Input 1.1.1 | ||
* (c) 2021 Matthias Stiller | ||
@@ -92,7 +92,9 @@ * @license MIT | ||
if (match && this.isValidIntegerFormat(this.decimalSymbol ? str.split(this.decimalSymbol)[0] : str, Number(match[1]))) { | ||
let number = Number(`${negative ? '-' : ''}${this.onlyDigits(match[1])}.${this.onlyDigits(match[2] || '')}`); | ||
const number = Number(`${negative ? '-' : ''}${this.onlyDigits(match[1])}.${this.onlyDigits(match[2] || '')}`); | ||
if (this.style === exports.NumberFormatStyle.Percent) { | ||
number /= 100; | ||
return Number((number / 100).toFixed(this.maximumFractionDigits + 2)); | ||
} | ||
return number; | ||
else { | ||
return number; | ||
} | ||
} | ||
@@ -225,3 +227,3 @@ } | ||
} | ||
class AutoDecimalModeNumberMask extends AbstractNumberMask { | ||
class AutoDecimalDigitsNumberMask extends AbstractNumberMask { | ||
conformToMask(str, previousConformedValue = '') { | ||
@@ -236,6 +238,6 @@ if (str === '' || | ||
? -0 | ||
: Number(`${negative ? '-' : ''}${removeLeadingZeros(this.numberFormat.onlyDigits(str))}`) / Math.pow(10, this.numberFormat.minimumFractionDigits); | ||
: Number(`${negative ? '-' : ''}${removeLeadingZeros(this.numberFormat.onlyDigits(str))}`) / Math.pow(10, this.numberFormat.maximumFractionDigits); | ||
return { | ||
numberValue, | ||
fractionDigits: numberValue.toFixed(this.numberFormat.minimumFractionDigits).slice(-this.numberFormat.minimumFractionDigits) | ||
fractionDigits: numberValue.toFixed(this.numberFormat.maximumFractionDigits).slice(-this.numberFormat.maximumFractionDigits) | ||
}; | ||
@@ -292,3 +294,3 @@ } | ||
this.numberFormat = new NumberFormat(this.options); | ||
this.numberMask = this.options.autoDecimalDigits ? new AutoDecimalModeNumberMask(this.numberFormat) : new DefaultNumberMask(this.numberFormat); | ||
this.numberMask = this.options.autoDecimalDigits ? new AutoDecimalDigitsNumberMask(this.numberFormat) : new DefaultNumberMask(this.numberFormat); | ||
this.step = options.step && options.step > 0 ? Math.max(options.step, this.toFloat(1)) : this.toFloat(1); | ||
@@ -295,0 +297,0 @@ this.minValue = this.getMinValue(); |
@@ -0,0 +0,0 @@ interface NumberInputConstructorArgs { |
/** | ||
* Intl Number Input 1.1.0 | ||
* Intl Number Input 1.1.1 | ||
* (c) 2021 Matthias Stiller | ||
@@ -88,7 +88,9 @@ * @license MIT | ||
if (match && this.isValidIntegerFormat(this.decimalSymbol ? str.split(this.decimalSymbol)[0] : str, Number(match[1]))) { | ||
let number = Number(`${negative ? '-' : ''}${this.onlyDigits(match[1])}.${this.onlyDigits(match[2] || '')}`); | ||
const number = Number(`${negative ? '-' : ''}${this.onlyDigits(match[1])}.${this.onlyDigits(match[2] || '')}`); | ||
if (this.style === NumberFormatStyle.Percent) { | ||
number /= 100; | ||
return Number((number / 100).toFixed(this.maximumFractionDigits + 2)); | ||
} | ||
return number; | ||
else { | ||
return number; | ||
} | ||
} | ||
@@ -221,3 +223,3 @@ } | ||
} | ||
class AutoDecimalModeNumberMask extends AbstractNumberMask { | ||
class AutoDecimalDigitsNumberMask extends AbstractNumberMask { | ||
conformToMask(str, previousConformedValue = '') { | ||
@@ -232,6 +234,6 @@ if (str === '' || | ||
? -0 | ||
: Number(`${negative ? '-' : ''}${removeLeadingZeros(this.numberFormat.onlyDigits(str))}`) / Math.pow(10, this.numberFormat.minimumFractionDigits); | ||
: Number(`${negative ? '-' : ''}${removeLeadingZeros(this.numberFormat.onlyDigits(str))}`) / Math.pow(10, this.numberFormat.maximumFractionDigits); | ||
return { | ||
numberValue, | ||
fractionDigits: numberValue.toFixed(this.numberFormat.minimumFractionDigits).slice(-this.numberFormat.minimumFractionDigits) | ||
fractionDigits: numberValue.toFixed(this.numberFormat.maximumFractionDigits).slice(-this.numberFormat.maximumFractionDigits) | ||
}; | ||
@@ -288,3 +290,3 @@ } | ||
this.numberFormat = new NumberFormat(this.options); | ||
this.numberMask = this.options.autoDecimalDigits ? new AutoDecimalModeNumberMask(this.numberFormat) : new DefaultNumberMask(this.numberFormat); | ||
this.numberMask = this.options.autoDecimalDigits ? new AutoDecimalDigitsNumberMask(this.numberFormat) : new DefaultNumberMask(this.numberFormat); | ||
this.step = options.step && options.step > 0 ? Math.max(options.step, this.toFloat(1)) : this.toFloat(1); | ||
@@ -291,0 +293,0 @@ this.minValue = this.getMinValue(); |
{ | ||
"name": "intl-number-input", | ||
"description": "Easy input of formatted numbers based on the ECMAScript Internationalization API (ECMA-402).", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "module": "./dist/index.esm.js", |
1045
51327
6