@formatjs/ecma402-abstract 1.17.2 → 1.17.3
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/NumberFormat/InitializeNumberFormat.d.ts +1 -1
- package/NumberFormat/InitializeNumberFormat.js +7 -7
- package/SupportedLocales.js +3 -3
- package/lib/262.js +49 -23
- package/lib/CanonicalizeLocaleList.js +5 -1
- package/lib/CanonicalizeTimeZoneName.js +5 -1
- package/lib/CoerceOptionsToObject.js +7 -3
- package/lib/DefaultNumberOption.js +5 -1
- package/lib/GetNumberOption.js +7 -3
- package/lib/GetOption.js +7 -3
- package/lib/GetOptionsObject.js +5 -1
- package/lib/GetStringOrBooleanOption.js +7 -3
- package/lib/IsSanctionedSimpleUnitIdentifier.js +10 -5
- package/lib/IsValidTimeZoneName.js +5 -1
- package/lib/IsWellFormedCurrencyCode.js +5 -1
- package/lib/IsWellFormedUnitIdentifier.js +9 -5
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +5 -1
- package/lib/NumberFormat/CollapseNumberRange.js +5 -1
- package/lib/NumberFormat/ComputeExponent.js +13 -9
- package/lib/NumberFormat/ComputeExponentForMagnitude.js +5 -1
- package/lib/NumberFormat/CurrencyDigits.js +7 -3
- package/lib/NumberFormat/FormatApproximately.js +5 -1
- package/lib/NumberFormat/FormatNumericRange.js +7 -3
- package/lib/NumberFormat/FormatNumericRangeToParts.js +7 -3
- package/lib/NumberFormat/FormatNumericToParts.js +9 -5
- package/lib/NumberFormat/FormatNumericToString.js +15 -11
- package/lib/NumberFormat/GetUnsignedRoundingMode.js +5 -1
- package/lib/NumberFormat/InitializeNumberFormat.d.ts +1 -1
- package/lib/NumberFormat/InitializeNumberFormat.js +31 -27
- package/lib/NumberFormat/PartitionNumberPattern.js +16 -11
- package/lib/NumberFormat/PartitionNumberRangePattern.js +12 -8
- package/lib/NumberFormat/SetNumberFormatDigitOptions.js +14 -10
- package/lib/NumberFormat/SetNumberFormatUnitOptions.js +16 -12
- package/lib/NumberFormat/ToRawFixed.js +8 -4
- package/lib/NumberFormat/ToRawPrecision.js +11 -7
- package/lib/NumberFormat/digit-mapping.generated.js +4 -1
- package/lib/NumberFormat/format_to_parts.js +11 -8
- package/lib/PartitionPattern.js +7 -3
- package/lib/SupportedLocales.js +12 -8
- package/lib/data.js +7 -3
- package/lib/index.js +56 -42
- package/lib/regex.generated.js +4 -1
- package/lib/types/core.js +2 -1
- package/lib/types/date-time.js +5 -2
- package/lib/types/displaynames.js +2 -1
- package/lib/types/list.js +2 -1
- package/lib/types/number.js +2 -1
- package/lib/types/plural-rules.js +2 -1
- package/lib/types/relative-time.js +2 -1
- package/lib/utils.js +22 -10
- package/package.json +3 -3
- package/types/date-time.js +1 -1
- package/262.d.ts.map +0 -1
- package/CanonicalizeLocaleList.d.ts.map +0 -1
- package/CanonicalizeTimeZoneName.d.ts.map +0 -1
- package/CoerceOptionsToObject.d.ts.map +0 -1
- package/DefaultNumberOption.d.ts.map +0 -1
- package/GetNumberOption.d.ts.map +0 -1
- package/GetOption.d.ts.map +0 -1
- package/GetOptionsObject.d.ts.map +0 -1
- package/GetStringOrBooleanOption.d.ts.map +0 -1
- package/IsSanctionedSimpleUnitIdentifier.d.ts.map +0 -1
- package/IsValidTimeZoneName.d.ts.map +0 -1
- package/IsWellFormedCurrencyCode.d.ts.map +0 -1
- package/IsWellFormedUnitIdentifier.d.ts.map +0 -1
- package/NumberFormat/ApplyUnsignedRoundingMode.d.ts.map +0 -1
- package/NumberFormat/CollapseNumberRange.d.ts.map +0 -1
- package/NumberFormat/ComputeExponent.d.ts.map +0 -1
- package/NumberFormat/ComputeExponentForMagnitude.d.ts.map +0 -1
- package/NumberFormat/CurrencyDigits.d.ts.map +0 -1
- package/NumberFormat/FormatApproximately.d.ts.map +0 -1
- package/NumberFormat/FormatNumericRange.d.ts.map +0 -1
- package/NumberFormat/FormatNumericRangeToParts.d.ts.map +0 -1
- package/NumberFormat/FormatNumericToParts.d.ts.map +0 -1
- package/NumberFormat/FormatNumericToString.d.ts.map +0 -1
- package/NumberFormat/GetUnsignedRoundingMode.d.ts.map +0 -1
- package/NumberFormat/InitializeNumberFormat.d.ts.map +0 -1
- package/NumberFormat/PartitionNumberPattern.d.ts.map +0 -1
- package/NumberFormat/PartitionNumberRangePattern.d.ts.map +0 -1
- package/NumberFormat/SetNumberFormatDigitOptions.d.ts.map +0 -1
- package/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +0 -1
- package/NumberFormat/ToRawFixed.d.ts.map +0 -1
- package/NumberFormat/ToRawPrecision.d.ts.map +0 -1
- package/NumberFormat/digit-mapping.generated.d.ts.map +0 -1
- package/NumberFormat/format_to_parts.d.ts.map +0 -1
- package/PartitionPattern.d.ts.map +0 -1
- package/SupportedLocales.d.ts.map +0 -1
- package/data.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/lib/262.d.ts.map +0 -1
- package/lib/CanonicalizeLocaleList.d.ts.map +0 -1
- package/lib/CanonicalizeTimeZoneName.d.ts.map +0 -1
- package/lib/CoerceOptionsToObject.d.ts.map +0 -1
- package/lib/DefaultNumberOption.d.ts.map +0 -1
- package/lib/GetNumberOption.d.ts.map +0 -1
- package/lib/GetOption.d.ts.map +0 -1
- package/lib/GetOptionsObject.d.ts.map +0 -1
- package/lib/GetStringOrBooleanOption.d.ts.map +0 -1
- package/lib/IsSanctionedSimpleUnitIdentifier.d.ts.map +0 -1
- package/lib/IsValidTimeZoneName.d.ts.map +0 -1
- package/lib/IsWellFormedCurrencyCode.d.ts.map +0 -1
- package/lib/IsWellFormedUnitIdentifier.d.ts.map +0 -1
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.d.ts.map +0 -1
- package/lib/NumberFormat/CollapseNumberRange.d.ts.map +0 -1
- package/lib/NumberFormat/ComputeExponent.d.ts.map +0 -1
- package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts.map +0 -1
- package/lib/NumberFormat/CurrencyDigits.d.ts.map +0 -1
- package/lib/NumberFormat/FormatApproximately.d.ts.map +0 -1
- package/lib/NumberFormat/FormatNumericRange.d.ts.map +0 -1
- package/lib/NumberFormat/FormatNumericRangeToParts.d.ts.map +0 -1
- package/lib/NumberFormat/FormatNumericToParts.d.ts.map +0 -1
- package/lib/NumberFormat/FormatNumericToString.d.ts.map +0 -1
- package/lib/NumberFormat/GetUnsignedRoundingMode.d.ts.map +0 -1
- package/lib/NumberFormat/InitializeNumberFormat.d.ts.map +0 -1
- package/lib/NumberFormat/PartitionNumberPattern.d.ts.map +0 -1
- package/lib/NumberFormat/PartitionNumberRangePattern.d.ts.map +0 -1
- package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts.map +0 -1
- package/lib/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +0 -1
- package/lib/NumberFormat/ToRawFixed.d.ts.map +0 -1
- package/lib/NumberFormat/ToRawPrecision.d.ts.map +0 -1
- package/lib/NumberFormat/digit-mapping.generated.d.ts.map +0 -1
- package/lib/NumberFormat/format_to_parts.d.ts.map +0 -1
- package/lib/PartitionPattern.d.ts.map +0 -1
- package/lib/SupportedLocales.d.ts.map +0 -1
- package/lib/data.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/regex.generated.d.ts.map +0 -1
- package/lib/types/core.d.ts.map +0 -1
- package/lib/types/date-time.d.ts.map +0 -1
- package/lib/types/displaynames.d.ts.map +0 -1
- package/lib/types/list.d.ts.map +0 -1
- package/lib/types/number.d.ts.map +0 -1
- package/lib/types/plural-rules.d.ts.map +0 -1
- package/lib/types/relative-time.d.ts.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/regex.generated.d.ts.map +0 -1
- package/types/core.d.ts.map +0 -1
- package/types/date-time.d.ts.map +0 -1
- package/types/displaynames.d.ts.map +0 -1
- package/types/list.d.ts.map +0 -1
- package/types/number.d.ts.map +0 -1
- package/types/plural-rules.d.ts.map +0 -1
- package/types/relative-time.d.ts.map +0 -1
- package/utils.d.ts.map +0 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComputeExponentForMagnitude = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
|
|
3
6
|
* number of the given magnitude (power of ten of the most significant digit) according to the
|
|
4
7
|
* locale and the desired notation (scientific, engineering, or compact).
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
|
|
7
10
|
var getInternalSlots = _a.getInternalSlots;
|
|
8
11
|
var internalSlots = getInternalSlots(numberFormat);
|
|
9
12
|
var notation = internalSlots.notation, dataLocaleData = internalSlots.dataLocaleData, numberingSystem = internalSlots.numberingSystem;
|
|
@@ -58,3 +61,4 @@ export function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
|
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
}
|
|
64
|
+
exports.ComputeExponentForMagnitude = ComputeExponentForMagnitude;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrencyDigits = void 0;
|
|
4
|
+
var _262_1 = require("../262");
|
|
2
5
|
/**
|
|
3
6
|
* https://tc39.es/ecma402/#sec-currencydigits
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
function CurrencyDigits(c, _a) {
|
|
6
9
|
var currencyDigitsData = _a.currencyDigitsData;
|
|
7
|
-
return HasOwnProperty(currencyDigitsData, c)
|
|
10
|
+
return (0, _262_1.HasOwnProperty)(currencyDigitsData, c)
|
|
8
11
|
? currencyDigitsData[c]
|
|
9
12
|
: 2;
|
|
10
13
|
}
|
|
14
|
+
exports.CurrencyDigits = CurrencyDigits;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatApproximately = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* https://tc39.es/ecma402/#sec-formatapproximately
|
|
3
6
|
*/
|
|
4
|
-
|
|
7
|
+
function FormatApproximately(numberFormat, result, _a) {
|
|
5
8
|
var getInternalSlots = _a.getInternalSlots;
|
|
6
9
|
var internalSlots = getInternalSlots(numberFormat);
|
|
7
10
|
var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
|
|
@@ -9,3 +12,4 @@ export function FormatApproximately(numberFormat, result, _a) {
|
|
|
9
12
|
result.push({ type: 'approximatelySign', value: approximatelySign });
|
|
10
13
|
return result;
|
|
11
14
|
}
|
|
15
|
+
exports.FormatApproximately = FormatApproximately;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatNumericRange = void 0;
|
|
4
|
+
var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
|
|
2
5
|
/**
|
|
3
6
|
* https://tc39.es/ecma402/#sec-formatnumericrange
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
function FormatNumericRange(numberFormat, x, y, _a) {
|
|
6
9
|
var getInternalSlots = _a.getInternalSlots;
|
|
7
|
-
var parts = PartitionNumberRangePattern(numberFormat, x, y, {
|
|
10
|
+
var parts = (0, PartitionNumberRangePattern_1.PartitionNumberRangePattern)(numberFormat, x, y, {
|
|
8
11
|
getInternalSlots: getInternalSlots,
|
|
9
12
|
});
|
|
10
13
|
return parts.map(function (part) { return part.value; }).join('');
|
|
11
14
|
}
|
|
15
|
+
exports.FormatNumericRange = FormatNumericRange;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatNumericRangeToParts = void 0;
|
|
4
|
+
var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
|
|
2
5
|
/**
|
|
3
6
|
* https://tc39.es/ecma402/#sec-formatnumericrangetoparts
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
function FormatNumericRangeToParts(numberFormat, x, y, _a) {
|
|
6
9
|
var getInternalSlots = _a.getInternalSlots;
|
|
7
|
-
var parts = PartitionNumberRangePattern(numberFormat, x, y, {
|
|
10
|
+
var parts = (0, PartitionNumberRangePattern_1.PartitionNumberRangePattern)(numberFormat, x, y, {
|
|
8
11
|
getInternalSlots: getInternalSlots,
|
|
9
12
|
});
|
|
10
13
|
return parts.map(function (part, index) { return ({
|
|
@@ -14,3 +17,4 @@ export function FormatNumericRangeToParts(numberFormat, x, y, _a) {
|
|
|
14
17
|
result: index.toString(),
|
|
15
18
|
}); });
|
|
16
19
|
}
|
|
20
|
+
exports.FormatNumericRangeToParts = FormatNumericRangeToParts;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatNumericToParts = void 0;
|
|
4
|
+
var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
|
|
5
|
+
var _262_1 = require("../262");
|
|
6
|
+
function FormatNumericToParts(nf, x, implDetails) {
|
|
7
|
+
var parts = (0, PartitionNumberPattern_1.PartitionNumberPattern)(nf, x, implDetails);
|
|
8
|
+
var result = (0, _262_1.ArrayCreate)(0);
|
|
6
9
|
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
7
10
|
var part = parts_1[_i];
|
|
8
11
|
result.push({
|
|
@@ -12,3 +15,4 @@ export function FormatNumericToParts(nf, x, implDetails) {
|
|
|
12
15
|
}
|
|
13
16
|
return result;
|
|
14
17
|
}
|
|
18
|
+
exports.FormatNumericToParts = FormatNumericToParts;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatNumericToString = void 0;
|
|
4
|
+
var _262_1 = require("../262");
|
|
5
|
+
var ToRawPrecision_1 = require("./ToRawPrecision");
|
|
6
|
+
var utils_1 = require("../utils");
|
|
7
|
+
var ToRawFixed_1 = require("./ToRawFixed");
|
|
5
8
|
/**
|
|
6
9
|
* https://tc39.es/ecma402/#sec-formatnumberstring
|
|
7
10
|
*/
|
|
8
|
-
|
|
9
|
-
var isNegative = x < 0 || SameValue(x, -0);
|
|
11
|
+
function FormatNumericToString(intlObject, x) {
|
|
12
|
+
var isNegative = x < 0 || (0, _262_1.SameValue)(x, -0);
|
|
10
13
|
if (isNegative) {
|
|
11
14
|
x = -x;
|
|
12
15
|
}
|
|
@@ -14,15 +17,15 @@ export function FormatNumericToString(intlObject, x) {
|
|
|
14
17
|
var rourndingType = intlObject.roundingType;
|
|
15
18
|
switch (rourndingType) {
|
|
16
19
|
case 'significantDigits':
|
|
17
|
-
result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits);
|
|
20
|
+
result = (0, ToRawPrecision_1.ToRawPrecision)(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits);
|
|
18
21
|
break;
|
|
19
22
|
case 'fractionDigits':
|
|
20
|
-
result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits);
|
|
23
|
+
result = (0, ToRawFixed_1.ToRawFixed)(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits);
|
|
21
24
|
break;
|
|
22
25
|
default:
|
|
23
|
-
result = ToRawPrecision(x, 1, 2);
|
|
26
|
+
result = (0, ToRawPrecision_1.ToRawPrecision)(x, 1, 2);
|
|
24
27
|
if (result.integerDigitsCount > 1) {
|
|
25
|
-
result = ToRawFixed(x, 0, 0);
|
|
28
|
+
result = (0, ToRawFixed_1.ToRawFixed)(x, 0, 0);
|
|
26
29
|
}
|
|
27
30
|
break;
|
|
28
31
|
}
|
|
@@ -31,7 +34,7 @@ export function FormatNumericToString(intlObject, x) {
|
|
|
31
34
|
var int = result.integerDigitsCount;
|
|
32
35
|
var minInteger = intlObject.minimumIntegerDigits;
|
|
33
36
|
if (int < minInteger) {
|
|
34
|
-
var forwardZeros = repeat('0', minInteger - int);
|
|
37
|
+
var forwardZeros = (0, utils_1.repeat)('0', minInteger - int);
|
|
35
38
|
string = forwardZeros + string;
|
|
36
39
|
}
|
|
37
40
|
if (isNegative) {
|
|
@@ -39,3 +42,4 @@ export function FormatNumericToString(intlObject, x) {
|
|
|
39
42
|
}
|
|
40
43
|
return { roundedNumber: x, formattedString: string };
|
|
41
44
|
}
|
|
45
|
+
exports.FormatNumericToString = FormatNumericToString;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetUnsignedRoundingMode = void 0;
|
|
1
4
|
var negativeMapping = {
|
|
2
5
|
ceil: 'zero',
|
|
3
6
|
floor: 'infinity',
|
|
@@ -20,9 +23,10 @@ var positiveMapping = {
|
|
|
20
23
|
halfTrunc: 'half-zero',
|
|
21
24
|
halfEven: 'half-even',
|
|
22
25
|
};
|
|
23
|
-
|
|
26
|
+
function GetUnsignedRoundingMode(roundingMode, isNegative) {
|
|
24
27
|
if (isNegative) {
|
|
25
28
|
return negativeMapping[roundingMode];
|
|
26
29
|
}
|
|
27
30
|
return positiveMapping[roundingMode];
|
|
28
31
|
}
|
|
32
|
+
exports.GetUnsignedRoundingMode = GetUnsignedRoundingMode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NumberFormatInternal,
|
|
1
|
+
import { NumberFormatInternal, NumberFormatLocaleInternalData, NumberFormatOptions } from '../types/number';
|
|
2
2
|
/**
|
|
3
3
|
* https://tc39.es/ecma402/#sec-initializenumberformat
|
|
4
4
|
*/
|
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InitializeNumberFormat = void 0;
|
|
4
|
+
var intl_localematcher_1 = require("@formatjs/intl-localematcher");
|
|
5
|
+
var CanonicalizeLocaleList_1 = require("../CanonicalizeLocaleList");
|
|
6
|
+
var CoerceOptionsToObject_1 = require("../CoerceOptionsToObject");
|
|
7
|
+
var GetNumberOption_1 = require("../GetNumberOption");
|
|
8
|
+
var GetOption_1 = require("../GetOption");
|
|
9
|
+
var GetStringOrBooleanOption_1 = require("../GetStringOrBooleanOption");
|
|
10
|
+
var utils_1 = require("../utils");
|
|
11
|
+
var CurrencyDigits_1 = require("./CurrencyDigits");
|
|
12
|
+
var SetNumberFormatDigitOptions_1 = require("./SetNumberFormatDigitOptions");
|
|
13
|
+
var SetNumberFormatUnitOptions_1 = require("./SetNumberFormatUnitOptions");
|
|
11
14
|
var VALID_ROUND_INCREMENT_VALUES = [
|
|
12
15
|
1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000,
|
|
13
16
|
];
|
|
14
17
|
/**
|
|
15
18
|
* https://tc39.es/ecma402/#sec-initializenumberformat
|
|
16
19
|
*/
|
|
17
|
-
|
|
20
|
+
function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
18
21
|
var getInternalSlots = _a.getInternalSlots, localeData = _a.localeData, availableLocales = _a.availableLocales, numberingSystemNames = _a.numberingSystemNames, getDefaultLocale = _a.getDefaultLocale, currencyDigitsData = _a.currencyDigitsData;
|
|
19
22
|
// @ts-ignore
|
|
20
|
-
var requestedLocales = CanonicalizeLocaleList(locales);
|
|
21
|
-
var options = CoerceOptionsToObject(opts);
|
|
23
|
+
var requestedLocales = (0, CanonicalizeLocaleList_1.CanonicalizeLocaleList)(locales);
|
|
24
|
+
var options = (0, CoerceOptionsToObject_1.CoerceOptionsToObject)(opts);
|
|
22
25
|
var opt = Object.create(null);
|
|
23
|
-
var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
|
|
26
|
+
var matcher = (0, GetOption_1.GetOption)(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
|
|
24
27
|
opt.localeMatcher = matcher;
|
|
25
|
-
var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
|
|
28
|
+
var numberingSystem = (0, GetOption_1.GetOption)(options, 'numberingSystem', 'string', undefined, undefined);
|
|
26
29
|
if (numberingSystem !== undefined &&
|
|
27
30
|
numberingSystemNames.indexOf(numberingSystem) < 0) {
|
|
28
31
|
// 8.a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal,
|
|
@@ -30,23 +33,23 @@ export function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
30
33
|
throw RangeError("Invalid numberingSystems: ".concat(numberingSystem));
|
|
31
34
|
}
|
|
32
35
|
opt.nu = numberingSystem;
|
|
33
|
-
var r = ResolveLocale(availableLocales, requestedLocales, opt,
|
|
36
|
+
var r = (0, intl_localematcher_1.ResolveLocale)(Array.from(availableLocales), requestedLocales, opt,
|
|
34
37
|
// [[RelevantExtensionKeys]] slot, which is a constant
|
|
35
38
|
['nu'], localeData, getDefaultLocale);
|
|
36
39
|
var dataLocaleData = localeData[r.dataLocale];
|
|
37
|
-
invariant(!!dataLocaleData, "Missing locale data for ".concat(r.dataLocale));
|
|
40
|
+
(0, utils_1.invariant)(!!dataLocaleData, "Missing locale data for ".concat(r.dataLocale));
|
|
38
41
|
var internalSlots = getInternalSlots(nf);
|
|
39
42
|
internalSlots.locale = r.locale;
|
|
40
43
|
internalSlots.dataLocale = r.dataLocale;
|
|
41
44
|
internalSlots.numberingSystem = r.nu;
|
|
42
45
|
internalSlots.dataLocaleData = dataLocaleData;
|
|
43
|
-
SetNumberFormatUnitOptions(nf, options, { getInternalSlots: getInternalSlots });
|
|
46
|
+
(0, SetNumberFormatUnitOptions_1.SetNumberFormatUnitOptions)(nf, options, { getInternalSlots: getInternalSlots });
|
|
44
47
|
var style = internalSlots.style;
|
|
45
48
|
var mnfdDefault;
|
|
46
49
|
var mxfdDefault;
|
|
47
50
|
if (style === 'currency') {
|
|
48
51
|
var currency = internalSlots.currency;
|
|
49
|
-
var cDigits = CurrencyDigits(currency, { currencyDigitsData: currencyDigitsData });
|
|
52
|
+
var cDigits = (0, CurrencyDigits_1.CurrencyDigits)(currency, { currencyDigitsData: currencyDigitsData });
|
|
50
53
|
mnfdDefault = cDigits;
|
|
51
54
|
mxfdDefault = cDigits;
|
|
52
55
|
}
|
|
@@ -54,10 +57,10 @@ export function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
54
57
|
mnfdDefault = 0;
|
|
55
58
|
mxfdDefault = style === 'percent' ? 0 : 3;
|
|
56
59
|
}
|
|
57
|
-
var notation = GetOption(options, 'notation', 'string', ['standard', 'scientific', 'engineering', 'compact'], 'standard');
|
|
60
|
+
var notation = (0, GetOption_1.GetOption)(options, 'notation', 'string', ['standard', 'scientific', 'engineering', 'compact'], 'standard');
|
|
58
61
|
internalSlots.notation = notation;
|
|
59
|
-
SetNumberFormatDigitOptions(internalSlots, options, mnfdDefault, mxfdDefault, notation);
|
|
60
|
-
var roundingIncrement = GetNumberOption(options, 'roundingIncrement', 1, 5000, 1);
|
|
62
|
+
(0, SetNumberFormatDigitOptions_1.SetNumberFormatDigitOptions)(internalSlots, options, mnfdDefault, mxfdDefault, notation);
|
|
63
|
+
var roundingIncrement = (0, GetNumberOption_1.GetNumberOption)(options, 'roundingIncrement', 1, 5000, 1);
|
|
61
64
|
if (VALID_ROUND_INCREMENT_VALUES.indexOf(roundingIncrement) === -1) {
|
|
62
65
|
throw new RangeError("Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(VALID_ROUND_INCREMENT_VALUES, "."));
|
|
63
66
|
}
|
|
@@ -70,17 +73,17 @@ export function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
70
73
|
throw new RangeError('With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.');
|
|
71
74
|
}
|
|
72
75
|
internalSlots.roundingIncrement = roundingIncrement;
|
|
73
|
-
var trailingZeroDisplay = GetOption(options, 'trailingZeroDisplay', 'string', ['auto', 'stripIfInteger'], 'auto');
|
|
76
|
+
var trailingZeroDisplay = (0, GetOption_1.GetOption)(options, 'trailingZeroDisplay', 'string', ['auto', 'stripIfInteger'], 'auto');
|
|
74
77
|
internalSlots.trailingZeroDisplay = trailingZeroDisplay;
|
|
75
|
-
var compactDisplay = GetOption(options, 'compactDisplay', 'string', ['short', 'long'], 'short');
|
|
78
|
+
var compactDisplay = (0, GetOption_1.GetOption)(options, 'compactDisplay', 'string', ['short', 'long'], 'short');
|
|
76
79
|
var defaultUseGrouping = 'auto';
|
|
77
80
|
if (notation === 'compact') {
|
|
78
81
|
internalSlots.compactDisplay = compactDisplay;
|
|
79
82
|
defaultUseGrouping = 'min2';
|
|
80
83
|
}
|
|
81
|
-
internalSlots.useGrouping = GetStringOrBooleanOption(options, 'useGrouping', ['min2', 'auto', 'always'], 'always', false, defaultUseGrouping);
|
|
82
|
-
internalSlots.signDisplay = GetOption(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero', 'negative'], 'auto');
|
|
83
|
-
internalSlots.roundingMode = GetOption(options, 'roundingMode', 'string', [
|
|
84
|
+
internalSlots.useGrouping = (0, GetStringOrBooleanOption_1.GetStringOrBooleanOption)(options, 'useGrouping', ['min2', 'auto', 'always'], 'always', false, defaultUseGrouping);
|
|
85
|
+
internalSlots.signDisplay = (0, GetOption_1.GetOption)(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero', 'negative'], 'auto');
|
|
86
|
+
internalSlots.roundingMode = (0, GetOption_1.GetOption)(options, 'roundingMode', 'string', [
|
|
84
87
|
'ceil',
|
|
85
88
|
'floor',
|
|
86
89
|
'expand',
|
|
@@ -93,3 +96,4 @@ export function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
93
96
|
], 'halfExpand');
|
|
94
97
|
return nf;
|
|
95
98
|
}
|
|
99
|
+
exports.InitializeNumberFormat = InitializeNumberFormat;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartitionNumberPattern = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var FormatNumericToString_1 = require("./FormatNumericToString");
|
|
6
|
+
var _262_1 = require("../262");
|
|
7
|
+
var ComputeExponent_1 = require("./ComputeExponent");
|
|
8
|
+
var format_to_parts_1 = tslib_1.__importDefault(require("./format_to_parts"));
|
|
5
9
|
/**
|
|
6
10
|
* https://tc39.es/ecma402/#sec-formatnumberstring
|
|
7
11
|
*/
|
|
8
|
-
|
|
12
|
+
function PartitionNumberPattern(numberFormat, x, _a) {
|
|
9
13
|
var _b;
|
|
10
14
|
var getInternalSlots = _a.getInternalSlots;
|
|
11
15
|
var internalSlots = getInternalSlots(numberFormat);
|
|
@@ -22,7 +26,7 @@ export function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
22
26
|
n = symbols.infinity;
|
|
23
27
|
}
|
|
24
28
|
else {
|
|
25
|
-
if (!SameValue(x, -0)) {
|
|
29
|
+
if (!(0, _262_1.SameValue)(x, -0)) {
|
|
26
30
|
if (!isFinite(x)) {
|
|
27
31
|
throw new Error('Input must be a mathematical value');
|
|
28
32
|
}
|
|
@@ -30,13 +34,13 @@ export function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
30
34
|
x *= 100;
|
|
31
35
|
}
|
|
32
36
|
;
|
|
33
|
-
_b = ComputeExponent(numberFormat, x, {
|
|
37
|
+
_b = (0, ComputeExponent_1.ComputeExponent)(numberFormat, x, {
|
|
34
38
|
getInternalSlots: getInternalSlots,
|
|
35
39
|
}), exponent = _b[0], magnitude = _b[1];
|
|
36
40
|
// Preserve more precision by doing multiplication when exponent is negative.
|
|
37
41
|
x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
|
|
38
42
|
}
|
|
39
|
-
var formatNumberResult = FormatNumericToString(internalSlots, x);
|
|
43
|
+
var formatNumberResult = (0, FormatNumericToString_1.FormatNumericToString)(internalSlots, x);
|
|
40
44
|
n = formatNumberResult.formattedString;
|
|
41
45
|
x = formatNumberResult.roundedNumber;
|
|
42
46
|
}
|
|
@@ -49,7 +53,7 @@ export function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
49
53
|
sign = 0;
|
|
50
54
|
break;
|
|
51
55
|
case 'auto':
|
|
52
|
-
if (SameValue(x, 0) || x > 0 || isNaN(x)) {
|
|
56
|
+
if ((0, _262_1.SameValue)(x, 0) || x > 0 || isNaN(x)) {
|
|
53
57
|
sign = 0;
|
|
54
58
|
}
|
|
55
59
|
else {
|
|
@@ -57,7 +61,7 @@ export function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
57
61
|
}
|
|
58
62
|
break;
|
|
59
63
|
case 'always':
|
|
60
|
-
if (SameValue(x, 0) || x > 0 || isNaN(x)) {
|
|
64
|
+
if ((0, _262_1.SameValue)(x, 0) || x > 0 || isNaN(x)) {
|
|
61
65
|
sign = 1;
|
|
62
66
|
}
|
|
63
67
|
else {
|
|
@@ -76,5 +80,6 @@ export function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
76
80
|
sign = -1;
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
|
-
return
|
|
83
|
+
return (0, format_to_parts_1.default)({ roundedNumber: x, formattedString: n, exponent: exponent, magnitude: magnitude, sign: sign }, internalSlots.dataLocaleData, pl, internalSlots);
|
|
80
84
|
}
|
|
85
|
+
exports.PartitionNumberPattern = PartitionNumberPattern;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartitionNumberRangePattern = void 0;
|
|
4
|
+
var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
|
|
5
|
+
var CollapseNumberRange_1 = require("./CollapseNumberRange");
|
|
6
|
+
var FormatApproximately_1 = require("./FormatApproximately");
|
|
4
7
|
/**
|
|
5
8
|
* https://tc39.es/ecma402/#sec-partitionnumberrangepattern
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
function PartitionNumberRangePattern(numberFormat, x, y, _a) {
|
|
8
11
|
var getInternalSlots = _a.getInternalSlots;
|
|
9
12
|
if (isNaN(x) || isNaN(y)) {
|
|
10
13
|
throw new RangeError('Input must be a number');
|
|
11
14
|
}
|
|
12
15
|
var result = [];
|
|
13
|
-
var xResult = PartitionNumberPattern(numberFormat, x, { getInternalSlots: getInternalSlots });
|
|
14
|
-
var yResult = PartitionNumberPattern(numberFormat, y, { getInternalSlots: getInternalSlots });
|
|
16
|
+
var xResult = (0, PartitionNumberPattern_1.PartitionNumberPattern)(numberFormat, x, { getInternalSlots: getInternalSlots });
|
|
17
|
+
var yResult = (0, PartitionNumberPattern_1.PartitionNumberPattern)(numberFormat, y, { getInternalSlots: getInternalSlots });
|
|
15
18
|
if (xResult === yResult) {
|
|
16
|
-
return FormatApproximately(numberFormat, xResult, { getInternalSlots: getInternalSlots });
|
|
19
|
+
return (0, FormatApproximately_1.FormatApproximately)(numberFormat, xResult, { getInternalSlots: getInternalSlots });
|
|
17
20
|
}
|
|
18
21
|
for (var _i = 0, xResult_1 = xResult; _i < xResult_1.length; _i++) {
|
|
19
22
|
var r = xResult_1[_i];
|
|
@@ -28,5 +31,6 @@ export function PartitionNumberRangePattern(numberFormat, x, y, _a) {
|
|
|
28
31
|
r.source = 'endRange';
|
|
29
32
|
}
|
|
30
33
|
result = result.concat(yResult);
|
|
31
|
-
return CollapseNumberRange(result);
|
|
34
|
+
return (0, CollapseNumberRange_1.CollapseNumberRange)(result);
|
|
32
35
|
}
|
|
36
|
+
exports.PartitionNumberRangePattern = PartitionNumberRangePattern;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SetNumberFormatDigitOptions = void 0;
|
|
4
|
+
var GetNumberOption_1 = require("../GetNumberOption");
|
|
5
|
+
var DefaultNumberOption_1 = require("../DefaultNumberOption");
|
|
6
|
+
var GetOption_1 = require("../GetOption");
|
|
4
7
|
/**
|
|
5
8
|
* https://tc39.es/ecma402/#sec-setnfdigitoptions
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
var mnid = GetNumberOption(opts, 'minimumIntegerDigits', 1, 21, 1);
|
|
10
|
+
function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
|
|
11
|
+
var mnid = (0, GetNumberOption_1.GetNumberOption)(opts, 'minimumIntegerDigits', 1, 21, 1);
|
|
9
12
|
var mnfd = opts.minimumFractionDigits;
|
|
10
13
|
var mxfd = opts.maximumFractionDigits;
|
|
11
14
|
var mnsd = opts.minimumSignificantDigits;
|
|
12
15
|
var mxsd = opts.maximumSignificantDigits;
|
|
13
16
|
internalSlots.minimumIntegerDigits = mnid;
|
|
14
|
-
var roundingPriority = GetOption(opts, 'roundingPriority', 'string', ['auto', 'morePrecision', 'lessPrecision'], 'auto');
|
|
17
|
+
var roundingPriority = (0, GetOption_1.GetOption)(opts, 'roundingPriority', 'string', ['auto', 'morePrecision', 'lessPrecision'], 'auto');
|
|
15
18
|
var hasSd = mnsd !== undefined || mxsd !== undefined;
|
|
16
19
|
var hasFd = mnfd !== undefined || mxfd !== undefined;
|
|
17
20
|
var needSd = true;
|
|
@@ -24,8 +27,8 @@ export function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mx
|
|
|
24
27
|
}
|
|
25
28
|
if (needSd) {
|
|
26
29
|
if (hasSd) {
|
|
27
|
-
mnsd = DefaultNumberOption(mnsd, 1, 21, 1);
|
|
28
|
-
mxsd = DefaultNumberOption(mxsd, mnsd, 21, 21);
|
|
30
|
+
mnsd = (0, DefaultNumberOption_1.DefaultNumberOption)(mnsd, 1, 21, 1);
|
|
31
|
+
mxsd = (0, DefaultNumberOption_1.DefaultNumberOption)(mxsd, mnsd, 21, 21);
|
|
29
32
|
internalSlots.minimumSignificantDigits = mnsd;
|
|
30
33
|
internalSlots.maximumSignificantDigits = mxsd;
|
|
31
34
|
}
|
|
@@ -37,9 +40,9 @@ export function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mx
|
|
|
37
40
|
if (needFd) {
|
|
38
41
|
if (hasFd) {
|
|
39
42
|
// @ts-expect-error
|
|
40
|
-
mnfd = DefaultNumberOption(mnfd, 0, 20, undefined);
|
|
43
|
+
mnfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mnfd, 0, 20, undefined);
|
|
41
44
|
// @ts-expect-error
|
|
42
|
-
mxfd = DefaultNumberOption(mxfd, 0, 20, undefined);
|
|
45
|
+
mxfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mxfd, 0, 20, undefined);
|
|
43
46
|
if (mnfd === undefined) {
|
|
44
47
|
mnfd = Math.min(mnfdDefault, mxfd);
|
|
45
48
|
}
|
|
@@ -79,3 +82,4 @@ export function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mx
|
|
|
79
82
|
internalSlots.maximumSignificantDigits = 2;
|
|
80
83
|
}
|
|
81
84
|
}
|
|
85
|
+
exports.SetNumberFormatDigitOptions = SetNumberFormatDigitOptions;
|
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SetNumberFormatUnitOptions = void 0;
|
|
4
|
+
var GetOption_1 = require("../GetOption");
|
|
5
|
+
var IsWellFormedCurrencyCode_1 = require("../IsWellFormedCurrencyCode");
|
|
6
|
+
var IsWellFormedUnitIdentifier_1 = require("../IsWellFormedUnitIdentifier");
|
|
4
7
|
/**
|
|
5
8
|
* https://tc39.es/ecma402/#sec-setnumberformatunitoptions
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
function SetNumberFormatUnitOptions(nf, options, _a) {
|
|
8
11
|
if (options === void 0) { options = Object.create(null); }
|
|
9
12
|
var getInternalSlots = _a.getInternalSlots;
|
|
10
13
|
var internalSlots = getInternalSlots(nf);
|
|
11
|
-
var style = GetOption(options, 'style', 'string', ['decimal', 'percent', 'currency', 'unit'], 'decimal');
|
|
14
|
+
var style = (0, GetOption_1.GetOption)(options, 'style', 'string', ['decimal', 'percent', 'currency', 'unit'], 'decimal');
|
|
12
15
|
internalSlots.style = style;
|
|
13
|
-
var currency = GetOption(options, 'currency', 'string', undefined, undefined);
|
|
14
|
-
if (currency !== undefined && !IsWellFormedCurrencyCode(currency)) {
|
|
16
|
+
var currency = (0, GetOption_1.GetOption)(options, 'currency', 'string', undefined, undefined);
|
|
17
|
+
if (currency !== undefined && !(0, IsWellFormedCurrencyCode_1.IsWellFormedCurrencyCode)(currency)) {
|
|
15
18
|
throw RangeError('Malformed currency code');
|
|
16
19
|
}
|
|
17
20
|
if (style === 'currency' && currency === undefined) {
|
|
18
21
|
throw TypeError('currency cannot be undefined');
|
|
19
22
|
}
|
|
20
|
-
var currencyDisplay = GetOption(options, 'currencyDisplay', 'string', ['code', 'symbol', 'narrowSymbol', 'name'], 'symbol');
|
|
21
|
-
var currencySign = GetOption(options, 'currencySign', 'string', ['standard', 'accounting'], 'standard');
|
|
22
|
-
var unit = GetOption(options, 'unit', 'string', undefined, undefined);
|
|
23
|
-
if (unit !== undefined && !IsWellFormedUnitIdentifier(unit)) {
|
|
23
|
+
var currencyDisplay = (0, GetOption_1.GetOption)(options, 'currencyDisplay', 'string', ['code', 'symbol', 'narrowSymbol', 'name'], 'symbol');
|
|
24
|
+
var currencySign = (0, GetOption_1.GetOption)(options, 'currencySign', 'string', ['standard', 'accounting'], 'standard');
|
|
25
|
+
var unit = (0, GetOption_1.GetOption)(options, 'unit', 'string', undefined, undefined);
|
|
26
|
+
if (unit !== undefined && !(0, IsWellFormedUnitIdentifier_1.IsWellFormedUnitIdentifier)(unit)) {
|
|
24
27
|
throw RangeError('Invalid unit argument for Intl.NumberFormat()');
|
|
25
28
|
}
|
|
26
29
|
if (style === 'unit' && unit === undefined) {
|
|
27
30
|
throw TypeError('unit cannot be undefined');
|
|
28
31
|
}
|
|
29
|
-
var unitDisplay = GetOption(options, 'unitDisplay', 'string', ['short', 'narrow', 'long'], 'short');
|
|
32
|
+
var unitDisplay = (0, GetOption_1.GetOption)(options, 'unitDisplay', 'string', ['short', 'narrow', 'long'], 'short');
|
|
30
33
|
if (style === 'currency') {
|
|
31
34
|
internalSlots.currency = currency.toUpperCase();
|
|
32
35
|
internalSlots.currencyDisplay = currencyDisplay;
|
|
@@ -37,3 +40,4 @@ export function SetNumberFormatUnitOptions(nf, options, _a) {
|
|
|
37
40
|
internalSlots.unitDisplay = unitDisplay;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
43
|
+
exports.SetNumberFormatUnitOptions = SetNumberFormatUnitOptions;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToRawFixed = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
2
5
|
/**
|
|
3
6
|
* TODO: dedup with intl-pluralrules and support BigInt
|
|
4
7
|
* https://tc39.es/ecma402/#sec-torawfixed
|
|
@@ -6,7 +9,7 @@ import { repeat } from '../utils';
|
|
|
6
9
|
* @param minFraction and integer between 0 and 20
|
|
7
10
|
* @param maxFraction and integer between 0 and 20
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
function ToRawFixed(x, minFraction, maxFraction) {
|
|
10
13
|
var f = maxFraction;
|
|
11
14
|
var n = Math.round(x * Math.pow(10, f));
|
|
12
15
|
var xFinal = n / Math.pow(10, f);
|
|
@@ -21,13 +24,13 @@ export function ToRawFixed(x, minFraction, maxFraction) {
|
|
|
21
24
|
m = n.toString();
|
|
22
25
|
var _a = m.split('e'), mantissa = _a[0], exponent = _a[1];
|
|
23
26
|
m = mantissa.replace('.', '');
|
|
24
|
-
m = m + repeat('0', Math.max(+exponent - m.length + 1, 0));
|
|
27
|
+
m = m + (0, utils_1.repeat)('0', Math.max(+exponent - m.length + 1, 0));
|
|
25
28
|
}
|
|
26
29
|
var int;
|
|
27
30
|
if (f !== 0) {
|
|
28
31
|
var k = m.length;
|
|
29
32
|
if (k <= f) {
|
|
30
|
-
var z = repeat('0', f + 1 - k);
|
|
33
|
+
var z = (0, utils_1.repeat)('0', f + 1 - k);
|
|
31
34
|
m = z + m;
|
|
32
35
|
k = f + 1;
|
|
33
36
|
}
|
|
@@ -49,3 +52,4 @@ export function ToRawFixed(x, minFraction, maxFraction) {
|
|
|
49
52
|
}
|
|
50
53
|
return { formattedString: m, roundedNumber: xFinal, integerDigitsCount: int };
|
|
51
54
|
}
|
|
55
|
+
exports.ToRawFixed = ToRawFixed;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToRawPrecision = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
|
+
function ToRawPrecision(x, minPrecision, maxPrecision) {
|
|
3
6
|
var p = maxPrecision;
|
|
4
7
|
var m;
|
|
5
8
|
var e;
|
|
6
9
|
var xFinal;
|
|
7
10
|
if (x === 0) {
|
|
8
|
-
m = repeat('0', p);
|
|
11
|
+
m = (0, utils_1.repeat)('0', p);
|
|
9
12
|
e = 0;
|
|
10
13
|
xFinal = 0;
|
|
11
14
|
}
|
|
@@ -23,11 +26,11 @@ export function ToRawPrecision(x, minPrecision, maxPrecision) {
|
|
|
23
26
|
e = +xToStringExponent;
|
|
24
27
|
m =
|
|
25
28
|
xToStringMantissaWithoutDecimalPoint +
|
|
26
|
-
repeat('0', p - xToStringMantissaWithoutDecimalPoint.length);
|
|
29
|
+
(0, utils_1.repeat)('0', p - xToStringMantissaWithoutDecimalPoint.length);
|
|
27
30
|
xFinal = x;
|
|
28
31
|
}
|
|
29
32
|
else {
|
|
30
|
-
e = getMagnitude(x);
|
|
33
|
+
e = (0, utils_1.getMagnitude)(x);
|
|
31
34
|
var decimalPlaceOffset = e - p + 1;
|
|
32
35
|
// n is the integer containing the required precision digits. To derive the formatted string,
|
|
33
36
|
// we will adjust its decimal place in the logic below.
|
|
@@ -45,7 +48,7 @@ export function ToRawPrecision(x, minPrecision, maxPrecision) {
|
|
|
45
48
|
}
|
|
46
49
|
var int;
|
|
47
50
|
if (e >= p - 1) {
|
|
48
|
-
m = m + repeat('0', e - p + 1);
|
|
51
|
+
m = m + (0, utils_1.repeat)('0', e - p + 1);
|
|
49
52
|
int = e + 1;
|
|
50
53
|
}
|
|
51
54
|
else if (e >= 0) {
|
|
@@ -53,7 +56,7 @@ export function ToRawPrecision(x, minPrecision, maxPrecision) {
|
|
|
53
56
|
int = e + 1;
|
|
54
57
|
}
|
|
55
58
|
else {
|
|
56
|
-
m = "0.".concat(repeat('0', -e - 1)).concat(m);
|
|
59
|
+
m = "0.".concat((0, utils_1.repeat)('0', -e - 1)).concat(m);
|
|
57
60
|
int = 1;
|
|
58
61
|
}
|
|
59
62
|
if (m.indexOf('.') >= 0 && maxPrecision > minPrecision) {
|
|
@@ -72,3 +75,4 @@ export function ToRawPrecision(x, minPrecision, maxPrecision) {
|
|
|
72
75
|
return magnitude < 0 ? x * Math.pow(10, -magnitude) : x / Math.pow(10, magnitude);
|
|
73
76
|
}
|
|
74
77
|
}
|
|
78
|
+
exports.ToRawPrecision = ToRawPrecision;
|