@formatjs/ecma402-abstract 2.3.6 → 3.0.0
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/262.d.ts +1 -1
- package/262.js +42 -68
- package/CanonicalizeLocaleList.js +1 -4
- package/CanonicalizeTimeZoneName.js +1 -4
- package/CoerceOptionsToObject.js +3 -6
- package/DefaultNumberOption.js +1 -4
- package/GetNumberOption.js +3 -6
- package/GetOption.js +3 -6
- package/GetOptionsObject.js +1 -4
- package/GetStringOrBooleanOption.js +3 -6
- package/IsSanctionedSimpleUnitIdentifier.js +5 -10
- package/IsValidTimeZoneName.js +1 -4
- package/IsWellFormedCurrencyCode.js +1 -4
- package/IsWellFormedUnitIdentifier.js +5 -8
- package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -2
- package/NumberFormat/ApplyUnsignedRoundingMode.js +5 -8
- package/NumberFormat/CollapseNumberRange.d.ts +1 -1
- package/NumberFormat/CollapseNumberRange.js +1 -4
- package/NumberFormat/ComputeExponent.d.ts +2 -2
- package/NumberFormat/ComputeExponent.js +8 -12
- package/NumberFormat/ComputeExponentForMagnitude.d.ts +2 -2
- package/NumberFormat/ComputeExponentForMagnitude.js +6 -10
- package/NumberFormat/CurrencyDigits.js +3 -6
- package/NumberFormat/FormatApproximately.d.ts +1 -1
- package/NumberFormat/FormatApproximately.js +1 -4
- package/NumberFormat/FormatNumeric.d.ts +2 -2
- package/NumberFormat/FormatNumeric.js +3 -6
- package/NumberFormat/FormatNumericRange.d.ts +2 -2
- package/NumberFormat/FormatNumericRange.js +3 -6
- package/NumberFormat/FormatNumericRangeToParts.d.ts +2 -2
- package/NumberFormat/FormatNumericRangeToParts.js +3 -6
- package/NumberFormat/FormatNumericToParts.d.ts +2 -2
- package/NumberFormat/FormatNumericToParts.js +5 -8
- package/NumberFormat/FormatNumericToString.d.ts +2 -2
- package/NumberFormat/FormatNumericToString.js +16 -19
- package/NumberFormat/GetUnsignedRoundingMode.d.ts +1 -1
- package/NumberFormat/GetUnsignedRoundingMode.js +1 -4
- package/NumberFormat/InitializeNumberFormat.d.ts +1 -1
- package/NumberFormat/InitializeNumberFormat.js +23 -26
- package/NumberFormat/PartitionNumberPattern.d.ts +2 -2
- package/NumberFormat/PartitionNumberPattern.js +12 -16
- package/NumberFormat/PartitionNumberRangePattern.d.ts +2 -2
- package/NumberFormat/PartitionNumberRangePattern.js +12 -15
- package/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
- package/NumberFormat/SetNumberFormatDigitOptions.js +18 -21
- package/NumberFormat/SetNumberFormatUnitOptions.d.ts +1 -1
- package/NumberFormat/SetNumberFormatUnitOptions.js +15 -18
- package/NumberFormat/ToRawFixed.d.ts +2 -2
- package/NumberFormat/ToRawFixed.js +10 -14
- package/NumberFormat/ToRawPrecision.d.ts +2 -2
- package/NumberFormat/ToRawPrecision.js +19 -23
- package/NumberFormat/digit-mapping.generated.js +1 -4
- package/NumberFormat/format_to_parts.d.ts +2 -2
- package/NumberFormat/format_to_parts.js +18 -22
- package/PartitionPattern.js +3 -6
- package/SupportedLocales.js +8 -11
- package/ToIntlMathematicalValue.d.ts +1 -1
- package/ToIntlMathematicalValue.js +12 -16
- package/constants.d.ts +1 -1
- package/constants.js +4 -8
- package/data.js +3 -6
- package/index.d.ts +47 -47
- package/index.js +45 -66
- package/package.json +13 -11
- package/regex.generated.js +1 -4
- package/types/core.js +1 -2
- package/types/date-time.js +2 -5
- package/types/displaynames.d.ts +1 -1
- package/types/displaynames.js +1 -2
- package/types/list.d.ts +1 -1
- package/types/list.js +1 -2
- package/types/number.d.ts +3 -3
- package/types/number.js +1 -2
- package/types/plural-rules.d.ts +2 -2
- package/types/plural-rules.js +1 -2
- package/types/relative-time.d.ts +2 -2
- package/types/relative-time.js +1 -2
- package/utils.js +28 -40
- package/lib/262.d.ts +0 -93
- package/lib/262.js +0 -400
- package/lib/CanonicalizeLocaleList.d.ts +0 -5
- package/lib/CanonicalizeLocaleList.js +0 -8
- package/lib/CanonicalizeTimeZoneName.d.ts +0 -8
- package/lib/CanonicalizeTimeZoneName.js +0 -17
- package/lib/CoerceOptionsToObject.d.ts +0 -6
- package/lib/CoerceOptionsToObject.js +0 -12
- package/lib/DefaultNumberOption.d.ts +0 -8
- package/lib/DefaultNumberOption.js +0 -18
- package/lib/GetNumberOption.d.ts +0 -9
- package/lib/GetNumberOption.js +0 -13
- package/lib/GetOption.d.ts +0 -9
- package/lib/GetOption.js +0 -31
- package/lib/GetOptionsObject.d.ts +0 -6
- package/lib/GetOptionsObject.js +0 -14
- package/lib/GetStringOrBooleanOption.d.ts +0 -10
- package/lib/GetStringOrBooleanOption.js +0 -31
- package/lib/IsSanctionedSimpleUnitIdentifier.d.ts +0 -13
- package/lib/IsSanctionedSimpleUnitIdentifier.js +0 -63
- package/lib/IsValidTimeZoneName.d.ts +0 -9
- package/lib/IsValidTimeZoneName.js +0 -17
- package/lib/IsWellFormedCurrencyCode.d.ts +0 -4
- package/lib/IsWellFormedCurrencyCode.js +0 -21
- package/lib/IsWellFormedUnitIdentifier.d.ts +0 -5
- package/lib/IsWellFormedUnitIdentifier.js +0 -28
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.d.ts +0 -3
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +0 -33
- package/lib/NumberFormat/CollapseNumberRange.d.ts +0 -8
- package/lib/NumberFormat/CollapseNumberRange.js +0 -50
- package/lib/NumberFormat/ComputeExponent.d.ts +0 -10
- package/lib/NumberFormat/ComputeExponent.js +0 -34
- package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts +0 -8
- package/lib/NumberFormat/ComputeExponentForMagnitude.js +0 -65
- package/lib/NumberFormat/CurrencyDigits.d.ts +0 -6
- package/lib/NumberFormat/CurrencyDigits.js +0 -10
- package/lib/NumberFormat/FormatApproximately.d.ts +0 -5
- package/lib/NumberFormat/FormatApproximately.js +0 -9
- package/lib/NumberFormat/FormatNumeric.d.ts +0 -3
- package/lib/NumberFormat/FormatNumeric.js +0 -5
- package/lib/NumberFormat/FormatNumericRange.d.ts +0 -8
- package/lib/NumberFormat/FormatNumericRange.js +0 -11
- package/lib/NumberFormat/FormatNumericRangeToParts.d.ts +0 -8
- package/lib/NumberFormat/FormatNumericRangeToParts.js +0 -16
- package/lib/NumberFormat/FormatNumericToParts.d.ts +0 -5
- package/lib/NumberFormat/FormatNumericToParts.js +0 -14
- package/lib/NumberFormat/FormatNumericToString.d.ts +0 -9
- package/lib/NumberFormat/FormatNumericToString.js +0 -84
- package/lib/NumberFormat/GetUnsignedRoundingMode.d.ts +0 -2
- package/lib/NumberFormat/GetUnsignedRoundingMode.js +0 -28
- package/lib/NumberFormat/InitializeNumberFormat.d.ts +0 -12
- package/lib/NumberFormat/InitializeNumberFormat.js +0 -66
- package/lib/NumberFormat/PartitionNumberPattern.d.ts +0 -6
- package/lib/NumberFormat/PartitionNumberPattern.js +0 -126
- package/lib/NumberFormat/PartitionNumberRangePattern.d.ts +0 -8
- package/lib/NumberFormat/PartitionNumberRangePattern.js +0 -40
- package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +0 -5
- package/lib/NumberFormat/SetNumberFormatDigitOptions.js +0 -179
- package/lib/NumberFormat/SetNumberFormatUnitOptions.d.ts +0 -5
- package/lib/NumberFormat/SetNumberFormatUnitOptions.js +0 -50
- package/lib/NumberFormat/ToRawFixed.d.ts +0 -9
- package/lib/NumberFormat/ToRawFixed.js +0 -119
- package/lib/NumberFormat/ToRawPrecision.d.ts +0 -9
- package/lib/NumberFormat/ToRawPrecision.js +0 -148
- package/lib/NumberFormat/digit-mapping.generated.d.ts +0 -1
- package/lib/NumberFormat/digit-mapping.generated.js +0 -782
- package/lib/NumberFormat/format_to_parts.d.ts +0 -24
- package/lib/NumberFormat/format_to_parts.js +0 -447
- package/lib/PartitionPattern.d.ts +0 -9
- package/lib/PartitionPattern.js +0 -36
- package/lib/SupportedLocales.d.ts +0 -9
- package/lib/SupportedLocales.js +0 -20
- package/lib/ToIntlMathematicalValue.d.ts +0 -2
- package/lib/ToIntlMathematicalValue.js +0 -27
- package/lib/constants.d.ts +0 -4
- package/lib/constants.js +0 -4
- package/lib/data.d.ts +0 -5
- package/lib/data.js +0 -13
- package/lib/index.d.ts +0 -47
- package/lib/index.js +0 -45
- package/lib/regex.generated.d.ts +0 -1
- package/lib/regex.generated.js +0 -2
- package/lib/types/core.d.ts +0 -10
- package/lib/types/core.js +0 -1
- package/lib/types/date-time.d.ts +0 -135
- package/lib/types/date-time.js +0 -6
- package/lib/types/displaynames.d.ts +0 -65
- package/lib/types/displaynames.js +0 -1
- package/lib/types/list.d.ts +0 -18
- package/lib/types/list.js +0 -1
- package/lib/types/number.d.ts +0 -173
- package/lib/types/number.js +0 -1
- package/lib/types/plural-rules.d.ts +0 -16
- package/lib/types/plural-rules.js +0 -1
- package/lib/types/relative-time.d.ts +0 -40
- package/lib/types/relative-time.js +0 -1
- package/lib/utils.d.ts +0 -30
- package/lib/utils.js +0 -135
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { NumberFormatInternal } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { NumberFormatInternal } from '../types/number.js';
|
|
3
3
|
/**
|
|
4
4
|
* The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
|
|
5
5
|
* number of the given magnitude (power of ten of the most significant digit) according to the
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
6
|
-
var utils_1 = require("../utils");
|
|
7
|
-
decimal_js_1.default.set({
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { invariant } from '../utils.js';
|
|
3
|
+
Decimal.set({
|
|
8
4
|
toExpPos: 100,
|
|
9
5
|
});
|
|
10
6
|
/**
|
|
@@ -12,7 +8,7 @@ decimal_js_1.default.set({
|
|
|
12
8
|
* number of the given magnitude (power of ten of the most significant digit) according to the
|
|
13
9
|
* locale and the desired notation (scientific, engineering, or compact).
|
|
14
10
|
*/
|
|
15
|
-
function ComputeExponentForMagnitude(internalSlots, magnitude) {
|
|
11
|
+
export function ComputeExponentForMagnitude(internalSlots, magnitude) {
|
|
16
12
|
var notation = internalSlots.notation, dataLocaleData = internalSlots.dataLocaleData, numberingSystem = internalSlots.numberingSystem;
|
|
17
13
|
switch (notation) {
|
|
18
14
|
case 'standard':
|
|
@@ -23,7 +19,7 @@ function ComputeExponentForMagnitude(internalSlots, magnitude) {
|
|
|
23
19
|
var thousands = magnitude.div(3).floor();
|
|
24
20
|
return thousands.times(3).toNumber();
|
|
25
21
|
default: {
|
|
26
|
-
|
|
22
|
+
invariant(notation === 'compact', 'Invalid notation');
|
|
27
23
|
// Let exponent be an implementation- and locale-dependent (ILD) integer by which to scale a
|
|
28
24
|
// number of the given magnitude in compact notation for the current locale.
|
|
29
25
|
var compactDisplay = internalSlots.compactDisplay, style = internalSlots.style, currencyDisplay = internalSlots.currencyDisplay;
|
|
@@ -41,7 +37,7 @@ function ComputeExponentForMagnitude(internalSlots, magnitude) {
|
|
|
41
37
|
if (!thresholdMap) {
|
|
42
38
|
return 0;
|
|
43
39
|
}
|
|
44
|
-
var num =
|
|
40
|
+
var num = Decimal.pow(10, magnitude).toString();
|
|
45
41
|
var thresholds = Object.keys(thresholdMap); // TODO: this can be pre-processed
|
|
46
42
|
if (num < thresholds[0]) {
|
|
47
43
|
return 0;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CurrencyDigits = CurrencyDigits;
|
|
4
|
-
var _262_1 = require("../262");
|
|
1
|
+
import { HasOwnProperty } from '../262.js';
|
|
5
2
|
/**
|
|
6
3
|
* https://tc39.es/ecma402/#sec-currencydigits
|
|
7
4
|
*/
|
|
8
|
-
function CurrencyDigits(c, _a) {
|
|
5
|
+
export function CurrencyDigits(c, _a) {
|
|
9
6
|
var currencyDigitsData = _a.currencyDigitsData;
|
|
10
|
-
return
|
|
7
|
+
return HasOwnProperty(currencyDigitsData, c)
|
|
11
8
|
? currencyDigitsData[c]
|
|
12
9
|
: 2;
|
|
13
10
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormatApproximately = FormatApproximately;
|
|
4
1
|
/**
|
|
5
2
|
* https://tc39.es/ecma402/#sec-formatapproximately
|
|
6
3
|
*/
|
|
7
|
-
function FormatApproximately(internalSlots, result) {
|
|
4
|
+
export function FormatApproximately(internalSlots, result) {
|
|
8
5
|
var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
|
|
9
6
|
var approximatelySign = symbols.approximatelySign;
|
|
10
7
|
result.push({ type: 'approximatelySign', value: approximatelySign });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { NumberFormatInternal } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { NumberFormatInternal } from '../types/number.js';
|
|
3
3
|
export declare function FormatNumeric(internalSlots: NumberFormatInternal, x: Decimal): string;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
|
|
5
|
-
function FormatNumeric(internalSlots, x) {
|
|
6
|
-
var parts = (0, PartitionNumberPattern_1.PartitionNumberPattern)(internalSlots, x);
|
|
1
|
+
import { PartitionNumberPattern } from './PartitionNumberPattern.js';
|
|
2
|
+
export function FormatNumeric(internalSlots, x) {
|
|
3
|
+
var parts = PartitionNumberPattern(internalSlots, x);
|
|
7
4
|
return parts.map(function (p) { return p.value; }).join('');
|
|
8
5
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormatNumericRange = FormatNumericRange;
|
|
4
|
-
var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
|
|
1
|
+
import { PartitionNumberRangePattern } from './PartitionNumberRangePattern.js';
|
|
5
2
|
/**
|
|
6
3
|
* https://tc39.es/ecma402/#sec-formatnumericrange
|
|
7
4
|
*/
|
|
8
|
-
function FormatNumericRange(numberFormat, x, y, _a) {
|
|
5
|
+
export function FormatNumericRange(numberFormat, x, y, _a) {
|
|
9
6
|
var getInternalSlots = _a.getInternalSlots;
|
|
10
|
-
var parts =
|
|
7
|
+
var parts = PartitionNumberRangePattern(numberFormat, x, y, {
|
|
11
8
|
getInternalSlots: getInternalSlots,
|
|
12
9
|
});
|
|
13
10
|
return parts.map(function (part) { return part.value; }).join('');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { NumberFormatInternal, NumberRangeToParts } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { NumberFormatInternal, NumberRangeToParts } from '../types/number.js';
|
|
3
3
|
/**
|
|
4
4
|
* https://tc39.es/ecma402/#sec-formatnumericrangetoparts
|
|
5
5
|
*/
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormatNumericRangeToParts = FormatNumericRangeToParts;
|
|
4
|
-
var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
|
|
1
|
+
import { PartitionNumberRangePattern } from './PartitionNumberRangePattern.js';
|
|
5
2
|
/**
|
|
6
3
|
* https://tc39.es/ecma402/#sec-formatnumericrangetoparts
|
|
7
4
|
*/
|
|
8
|
-
function FormatNumericRangeToParts(numberFormat, x, y, _a) {
|
|
5
|
+
export function FormatNumericRangeToParts(numberFormat, x, y, _a) {
|
|
9
6
|
var getInternalSlots = _a.getInternalSlots;
|
|
10
|
-
var parts =
|
|
7
|
+
var parts = PartitionNumberRangePattern(numberFormat, x, y, {
|
|
11
8
|
getInternalSlots: getInternalSlots,
|
|
12
9
|
});
|
|
13
10
|
return parts.map(function (part, index) { return ({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { NumberFormatInternal, NumberFormatPart } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { NumberFormatInternal, NumberFormatPart } from '../types/number.js';
|
|
3
3
|
export declare function FormatNumericToParts(nf: Intl.NumberFormat, x: Decimal, implDetails: {
|
|
4
4
|
getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
|
|
5
5
|
}): NumberFormatPart[];
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
function FormatNumericToParts(nf, x, implDetails) {
|
|
7
|
-
var parts = (0, PartitionNumberPattern_1.PartitionNumberPattern)(implDetails.getInternalSlots(nf), x);
|
|
8
|
-
var result = (0, _262_1.ArrayCreate)(0);
|
|
1
|
+
import { ArrayCreate } from '../262.js';
|
|
2
|
+
import { PartitionNumberPattern } from './PartitionNumberPattern.js';
|
|
3
|
+
export function FormatNumericToParts(nf, x, implDetails) {
|
|
4
|
+
var parts = PartitionNumberPattern(implDetails.getInternalSlots(nf), x);
|
|
5
|
+
var result = ArrayCreate(0);
|
|
9
6
|
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
10
7
|
var part = parts_1[_i];
|
|
11
8
|
result.push({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { NumberFormatDigitInternalSlots } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { NumberFormatDigitInternalSlots } from '../types/number.js';
|
|
3
3
|
/**
|
|
4
4
|
* https://tc39.es/ecma402/#sec-formatnumberstring
|
|
5
5
|
*/
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var GetUnsignedRoundingMode_1 = require("./GetUnsignedRoundingMode");
|
|
7
|
-
var ToRawFixed_1 = require("./ToRawFixed");
|
|
8
|
-
var ToRawPrecision_1 = require("./ToRawPrecision");
|
|
1
|
+
import { NEGATIVE_ZERO, ZERO } from '../constants.js';
|
|
2
|
+
import { invariant, repeat } from '../utils.js';
|
|
3
|
+
import { GetUnsignedRoundingMode } from './GetUnsignedRoundingMode.js';
|
|
4
|
+
import { ToRawFixed } from './ToRawFixed.js';
|
|
5
|
+
import { ToRawPrecision } from './ToRawPrecision.js';
|
|
9
6
|
/**
|
|
10
7
|
* https://tc39.es/ecma402/#sec-formatnumberstring
|
|
11
8
|
*/
|
|
12
|
-
function FormatNumericToString(intlObject, _x) {
|
|
9
|
+
export function FormatNumericToString(intlObject, _x) {
|
|
13
10
|
var x = _x;
|
|
14
11
|
var sign;
|
|
15
12
|
// -0
|
|
16
13
|
if (x.isZero() && x.isNegative()) {
|
|
17
14
|
sign = 'negative';
|
|
18
|
-
x =
|
|
15
|
+
x = ZERO;
|
|
19
16
|
}
|
|
20
17
|
else {
|
|
21
|
-
|
|
18
|
+
invariant(x.isFinite(), 'NumberFormatDigitInternalSlots value is not finite');
|
|
22
19
|
if (x.lessThan(0)) {
|
|
23
20
|
sign = 'negative';
|
|
24
21
|
}
|
|
@@ -31,17 +28,17 @@ function FormatNumericToString(intlObject, _x) {
|
|
|
31
28
|
}
|
|
32
29
|
var result;
|
|
33
30
|
var roundingType = intlObject.roundingType;
|
|
34
|
-
var unsignedRoundingMode =
|
|
31
|
+
var unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode, sign === 'negative');
|
|
35
32
|
switch (roundingType) {
|
|
36
33
|
case 'significantDigits':
|
|
37
|
-
result =
|
|
34
|
+
result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
|
|
38
35
|
break;
|
|
39
36
|
case 'fractionDigits':
|
|
40
|
-
result =
|
|
37
|
+
result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
|
|
41
38
|
break;
|
|
42
39
|
default:
|
|
43
|
-
var sResult =
|
|
44
|
-
var fResult =
|
|
40
|
+
var sResult = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
|
|
41
|
+
var fResult = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
|
|
45
42
|
if (intlObject.roundingType === 'morePrecision') {
|
|
46
43
|
if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
|
|
47
44
|
result = sResult;
|
|
@@ -51,7 +48,7 @@ function FormatNumericToString(intlObject, _x) {
|
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
else {
|
|
54
|
-
|
|
51
|
+
invariant(intlObject.roundingType === 'lessPrecision', 'Invalid roundingType');
|
|
55
52
|
if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
|
|
56
53
|
result = fResult;
|
|
57
54
|
}
|
|
@@ -72,12 +69,12 @@ function FormatNumericToString(intlObject, _x) {
|
|
|
72
69
|
var int = result.integerDigitsCount;
|
|
73
70
|
var minInteger = intlObject.minimumIntegerDigits;
|
|
74
71
|
if (int < minInteger) {
|
|
75
|
-
var forwardZeros =
|
|
72
|
+
var forwardZeros = repeat('0', minInteger - int);
|
|
76
73
|
string = forwardZeros + string;
|
|
77
74
|
}
|
|
78
75
|
if (sign === 'negative') {
|
|
79
76
|
if (x.isZero()) {
|
|
80
|
-
x =
|
|
77
|
+
x = NEGATIVE_ZERO;
|
|
81
78
|
}
|
|
82
79
|
else {
|
|
83
80
|
x = x.negated();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RoundingModeType, UnsignedRoundingModeType } from '../types/number';
|
|
1
|
+
import { RoundingModeType, UnsignedRoundingModeType } from '../types/number.js';
|
|
2
2
|
export declare function GetUnsignedRoundingMode(roundingMode: RoundingModeType, isNegative: boolean): UnsignedRoundingModeType;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetUnsignedRoundingMode = GetUnsignedRoundingMode;
|
|
4
1
|
var negativeMapping = {
|
|
5
2
|
ceil: 'zero',
|
|
6
3
|
floor: 'infinity',
|
|
@@ -23,7 +20,7 @@ var positiveMapping = {
|
|
|
23
20
|
halfTrunc: 'half-zero',
|
|
24
21
|
halfEven: 'half-even',
|
|
25
22
|
};
|
|
26
|
-
function GetUnsignedRoundingMode(roundingMode, isNegative) {
|
|
23
|
+
export function GetUnsignedRoundingMode(roundingMode, isNegative) {
|
|
27
24
|
if (isNegative) {
|
|
28
25
|
return negativeMapping[roundingMode];
|
|
29
26
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NumberFormatInternal, NumberFormatLocaleInternalData, NumberFormatOptions } from '../types/number';
|
|
1
|
+
import { NumberFormatInternal, NumberFormatLocaleInternalData, NumberFormatOptions } from '../types/number.js';
|
|
2
2
|
/**
|
|
3
3
|
* https://tc39.es/ecma402/#sec-initializenumberformat
|
|
4
4
|
*/
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var CurrencyDigits_1 = require("./CurrencyDigits");
|
|
11
|
-
var SetNumberFormatDigitOptions_1 = require("./SetNumberFormatDigitOptions");
|
|
12
|
-
var SetNumberFormatUnitOptions_1 = require("./SetNumberFormatUnitOptions");
|
|
1
|
+
import { ResolveLocale } from '@formatjs/intl-localematcher';
|
|
2
|
+
import { CanonicalizeLocaleList } from '../CanonicalizeLocaleList.js';
|
|
3
|
+
import { CoerceOptionsToObject } from '../CoerceOptionsToObject.js';
|
|
4
|
+
import { GetOption } from '../GetOption.js';
|
|
5
|
+
import { GetStringOrBooleanOption } from '../GetStringOrBooleanOption.js';
|
|
6
|
+
import { invariant } from '../utils.js';
|
|
7
|
+
import { CurrencyDigits } from './CurrencyDigits.js';
|
|
8
|
+
import { SetNumberFormatDigitOptions } from './SetNumberFormatDigitOptions.js';
|
|
9
|
+
import { SetNumberFormatUnitOptions } from './SetNumberFormatUnitOptions.js';
|
|
13
10
|
/**
|
|
14
11
|
* https://tc39.es/ecma402/#sec-initializenumberformat
|
|
15
12
|
*/
|
|
16
|
-
function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
13
|
+
export function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
17
14
|
var getInternalSlots = _a.getInternalSlots, localeData = _a.localeData, availableLocales = _a.availableLocales, numberingSystemNames = _a.numberingSystemNames, getDefaultLocale = _a.getDefaultLocale, currencyDigitsData = _a.currencyDigitsData;
|
|
18
|
-
var requestedLocales =
|
|
19
|
-
var options =
|
|
15
|
+
var requestedLocales = CanonicalizeLocaleList(locales);
|
|
16
|
+
var options = CoerceOptionsToObject(opts);
|
|
20
17
|
var opt = Object.create(null);
|
|
21
|
-
var matcher =
|
|
18
|
+
var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
|
|
22
19
|
opt.localeMatcher = matcher;
|
|
23
|
-
var numberingSystem =
|
|
20
|
+
var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
|
|
24
21
|
if (numberingSystem !== undefined &&
|
|
25
22
|
numberingSystemNames.indexOf(numberingSystem) < 0) {
|
|
26
23
|
// 8.a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal,
|
|
@@ -28,25 +25,25 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
28
25
|
throw RangeError("Invalid numberingSystems: ".concat(numberingSystem));
|
|
29
26
|
}
|
|
30
27
|
opt.nu = numberingSystem;
|
|
31
|
-
var r =
|
|
28
|
+
var r = ResolveLocale(Array.from(availableLocales), requestedLocales, opt,
|
|
32
29
|
// [[RelevantExtensionKeys]] slot, which is a constant
|
|
33
30
|
['nu'], localeData, getDefaultLocale);
|
|
34
31
|
var dataLocaleData = localeData[r.dataLocale];
|
|
35
|
-
|
|
32
|
+
invariant(!!dataLocaleData, "Missing locale data for ".concat(r.dataLocale));
|
|
36
33
|
var internalSlots = getInternalSlots(nf);
|
|
37
34
|
internalSlots.locale = r.locale;
|
|
38
35
|
internalSlots.dataLocale = r.dataLocale;
|
|
39
36
|
internalSlots.numberingSystem = r.nu;
|
|
40
37
|
internalSlots.dataLocaleData = dataLocaleData;
|
|
41
|
-
|
|
38
|
+
SetNumberFormatUnitOptions(internalSlots, options);
|
|
42
39
|
var style = internalSlots.style;
|
|
43
|
-
var notation =
|
|
40
|
+
var notation = GetOption(options, 'notation', 'string', ['standard', 'scientific', 'engineering', 'compact'], 'standard');
|
|
44
41
|
internalSlots.notation = notation;
|
|
45
42
|
var mnfdDefault;
|
|
46
43
|
var mxfdDefault;
|
|
47
44
|
if (style === 'currency' && notation === 'standard') {
|
|
48
45
|
var currency = internalSlots.currency;
|
|
49
|
-
var cDigits =
|
|
46
|
+
var cDigits = CurrencyDigits(currency, { currencyDigitsData: currencyDigitsData });
|
|
50
47
|
mnfdDefault = cDigits;
|
|
51
48
|
mxfdDefault = cDigits;
|
|
52
49
|
}
|
|
@@ -54,16 +51,16 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
54
51
|
mnfdDefault = 0;
|
|
55
52
|
mxfdDefault = style === 'percent' ? 0 : 3;
|
|
56
53
|
}
|
|
57
|
-
|
|
58
|
-
var compactDisplay =
|
|
54
|
+
SetNumberFormatDigitOptions(internalSlots, options, mnfdDefault, mxfdDefault, notation);
|
|
55
|
+
var compactDisplay = GetOption(options, 'compactDisplay', 'string', ['short', 'long'], 'short');
|
|
59
56
|
var defaultUseGrouping = 'auto';
|
|
60
57
|
if (notation === 'compact') {
|
|
61
58
|
internalSlots.compactDisplay = compactDisplay;
|
|
62
59
|
defaultUseGrouping = 'min2';
|
|
63
60
|
}
|
|
64
|
-
var useGrouping =
|
|
61
|
+
var useGrouping = GetStringOrBooleanOption(options, 'useGrouping', ['min2', 'auto', 'always'], 'always', false, defaultUseGrouping);
|
|
65
62
|
internalSlots.useGrouping = useGrouping;
|
|
66
|
-
var signDisplay =
|
|
63
|
+
var signDisplay = GetOption(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero', 'negative'], 'auto');
|
|
67
64
|
internalSlots.signDisplay = signDisplay;
|
|
68
65
|
return nf;
|
|
69
66
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { NumberFormatInternal, NumberFormatPart } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { NumberFormatInternal, NumberFormatPart } from '../types/number.js';
|
|
3
3
|
/**
|
|
4
4
|
* https://tc39.es/ecma402/#sec-partitionnumberpattern
|
|
5
5
|
*/
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var utils_1 = require("../utils");
|
|
7
|
-
var ComputeExponent_1 = require("./ComputeExponent");
|
|
8
|
-
var format_to_parts_1 = tslib_1.__importDefault(require("./format_to_parts"));
|
|
9
|
-
var FormatNumericToString_1 = require("./FormatNumericToString");
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { invariant } from '../utils.js';
|
|
3
|
+
import { ComputeExponent } from './ComputeExponent.js';
|
|
4
|
+
import formatToParts from './format_to_parts.js';
|
|
5
|
+
import { FormatNumericToString } from './FormatNumericToString.js';
|
|
10
6
|
/**
|
|
11
7
|
* https://tc39.es/ecma402/#sec-partitionnumberpattern
|
|
12
8
|
*/
|
|
13
|
-
function PartitionNumberPattern(internalSlots, _x) {
|
|
9
|
+
export function PartitionNumberPattern(internalSlots, _x) {
|
|
14
10
|
var _a;
|
|
15
11
|
var x = _x;
|
|
16
12
|
// IMPL: We need to record the magnitude of the number
|
|
@@ -38,21 +34,21 @@ function PartitionNumberPattern(internalSlots, _x) {
|
|
|
38
34
|
// 8. Else,
|
|
39
35
|
if (!x.isZero()) {
|
|
40
36
|
// 8.a. If x < 0, let x be -x.
|
|
41
|
-
|
|
37
|
+
invariant(x.isFinite(), 'Input must be a mathematical value');
|
|
42
38
|
// 8.b. If internalSlots.[[style]] is "percent", let x be 100 × x.
|
|
43
39
|
if (internalSlots.style == 'percent') {
|
|
44
40
|
x = x.times(100);
|
|
45
41
|
}
|
|
46
42
|
// 8.c. Let exponent be ComputeExponent(numberFormat, x).
|
|
47
43
|
;
|
|
48
|
-
_a =
|
|
44
|
+
_a = ComputeExponent(internalSlots, x), exponent = _a[0],
|
|
49
45
|
// IMPL: We need to record the magnitude of the number
|
|
50
46
|
magnitude = _a[1];
|
|
51
47
|
// 8.d. Let x be x × 10^(-exponent).
|
|
52
|
-
x = x.times(
|
|
48
|
+
x = x.times(Decimal.pow(10, -exponent));
|
|
53
49
|
}
|
|
54
50
|
// 8.e. Let formatNumberResult be FormatNumericToString(internalSlots, x).
|
|
55
|
-
var formatNumberResult =
|
|
51
|
+
var formatNumberResult = FormatNumericToString(internalSlots, x);
|
|
56
52
|
// 8.f. Let n be formatNumberResult.[[formattedString]].
|
|
57
53
|
n = formatNumberResult.formattedString;
|
|
58
54
|
// 8.g. Let x be formatNumberResult.[[roundedNumber]].
|
|
@@ -107,7 +103,7 @@ function PartitionNumberPattern(internalSlots, _x) {
|
|
|
107
103
|
break;
|
|
108
104
|
default:
|
|
109
105
|
// 10.e. Else,
|
|
110
|
-
|
|
106
|
+
invariant(signDisplay === 'negative', 'signDisplay must be "negative"');
|
|
111
107
|
if (x.isNegative() && !x.isZero()) {
|
|
112
108
|
// 10.e.i. If x is negative and x is not 0, let sign be -1.
|
|
113
109
|
sign = -1;
|
|
@@ -119,7 +115,7 @@ function PartitionNumberPattern(internalSlots, _x) {
|
|
|
119
115
|
break;
|
|
120
116
|
}
|
|
121
117
|
// 11. Return ? FormatNumberToParts(numberFormat, x, n, exponent, sign).
|
|
122
|
-
return (
|
|
118
|
+
return formatToParts({
|
|
123
119
|
roundedNumber: x,
|
|
124
120
|
formattedString: n,
|
|
125
121
|
exponent: exponent,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { NumberFormatInternal, NumberFormatPart } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { NumberFormatInternal, NumberFormatPart } from '../types/number.js';
|
|
3
3
|
/**
|
|
4
4
|
* https://tc39.es/ecma402/#sec-partitionnumberrangepattern
|
|
5
5
|
*/
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var FormatApproximately_1 = require("./FormatApproximately");
|
|
7
|
-
var FormatNumeric_1 = require("./FormatNumeric");
|
|
8
|
-
var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
|
|
1
|
+
import { invariant } from '../utils.js';
|
|
2
|
+
import { CollapseNumberRange } from './CollapseNumberRange.js';
|
|
3
|
+
import { FormatApproximately } from './FormatApproximately.js';
|
|
4
|
+
import { FormatNumeric } from './FormatNumeric.js';
|
|
5
|
+
import { PartitionNumberPattern } from './PartitionNumberPattern.js';
|
|
9
6
|
/**
|
|
10
7
|
* https://tc39.es/ecma402/#sec-partitionnumberrangepattern
|
|
11
8
|
*/
|
|
12
|
-
function PartitionNumberRangePattern(numberFormat, x, y, _a) {
|
|
9
|
+
export function PartitionNumberRangePattern(numberFormat, x, y, _a) {
|
|
13
10
|
var getInternalSlots = _a.getInternalSlots;
|
|
14
11
|
// 1. Assert: x and y are both mathematical values.
|
|
15
|
-
|
|
12
|
+
invariant(!x.isNaN() && !y.isNaN(), 'Input must be a number', RangeError);
|
|
16
13
|
var internalSlots = getInternalSlots(numberFormat);
|
|
17
14
|
// 3. Let xResult be ? PartitionNumberPattern(numberFormat, x).
|
|
18
|
-
var xResult =
|
|
15
|
+
var xResult = PartitionNumberPattern(internalSlots, x);
|
|
19
16
|
// 4. Let yResult be ? PartitionNumberPattern(numberFormat, y).
|
|
20
|
-
var yResult =
|
|
21
|
-
if (
|
|
22
|
-
var appxResult =
|
|
17
|
+
var yResult = PartitionNumberPattern(internalSlots, y);
|
|
18
|
+
if (FormatNumeric(internalSlots, x) === FormatNumeric(internalSlots, y)) {
|
|
19
|
+
var appxResult = FormatApproximately(internalSlots, xResult);
|
|
23
20
|
appxResult.forEach(function (el) {
|
|
24
21
|
el.source = 'shared';
|
|
25
22
|
});
|
|
@@ -39,5 +36,5 @@ function PartitionNumberRangePattern(numberFormat, x, y, _a) {
|
|
|
39
36
|
result.push(el);
|
|
40
37
|
});
|
|
41
38
|
// 13. Return ? CollapseNumberRange(numberFormat, result).
|
|
42
|
-
return
|
|
39
|
+
return CollapseNumberRange(numberFormat, result, { getInternalSlots: getInternalSlots });
|
|
43
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NumberFormatDigitInternalSlots, NumberFormatDigitOptions, NumberFormatNotation } from '../types/number';
|
|
1
|
+
import { NumberFormatDigitInternalSlots, NumberFormatDigitOptions, NumberFormatNotation } from '../types/number.js';
|
|
2
2
|
/**
|
|
3
3
|
* https://tc39.es/ecma402/#sec-setnfdigitoptions
|
|
4
4
|
*/
|