@formatjs/ecma402-abstract 3.0.6 → 3.0.8
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 +55 -55
- package/262.js +322 -327
- package/CanonicalizeLocaleList.d.ts +3 -3
- package/CanonicalizeLocaleList.js +5 -5
- package/CanonicalizeTimeZoneName.d.ts +13 -6
- package/CanonicalizeTimeZoneName.js +88 -15
- package/CoerceOptionsToObject.d.ts +4 -4
- package/CoerceOptionsToObject.js +9 -9
- package/DefaultNumberOption.d.ts +6 -6
- package/DefaultNumberOption.js +15 -15
- package/GetNumberOption.d.ts +5 -9
- package/GetNumberOption.js +10 -10
- package/GetOption.d.ts +12 -8
- package/GetOption.js +28 -28
- package/GetOptionsObject.d.ts +4 -4
- package/GetOptionsObject.js +11 -11
- package/GetStringOrBooleanOption.d.ts +4 -10
- package/GetStringOrBooleanOption.js +28 -28
- package/IsSanctionedSimpleUnitIdentifier.d.ts +8 -6
- package/IsSanctionedSimpleUnitIdentifier.js +53 -53
- package/IsValidTimeZoneName.d.ts +15 -7
- package/IsValidTimeZoneName.js +69 -15
- package/IsWellFormedCurrencyCode.d.ts +2 -2
- package/IsWellFormedCurrencyCode.js +15 -15
- package/IsWellFormedUnitIdentifier.d.ts +3 -3
- package/IsWellFormedUnitIdentifier.js +21 -22
- package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -2
- package/NumberFormat/ApplyUnsignedRoundingMode.js +31 -31
- package/NumberFormat/CollapseNumberRange.d.ts +6 -6
- package/NumberFormat/CollapseNumberRange.js +47 -47
- package/NumberFormat/ComputeExponent.d.ts +8 -8
- package/NumberFormat/ComputeExponent.js +48 -58
- package/NumberFormat/ComputeExponentForMagnitude.d.ts +6 -6
- package/NumberFormat/ComputeExponentForMagnitude.js +64 -63
- package/NumberFormat/CurrencyDigits.d.ts +3 -3
- package/NumberFormat/CurrencyDigits.js +5 -8
- package/NumberFormat/FormatApproximately.d.ts +3 -3
- package/NumberFormat/FormatApproximately.js +10 -6
- package/NumberFormat/FormatNumeric.d.ts +2 -2
- package/NumberFormat/FormatNumeric.js +4 -3
- package/NumberFormat/FormatNumericRange.d.ts +6 -6
- package/NumberFormat/FormatNumericRange.js +7 -9
- package/NumberFormat/FormatNumericRangeToParts.d.ts +6 -6
- package/NumberFormat/FormatNumericRangeToParts.js +12 -14
- package/NumberFormat/FormatNumericToParts.d.ts +3 -3
- package/NumberFormat/FormatNumericToParts.js +12 -12
- package/NumberFormat/FormatNumericToString.d.ts +7 -7
- package/NumberFormat/FormatNumericToString.js +79 -81
- package/NumberFormat/GetUnsignedRoundingMode.d.ts +1 -1
- package/NumberFormat/GetUnsignedRoundingMode.js +25 -24
- package/NumberFormat/InitializeNumberFormat.d.ts +10 -10
- package/NumberFormat/InitializeNumberFormat.js +83 -64
- package/NumberFormat/PartitionNumberPattern.d.ts +4 -4
- package/NumberFormat/PartitionNumberPattern.js +112 -123
- package/NumberFormat/PartitionNumberRangePattern.d.ts +6 -6
- package/NumberFormat/PartitionNumberRangePattern.js +41 -38
- package/NumberFormat/SetNumberFormatDigitOptions.d.ts +3 -3
- package/NumberFormat/SetNumberFormatDigitOptions.js +185 -174
- package/NumberFormat/SetNumberFormatUnitOptions.d.ts +3 -3
- package/NumberFormat/SetNumberFormatUnitOptions.js +62 -48
- package/NumberFormat/ToRawFixed.d.ts +7 -7
- package/NumberFormat/ToRawFixed.js +103 -107
- package/NumberFormat/ToRawPrecision.d.ts +7 -7
- package/NumberFormat/ToRawPrecision.js +199 -202
- package/NumberFormat/decimal-cache.d.ts +10 -10
- package/NumberFormat/decimal-cache.js +13 -13
- package/NumberFormat/digit-mapping.generated.js +781 -781
- package/NumberFormat/format_to_parts.d.ts +24 -20
- package/NumberFormat/format_to_parts.js +446 -420
- package/PartitionPattern.d.ts +6 -6
- package/PartitionPattern.js +33 -33
- package/SupportedLocales.d.ts +6 -6
- package/SupportedLocales.js +17 -17
- package/ToIntlMathematicalValue.d.ts +1 -1
- package/ToIntlMathematicalValue.js +24 -25
- package/constants.d.ts +1 -1
- package/constants.js +4 -4
- package/data.d.ts +1 -1
- package/data.js +4 -11
- package/index.d.ts +47 -47
- package/index.js +45 -45
- package/package.json +3 -3
- package/regex.generated.d.ts +1 -0
- package/regex.generated.js +1 -1
- package/types/core.d.ts +5 -5
- package/types/date-time.d.ts +123 -128
- package/types/date-time.js +6 -6
- package/types/displaynames.d.ts +55 -55
- package/types/displaynames.js +1 -1
- package/types/list.d.ts +11 -11
- package/types/list.js +1 -1
- package/types/number.d.ts +151 -137
- package/types/number.js +2 -1
- package/types/plural-rules.d.ts +11 -11
- package/types/plural-rules.js +2 -1
- package/types/relative-time.d.ts +26 -32
- package/types/relative-time.js +2 -1
- package/utils.d.ts +40 -14
- package/utils.js +63 -116
|
@@ -1,66 +1,67 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
import "../types/number.js";
|
|
3
|
+
import { invariant } from "../utils.js";
|
|
4
|
+
import { getPowerOf10 } from "./decimal-cache.js";
|
|
5
|
+
Decimal.set({ toExpPos: 100 });
|
|
7
6
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
* The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
|
|
8
|
+
* number of the given magnitude (power of ten of the most significant digit) according to the
|
|
9
|
+
* locale and the desired notation (scientific, engineering, or compact).
|
|
10
|
+
*/
|
|
12
11
|
export function ComputeExponentForMagnitude(internalSlots, magnitude) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
12
|
+
const { notation, dataLocaleData, numberingSystem } = internalSlots;
|
|
13
|
+
switch (notation) {
|
|
14
|
+
case "standard": return 0;
|
|
15
|
+
case "scientific": return magnitude.toNumber();
|
|
16
|
+
case "engineering":
|
|
17
|
+
const thousands = magnitude.div(3).floor();
|
|
18
|
+
return thousands.times(3).toNumber();
|
|
19
|
+
default: {
|
|
20
|
+
invariant(notation === "compact", "Invalid notation");
|
|
21
|
+
// Let exponent be an implementation- and locale-dependent (ILD) integer by which to scale a
|
|
22
|
+
// number of the given magnitude in compact notation for the current locale.
|
|
23
|
+
const { compactDisplay, style, currencyDisplay } = internalSlots;
|
|
24
|
+
let thresholdMap;
|
|
25
|
+
if (style === "currency" && currencyDisplay !== "name") {
|
|
26
|
+
const currency = dataLocaleData.numbers.currency[numberingSystem] || dataLocaleData.numbers.currency[dataLocaleData.numbers.nu[0]];
|
|
27
|
+
thresholdMap = currency.short;
|
|
28
|
+
} else {
|
|
29
|
+
const decimal = dataLocaleData.numbers.decimal[numberingSystem] || dataLocaleData.numbers.decimal[dataLocaleData.numbers.nu[0]];
|
|
30
|
+
thresholdMap = compactDisplay === "long" ? decimal.long : decimal.short;
|
|
31
|
+
}
|
|
32
|
+
if (!thresholdMap) {
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
const num = getPowerOf10(magnitude).toString();
|
|
36
|
+
const thresholds = Object.keys(thresholdMap);
|
|
37
|
+
if (num < thresholds[0]) {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
if (num > thresholds[thresholds.length - 1]) {
|
|
41
|
+
// GH #4236: When number exceeds max threshold, use the exponent
|
|
42
|
+
// corresponding to the largest available threshold in locale data.
|
|
43
|
+
// Calculate exponent the same way as for normal thresholds (lines 70-73).
|
|
44
|
+
const magnitudeKey = thresholds[thresholds.length - 1];
|
|
45
|
+
const compactPattern = thresholdMap[magnitudeKey].other;
|
|
46
|
+
if (compactPattern === "0") {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
return magnitudeKey.length - thresholdMap[magnitudeKey].other.match(/0+/)[0].length;
|
|
50
|
+
}
|
|
51
|
+
const i = thresholds.indexOf(num);
|
|
52
|
+
if (i === -1) {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
// See https://unicode.org/reports/tr35/tr35-numbers.html#Compact_Number_Formats
|
|
56
|
+
// Special handling if the pattern is precisely `0`.
|
|
57
|
+
const magnitudeKey = thresholds[i];
|
|
58
|
+
// TODO: do we need to handle plural here?
|
|
59
|
+
const compactPattern = thresholdMap[magnitudeKey].other;
|
|
60
|
+
if (compactPattern === "0") {
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
// Example: in zh-TW, `10000000` maps to `0000萬`. So we need to return 8 - 4 = 4 here.
|
|
64
|
+
return magnitudeKey.length - thresholdMap[magnitudeKey].other.match(/0+/)[0].length;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
66
67
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
* https://tc39.es/ecma402/#sec-currencydigits
|
|
3
|
+
*/
|
|
4
4
|
export declare function CurrencyDigits(c: string, { currencyDigitsData }: {
|
|
5
|
-
|
|
5
|
+
currencyDigitsData: Record<string, number>;
|
|
6
6
|
}): number;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { HasOwnProperty } from
|
|
1
|
+
import { HasOwnProperty } from "../262.js";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function CurrencyDigits(c,
|
|
6
|
-
|
|
7
|
-
return HasOwnProperty(currencyDigitsData, c)
|
|
8
|
-
? currencyDigitsData[c]
|
|
9
|
-
: 2;
|
|
3
|
+
* https://tc39.es/ecma402/#sec-currencydigits
|
|
4
|
+
*/
|
|
5
|
+
export function CurrencyDigits(c, { currencyDigitsData }) {
|
|
6
|
+
return HasOwnProperty(currencyDigitsData, c) ? currencyDigitsData[c] : 2;
|
|
10
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NumberFormatInternal, NumberFormatPart } from
|
|
1
|
+
import { type NumberFormatInternal, type NumberFormatPart } from "../types/number.js";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
* https://tc39.es/ecma402/#sec-formatapproximately
|
|
4
|
+
*/
|
|
5
5
|
export declare function FormatApproximately(internalSlots: NumberFormatInternal, result: NumberFormatPart[]): NumberFormatPart[];
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import "../types/number.js";
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
* https://tc39.es/ecma402/#sec-formatapproximately
|
|
4
|
+
*/
|
|
4
5
|
export function FormatApproximately(internalSlots, result) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
|
|
7
|
+
const approximatelySign = symbols.approximatelySign;
|
|
8
|
+
result.push({
|
|
9
|
+
type: "approximatelySign",
|
|
10
|
+
value: approximatelySign
|
|
11
|
+
});
|
|
12
|
+
return result;
|
|
9
13
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import { NumberFormatInternal } from
|
|
1
|
+
import type { Decimal } from "decimal.js";
|
|
2
|
+
import { type NumberFormatInternal } from "../types/number.js";
|
|
3
3
|
export declare function FormatNumeric(internalSlots: NumberFormatInternal, x: Decimal): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../types/number.js";
|
|
2
|
+
import { PartitionNumberPattern } from "./PartitionNumberPattern.js";
|
|
2
3
|
export function FormatNumeric(internalSlots, x) {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
const parts = PartitionNumberPattern(internalSlots, x);
|
|
5
|
+
return parts.map((p) => p.value).join("");
|
|
5
6
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import { NumberFormatInternal } from
|
|
1
|
+
import type { Decimal } from "decimal.js";
|
|
2
|
+
import { type NumberFormatInternal } from "../types/number.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function FormatNumericRange(numberFormat: Intl.NumberFormat, x: Decimal, y: Decimal, { getInternalSlots
|
|
7
|
-
|
|
4
|
+
* https://tc39.es/ecma402/#sec-formatnumericrange
|
|
5
|
+
*/
|
|
6
|
+
export declare function FormatNumericRange(numberFormat: Intl.NumberFormat, x: Decimal, y: Decimal, { getInternalSlots }: {
|
|
7
|
+
getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
|
|
8
8
|
}): string;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../types/number.js";
|
|
2
|
+
import { PartitionNumberRangePattern } from "./PartitionNumberRangePattern.js";
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function FormatNumericRange(numberFormat, x, y,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getInternalSlots: getInternalSlots,
|
|
9
|
-
});
|
|
10
|
-
return parts.map(function (part) { return part.value; }).join('');
|
|
4
|
+
* https://tc39.es/ecma402/#sec-formatnumericrange
|
|
5
|
+
*/
|
|
6
|
+
export function FormatNumericRange(numberFormat, x, y, { getInternalSlots }) {
|
|
7
|
+
const parts = PartitionNumberRangePattern(numberFormat, x, y, { getInternalSlots });
|
|
8
|
+
return parts.map((part) => part.value).join("");
|
|
11
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import { NumberFormatInternal, NumberRangeToParts } from
|
|
1
|
+
import type { Decimal } from "decimal.js";
|
|
2
|
+
import { type NumberFormatInternal, type NumberRangeToParts } from "../types/number.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function FormatNumericRangeToParts(numberFormat: Intl.NumberFormat, x: Decimal, y: Decimal, { getInternalSlots
|
|
7
|
-
|
|
4
|
+
* https://tc39.es/ecma402/#sec-formatnumericrangetoparts
|
|
5
|
+
*/
|
|
6
|
+
export declare function FormatNumericRangeToParts(numberFormat: Intl.NumberFormat, x: Decimal, y: Decimal, { getInternalSlots }: {
|
|
7
|
+
getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
|
|
8
8
|
}): NumberRangeToParts[];
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../types/number.js";
|
|
2
|
+
import { PartitionNumberRangePattern } from "./PartitionNumberRangePattern.js";
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function FormatNumericRangeToParts(numberFormat, x, y,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
source: part.source,
|
|
14
|
-
result: index.toString(),
|
|
15
|
-
}); });
|
|
4
|
+
* https://tc39.es/ecma402/#sec-formatnumericrangetoparts
|
|
5
|
+
*/
|
|
6
|
+
export function FormatNumericRangeToParts(numberFormat, x, y, { getInternalSlots }) {
|
|
7
|
+
const parts = PartitionNumberRangePattern(numberFormat, x, y, { getInternalSlots });
|
|
8
|
+
return parts.map((part, index) => ({
|
|
9
|
+
type: part.type,
|
|
10
|
+
value: part.value,
|
|
11
|
+
source: part.source,
|
|
12
|
+
result: index.toString()
|
|
13
|
+
}));
|
|
16
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import { NumberFormatInternal, NumberFormatPart } from
|
|
1
|
+
import type { Decimal } from "decimal.js";
|
|
2
|
+
import { type NumberFormatInternal, type 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,14 +1,14 @@
|
|
|
1
|
-
import { ArrayCreate } from
|
|
2
|
-
import
|
|
1
|
+
import { ArrayCreate } from "../262.js";
|
|
2
|
+
import "../types/number.js";
|
|
3
|
+
import { PartitionNumberPattern } from "./PartitionNumberPattern.js";
|
|
3
4
|
export function FormatNumericToParts(nf, x, implDetails) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return result;
|
|
5
|
+
const parts = PartitionNumberPattern(implDetails.getInternalSlots(nf), x);
|
|
6
|
+
const result = ArrayCreate(0);
|
|
7
|
+
for (const part of parts) {
|
|
8
|
+
result.push({
|
|
9
|
+
type: part.type,
|
|
10
|
+
value: part.value
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
14
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import { NumberFormatDigitInternalSlots } from
|
|
1
|
+
import type { Decimal } from "decimal.js";
|
|
2
|
+
import { type NumberFormatDigitInternalSlots } from "../types/number.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function FormatNumericToString(intlObject: Pick<NumberFormatDigitInternalSlots,
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
* https://tc39.es/ecma402/#sec-formatnumberstring
|
|
5
|
+
*/
|
|
6
|
+
export declare function FormatNumericToString(intlObject: Pick<NumberFormatDigitInternalSlots, "roundingType" | "minimumSignificantDigits" | "maximumSignificantDigits" | "minimumIntegerDigits" | "minimumFractionDigits" | "maximumFractionDigits" | "roundingIncrement" | "roundingMode" | "trailingZeroDisplay">, _x: Decimal): {
|
|
7
|
+
roundedNumber: Decimal;
|
|
8
|
+
formattedString: string;
|
|
9
9
|
};
|
|
@@ -1,84 +1,82 @@
|
|
|
1
|
-
import { NEGATIVE_ZERO, ZERO } from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { NEGATIVE_ZERO, ZERO } from "../constants.js";
|
|
2
|
+
import "../types/number.js";
|
|
3
|
+
import { invariant, repeat } from "../utils.js";
|
|
4
|
+
import { GetUnsignedRoundingMode } from "./GetUnsignedRoundingMode.js";
|
|
5
|
+
import { ToRawFixed } from "./ToRawFixed.js";
|
|
6
|
+
import { ToRawPrecision } from "./ToRawPrecision.js";
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
* https://tc39.es/ecma402/#sec-formatnumberstring
|
|
9
|
+
*/
|
|
9
10
|
export function FormatNumericToString(intlObject, _x) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return { roundedNumber: x, formattedString: string };
|
|
11
|
+
let x = _x;
|
|
12
|
+
let sign;
|
|
13
|
+
// -0
|
|
14
|
+
if (x.isZero() && x.isNegative()) {
|
|
15
|
+
sign = "negative";
|
|
16
|
+
x = ZERO;
|
|
17
|
+
} else {
|
|
18
|
+
invariant(x.isFinite(), "NumberFormatDigitInternalSlots value is not finite");
|
|
19
|
+
if (x.lessThan(0)) {
|
|
20
|
+
sign = "negative";
|
|
21
|
+
} else {
|
|
22
|
+
sign = "positive";
|
|
23
|
+
}
|
|
24
|
+
if (sign === "negative") {
|
|
25
|
+
x = x.negated();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
let result;
|
|
29
|
+
const roundingType = intlObject.roundingType;
|
|
30
|
+
const unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode, sign === "negative");
|
|
31
|
+
switch (roundingType) {
|
|
32
|
+
case "significantDigits":
|
|
33
|
+
result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
|
|
34
|
+
break;
|
|
35
|
+
case "fractionDigits":
|
|
36
|
+
result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
let sResult = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
|
|
40
|
+
let fResult = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
|
|
41
|
+
if (intlObject.roundingType === "morePrecision") {
|
|
42
|
+
if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
|
|
43
|
+
result = sResult;
|
|
44
|
+
} else {
|
|
45
|
+
result = fResult;
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
invariant(intlObject.roundingType === "lessPrecision", "Invalid roundingType");
|
|
49
|
+
if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
|
|
50
|
+
result = fResult;
|
|
51
|
+
} else {
|
|
52
|
+
result = sResult;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
x = result.roundedNumber;
|
|
58
|
+
let string = result.formattedString;
|
|
59
|
+
if (intlObject.trailingZeroDisplay === "stripIfInteger" && x.isInteger()) {
|
|
60
|
+
let i = string.indexOf(".");
|
|
61
|
+
if (i > -1) {
|
|
62
|
+
string = string.slice(0, i);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const int = result.integerDigitsCount;
|
|
66
|
+
const minInteger = intlObject.minimumIntegerDigits;
|
|
67
|
+
if (int < minInteger) {
|
|
68
|
+
const forwardZeros = repeat("0", minInteger - int);
|
|
69
|
+
string = forwardZeros + string;
|
|
70
|
+
}
|
|
71
|
+
if (sign === "negative") {
|
|
72
|
+
if (x.isZero()) {
|
|
73
|
+
x = NEGATIVE_ZERO;
|
|
74
|
+
} else {
|
|
75
|
+
x = x.negated();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
roundedNumber: x,
|
|
80
|
+
formattedString: string
|
|
81
|
+
};
|
|
84
82
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RoundingModeType, UnsignedRoundingModeType } from
|
|
1
|
+
import { type RoundingModeType, type UnsignedRoundingModeType } from "../types/number.js";
|
|
2
2
|
export declare function GetUnsignedRoundingMode(roundingMode: RoundingModeType, isNegative: boolean): UnsignedRoundingModeType;
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import "../types/number.js";
|
|
2
|
+
const negativeMapping = {
|
|
3
|
+
ceil: "zero",
|
|
4
|
+
floor: "infinity",
|
|
5
|
+
expand: "infinity",
|
|
6
|
+
trunc: "zero",
|
|
7
|
+
halfCeil: "half-zero",
|
|
8
|
+
halfFloor: "half-infinity",
|
|
9
|
+
halfExpand: "half-infinity",
|
|
10
|
+
halfTrunc: "half-zero",
|
|
11
|
+
halfEven: "half-even"
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
const positiveMapping = {
|
|
14
|
+
ceil: "infinity",
|
|
15
|
+
floor: "zero",
|
|
16
|
+
expand: "infinity",
|
|
17
|
+
trunc: "zero",
|
|
18
|
+
halfCeil: "half-infinity",
|
|
19
|
+
halfFloor: "half-zero",
|
|
20
|
+
halfExpand: "half-infinity",
|
|
21
|
+
halfTrunc: "half-zero",
|
|
22
|
+
halfEven: "half-even"
|
|
22
23
|
};
|
|
23
24
|
export function GetUnsignedRoundingMode(roundingMode, isNegative) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (isNegative) {
|
|
26
|
+
return negativeMapping[roundingMode];
|
|
27
|
+
}
|
|
28
|
+
return positiveMapping[roundingMode];
|
|
28
29
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { NumberFormatInternal, NumberFormatLocaleInternalData, NumberFormatOptions } from
|
|
1
|
+
import { type NumberFormatInternal, type NumberFormatLocaleInternalData, type NumberFormatOptions } from "../types/number.js";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare function InitializeNumberFormat(nf: Intl.NumberFormat, locales: string | ReadonlyArray<string> | undefined, opts: NumberFormatOptions | undefined, { getInternalSlots, localeData, availableLocales, numberingSystemNames, getDefaultLocale, currencyDigitsData
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
* https://tc39.es/ecma402/#sec-initializenumberformat
|
|
4
|
+
*/
|
|
5
|
+
export declare function InitializeNumberFormat(nf: Intl.NumberFormat, locales: string | ReadonlyArray<string> | undefined, opts: NumberFormatOptions | undefined, { getInternalSlots, localeData, availableLocales, numberingSystemNames, getDefaultLocale, currencyDigitsData }: {
|
|
6
|
+
getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
|
|
7
|
+
localeData: Record<string, NumberFormatLocaleInternalData | undefined>;
|
|
8
|
+
availableLocales: Set<string>;
|
|
9
|
+
numberingSystemNames: ReadonlyArray<string>;
|
|
10
|
+
getDefaultLocale(): string;
|
|
11
|
+
currencyDigitsData: Record<string, number>;
|
|
12
12
|
}): Intl.NumberFormat;
|