@skyux/core 8.0.0-alpha.10 → 8.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fesm2020/skyux-core.mjs
CHANGED
@@ -1942,9 +1942,17 @@ class SkyNumericService {
|
|
1942
1942
|
if (isNaN(value) || value === null) {
|
1943
1943
|
return '';
|
1944
1944
|
}
|
1945
|
+
const numericOptions = {
|
1946
|
+
digits: 0,
|
1947
|
+
format: 'number',
|
1948
|
+
currencySign: 'standard',
|
1949
|
+
iso: 'USD',
|
1950
|
+
truncateAfter: 1000,
|
1951
|
+
...options,
|
1952
|
+
};
|
1945
1953
|
const decimalPlaceRegExp = /\.0+$|(\.[0-9]*[1-9])0+$/;
|
1946
|
-
const locale =
|
1947
|
-
const digits =
|
1954
|
+
const locale = numericOptions.locale || this.currentLocale;
|
1955
|
+
const digits = numericOptions.digits || 0;
|
1948
1956
|
// Get the symbol for the number after rounding, since rounding could push the number
|
1949
1957
|
// into a different symbol range.
|
1950
1958
|
let roundedNumber = __classPrivateFieldGet(this, _SkyNumericService_instances, "m", _SkyNumericService_roundNumber).call(this, value, digits);
|
@@ -1952,9 +1960,9 @@ class SkyNumericService {
|
|
1952
1960
|
let suffix = '';
|
1953
1961
|
for (let i = 0; i < __classPrivateFieldGet(this, _SkyNumericService_symbolIndex, "f").length; i++) {
|
1954
1962
|
let symbol = __classPrivateFieldGet(this, _SkyNumericService_symbolIndex, "f")[i];
|
1955
|
-
if (
|
1956
|
-
|
1957
|
-
roundedNumberAbs >=
|
1963
|
+
if (numericOptions.truncate &&
|
1964
|
+
numericOptions.truncateAfter !== undefined &&
|
1965
|
+
roundedNumberAbs >= numericOptions.truncateAfter &&
|
1958
1966
|
roundedNumberAbs >= symbol.value) {
|
1959
1967
|
roundedNumber = __classPrivateFieldGet(this, _SkyNumericService_instances, "m", _SkyNumericService_roundNumber).call(this, value / symbol.value, digits);
|
1960
1968
|
if (Math.abs(roundedNumber) === 1000 && i > 0) {
|
@@ -1971,7 +1979,7 @@ class SkyNumericService {
|
|
1971
1979
|
let digitsFormatted;
|
1972
1980
|
let isDecimal = false;
|
1973
1981
|
// Checks the string entered for format. Using toLowerCase to ignore case.
|
1974
|
-
switch (
|
1982
|
+
switch (numericOptions.format?.toLowerCase()) {
|
1975
1983
|
// In a case where a decimal value was not shortened and
|
1976
1984
|
// the digit input is 2 or higher, it forces 2 digits.
|
1977
1985
|
// For example, this prevents a value like $15.50 from displaying as $15.5.
|
@@ -1979,8 +1987,8 @@ class SkyNumericService {
|
|
1979
1987
|
// three decimal digits.
|
1980
1988
|
case 'currency':
|
1981
1989
|
isDecimal = value % 1 !== 0;
|
1982
|
-
if (
|
1983
|
-
digitsFormatted = `1.${
|
1990
|
+
if (numericOptions.minDigits) {
|
1991
|
+
digitsFormatted = `1.${numericOptions.minDigits}-${digits}`;
|
1984
1992
|
}
|
1985
1993
|
else if (isDecimal && digits >= 2) {
|
1986
1994
|
digitsFormatted = `1.2-${digits}`;
|
@@ -1988,12 +1996,12 @@ class SkyNumericService {
|
|
1988
1996
|
else {
|
1989
1997
|
digitsFormatted = `1.0-${digits}`;
|
1990
1998
|
}
|
1991
|
-
output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), SkyIntlNumberFormatStyle.Currency, digitsFormatted,
|
1999
|
+
output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), SkyIntlNumberFormatStyle.Currency, digitsFormatted, numericOptions.iso,
|
1992
2000
|
// Angular 5+ needs a string for this parameter, but Angular 4 needs a boolean.
|
1993
2001
|
// To support both versions we can supply 'symbol' which will evaluate truthy for Angular 4
|
1994
2002
|
// and the appropriate string value for Angular 5+.
|
1995
2003
|
// See: https://angular.io/api/common/CurrencyPipe#parameters
|
1996
|
-
'symbol',
|
2004
|
+
'symbol', numericOptions.currencySign);
|
1997
2005
|
// ^^^^^^ Result can't be null since the sanitized input is always a number.
|
1998
2006
|
break;
|
1999
2007
|
// The following is a catch-all to ensure that if
|
@@ -2002,10 +2010,10 @@ class SkyNumericService {
|
|
2002
2010
|
default:
|
2003
2011
|
// Ensures localization of the number to ensure comma and
|
2004
2012
|
// decimal separator
|
2005
|
-
if (
|
2006
|
-
digitsFormatted = `1.${
|
2013
|
+
if (numericOptions.minDigits) {
|
2014
|
+
digitsFormatted = `1.${numericOptions.minDigits}-${digits}`;
|
2007
2015
|
}
|
2008
|
-
else if (
|
2016
|
+
else if (numericOptions.truncate) {
|
2009
2017
|
digitsFormatted = `1.0-${digits}`;
|
2010
2018
|
}
|
2011
2019
|
else {
|
@@ -2015,7 +2023,7 @@ class SkyNumericService {
|
|
2015
2023
|
// ^^^^^^ Result can't be null since the sanitized input is always a number.
|
2016
2024
|
break;
|
2017
2025
|
}
|
2018
|
-
if (
|
2026
|
+
if (numericOptions.truncate) {
|
2019
2027
|
output = __classPrivateFieldGet(this, _SkyNumericService_instances, "m", _SkyNumericService_replaceShortenSymbol).call(this, output);
|
2020
2028
|
}
|
2021
2029
|
return output;
|