@formatjs/ecma402-abstract 3.0.7 → 3.1.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 +55 -55
- package/262.js +327 -327
- package/CanonicalizeLocaleList.d.ts +3 -3
- package/CanonicalizeLocaleList.js +5 -5
- package/CanonicalizeTimeZoneName.d.ts +13 -13
- package/CanonicalizeTimeZoneName.js +81 -82
- 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 +6 -6
- package/IsSanctionedSimpleUnitIdentifier.js +53 -53
- package/IsValidTimeZoneName.d.ts +15 -15
- package/IsValidTimeZoneName.js +65 -66
- 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 +34 -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 -72
- 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 -66
- package/NumberFormat/format_to_parts.d.ts +19 -20
- package/NumberFormat/format_to_parts.js +446 -438
- 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 +5 -1
- package/ToIntlMathematicalValue.js +31 -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 +5 -5
- 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 +137 -137
- package/types/number.js +2 -1
- package/types/plural-rules.d.ts +19 -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 +30 -15
- package/utils.js +62 -116
|
@@ -1,179 +1,190 @@
|
|
|
1
|
-
import { DefaultNumberOption } from
|
|
2
|
-
import { GetNumberOption } from
|
|
3
|
-
import { GetOption } from
|
|
4
|
-
import
|
|
1
|
+
import { DefaultNumberOption } from "../DefaultNumberOption.js";
|
|
2
|
+
import { GetNumberOption } from "../GetNumberOption.js";
|
|
3
|
+
import { GetOption } from "../GetOption.js";
|
|
4
|
+
import "../types/number.js";
|
|
5
|
+
import { invariant } from "../utils.js";
|
|
5
6
|
//IMPL: Valid rounding increments as per implementation
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const VALID_ROUNDING_INCREMENTS = new Set([
|
|
8
|
+
1,
|
|
9
|
+
2,
|
|
10
|
+
5,
|
|
11
|
+
10,
|
|
12
|
+
20,
|
|
13
|
+
25,
|
|
14
|
+
50,
|
|
15
|
+
100,
|
|
16
|
+
200,
|
|
17
|
+
250,
|
|
18
|
+
500,
|
|
19
|
+
1e3,
|
|
20
|
+
2e3,
|
|
21
|
+
2500,
|
|
22
|
+
5e3
|
|
8
23
|
]);
|
|
9
24
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
25
|
+
* https://tc39.es/ecma402/#sec-setnfdigitoptions
|
|
26
|
+
*/
|
|
12
27
|
export function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// 28.b. Assert: internalSlots.[[MaximumFractionDigits]] is equal to internalSlots.[[MinimumFractionDigits]].
|
|
176
|
-
invariant(internalSlots.maximumFractionDigits ===
|
|
177
|
-
internalSlots.minimumFractionDigits, 'With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.', RangeError);
|
|
178
|
-
}
|
|
28
|
+
// 1. Let mnid be ? GetNumberOption(opts, "minimumIntegerDigits", 1, 21, 1).
|
|
29
|
+
const mnid = GetNumberOption(opts, "minimumIntegerDigits", 1, 21, 1);
|
|
30
|
+
// 2. Let mnfd be opts.[[MinimumFractionDigits]].
|
|
31
|
+
let mnfd = opts.minimumFractionDigits;
|
|
32
|
+
// 3. Let mxfd be opts.[[MaximumFractionDigits]].
|
|
33
|
+
let mxfd = opts.maximumFractionDigits;
|
|
34
|
+
// 4. Let mnsd be opts.[[MinimumSignificantDigits]].
|
|
35
|
+
let mnsd = opts.minimumSignificantDigits;
|
|
36
|
+
// 5. Let mxsd be opts.[[MaximumSignificantDigits]].
|
|
37
|
+
let mxsd = opts.maximumSignificantDigits;
|
|
38
|
+
// 6. Set internalSlots.[[MinimumIntegerDigits]] to mnid.
|
|
39
|
+
internalSlots.minimumIntegerDigits = mnid;
|
|
40
|
+
// 7. Let roundingIncrement be ? GetNumberOption(opts, "roundingIncrement", 1, 5000, 1).
|
|
41
|
+
const roundingIncrement = GetNumberOption(opts, "roundingIncrement", 1, 5e3, 1);
|
|
42
|
+
// 8. If roundingIncrement is not an element of the list {1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000}, throw a RangeError exception.
|
|
43
|
+
invariant(VALID_ROUNDING_INCREMENTS.has(roundingIncrement), `Invalid rounding increment value: ${roundingIncrement}.
|
|
44
|
+
Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
|
|
45
|
+
// 9. Let roundingMode be ? GetOption(opts, "roundingMode", "string", « "ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven" », "halfExpand").
|
|
46
|
+
const roundingMode = GetOption(opts, "roundingMode", "string", [
|
|
47
|
+
"ceil",
|
|
48
|
+
"floor",
|
|
49
|
+
"expand",
|
|
50
|
+
"trunc",
|
|
51
|
+
"halfCeil",
|
|
52
|
+
"halfFloor",
|
|
53
|
+
"halfExpand",
|
|
54
|
+
"halfTrunc",
|
|
55
|
+
"halfEven"
|
|
56
|
+
], "halfExpand");
|
|
57
|
+
// 10. Let roundingPriority be ? GetOption(opts, "roundingPriority", "string", « "auto", "morePrecision", "lessPrecision" », "auto").
|
|
58
|
+
const roundingPriority = GetOption(opts, "roundingPriority", "string", [
|
|
59
|
+
"auto",
|
|
60
|
+
"morePrecision",
|
|
61
|
+
"lessPrecision"
|
|
62
|
+
], "auto");
|
|
63
|
+
// 11. Let trailingZeroDisplay be ? GetOption(opts, "trailingZeroDisplay", "string", « "auto", "stripIfInteger" », "auto").
|
|
64
|
+
const trailingZeroDisplay = GetOption(opts, "trailingZeroDisplay", "string", ["auto", "stripIfInteger"], "auto");
|
|
65
|
+
// 12. If roundingIncrement is not 1, then
|
|
66
|
+
if (roundingIncrement !== 1) {
|
|
67
|
+
// 12.a. Set mxfdDefault to mnfdDefault.
|
|
68
|
+
mxfdDefault = mnfdDefault;
|
|
69
|
+
}
|
|
70
|
+
// 13. Set internalSlots.[[RoundingIncrement]] to roundingIncrement.
|
|
71
|
+
internalSlots.roundingIncrement = roundingIncrement;
|
|
72
|
+
// 14. Set internalSlots.[[RoundingMode]] to roundingMode.
|
|
73
|
+
internalSlots.roundingMode = roundingMode;
|
|
74
|
+
// 15. Set internalSlots.[[TrailingZeroDisplay]] to trailingZeroDisplay.
|
|
75
|
+
internalSlots.trailingZeroDisplay = trailingZeroDisplay;
|
|
76
|
+
// 16. Let hasSd be true if mnsd is not undefined or mxsd is not undefined; otherwise, let hasSd be false.
|
|
77
|
+
const hasSd = mnsd !== undefined || mxsd !== undefined;
|
|
78
|
+
// 17. Let hasFd be true if mnfd is not undefined or mxfd is not undefined; otherwise, let hasFd be false.
|
|
79
|
+
const hasFd = mnfd !== undefined || mxfd !== undefined;
|
|
80
|
+
// 18. Let needSd be true.
|
|
81
|
+
let needSd = true;
|
|
82
|
+
// 19. Let needFd be true.
|
|
83
|
+
let needFd = true;
|
|
84
|
+
// 20. If roundingPriority is "auto", then
|
|
85
|
+
if (roundingPriority === "auto") {
|
|
86
|
+
// 20.a. Set needSd to hasSd.
|
|
87
|
+
needSd = hasSd;
|
|
88
|
+
// 20.b. If hasSd is true or hasFd is false and notation is "compact", then
|
|
89
|
+
if (hasSd || !hasFd && notation === "compact") {
|
|
90
|
+
// 20.b.i. Set needFd to false.
|
|
91
|
+
needFd = false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// 21. If needSd is true, then
|
|
95
|
+
if (needSd) {
|
|
96
|
+
// 21.a. If hasSd is true, then
|
|
97
|
+
if (hasSd) {
|
|
98
|
+
// 21.a.i. Set internalSlots.[[MinimumSignificantDigits]] to ? DefaultNumberOption(mnsd, 1, 21, 1).
|
|
99
|
+
internalSlots.minimumSignificantDigits = DefaultNumberOption(mnsd, 1, 21, 1);
|
|
100
|
+
// 21.a.ii. Set internalSlots.[[MaximumSignificantDigits]] to ? DefaultNumberOption(mxsd, internalSlots.[[MinimumSignificantDigits]], 21, 21).
|
|
101
|
+
internalSlots.maximumSignificantDigits = DefaultNumberOption(mxsd, internalSlots.minimumSignificantDigits, 21, 21);
|
|
102
|
+
} else {
|
|
103
|
+
// 21.b. Else,
|
|
104
|
+
// 21.b.i. Set internalSlots.[[MinimumSignificantDigits]] to 1.
|
|
105
|
+
internalSlots.minimumSignificantDigits = 1;
|
|
106
|
+
// 21.b.ii. Set internalSlots.[[MaximumSignificantDigits]] to 21.
|
|
107
|
+
internalSlots.maximumSignificantDigits = 21;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// 22. If needFd is true, then
|
|
111
|
+
if (needFd) {
|
|
112
|
+
// 22.a. If hasFd is true, then
|
|
113
|
+
if (hasFd) {
|
|
114
|
+
// 22.a.i. Set mnfd to ? DefaultNumberOption(mnfd, 0, 100, undefined).
|
|
115
|
+
mnfd = DefaultNumberOption(mnfd, 0, 100, undefined);
|
|
116
|
+
// 22.a.ii. Set mxfd to ? DefaultNumberOption(mxfd, 0, 100, undefined).
|
|
117
|
+
mxfd = DefaultNumberOption(mxfd, 0, 100, undefined);
|
|
118
|
+
// 22.a.iii. If mnfd is undefined, then
|
|
119
|
+
if (mnfd === undefined) {
|
|
120
|
+
// 22.a.iii.1. Assert: mxfd is not undefined.
|
|
121
|
+
invariant(mxfd !== undefined, "maximumFractionDigits must be defined");
|
|
122
|
+
// 22.a.iii.2. Set mnfd to min(mnfdDefault, mxfd).
|
|
123
|
+
mnfd = Math.min(mnfdDefault, mxfd);
|
|
124
|
+
} else if (mxfd === undefined) {
|
|
125
|
+
// 22.a.iv. Else if mxfd is undefined, then
|
|
126
|
+
// 22.a.iv.1. Set mxfd to max(mxfdDefault, mnfd).
|
|
127
|
+
mxfd = Math.max(mxfdDefault, mnfd);
|
|
128
|
+
} else if (mnfd > mxfd) {
|
|
129
|
+
// 22.a.v. Else if mnfd > mxfd, throw a RangeError exception.
|
|
130
|
+
throw new RangeError(`Invalid range, ${mnfd} > ${mxfd}`);
|
|
131
|
+
}
|
|
132
|
+
// 22.a.vi. Set internalSlots.[[MinimumFractionDigits]] to mnfd.
|
|
133
|
+
internalSlots.minimumFractionDigits = mnfd;
|
|
134
|
+
// 22.a.vii. Set internalSlots.[[MaximumFractionDigits]] to mxfd.
|
|
135
|
+
internalSlots.maximumFractionDigits = mxfd;
|
|
136
|
+
} else {
|
|
137
|
+
// 22.b. Else,
|
|
138
|
+
// 22.b.i. Set internalSlots.[[MinimumFractionDigits]] to mnfdDefault.
|
|
139
|
+
internalSlots.minimumFractionDigits = mnfdDefault;
|
|
140
|
+
// 22.b.ii. Set internalSlots.[[MaximumFractionDigits]] to mxfdDefault.
|
|
141
|
+
internalSlots.maximumFractionDigits = mxfdDefault;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// 23. If needSd is false and needFd is false, then
|
|
145
|
+
if (!needSd && !needFd) {
|
|
146
|
+
// 23.a. Set internalSlots.[[MinimumFractionDigits]] to 0.
|
|
147
|
+
internalSlots.minimumFractionDigits = 0;
|
|
148
|
+
// 23.b. Set internalSlots.[[MaximumFractionDigits]] to 0.
|
|
149
|
+
internalSlots.maximumFractionDigits = 0;
|
|
150
|
+
// 23.c. Set internalSlots.[[MinimumSignificantDigits]] to 1.
|
|
151
|
+
internalSlots.minimumSignificantDigits = 1;
|
|
152
|
+
// 23.d. Set internalSlots.[[MaximumSignificantDigits]] to 2.
|
|
153
|
+
internalSlots.maximumSignificantDigits = 2;
|
|
154
|
+
// 23.e. Set internalSlots.[[RoundingType]] to "morePrecision".
|
|
155
|
+
internalSlots.roundingType = "morePrecision";
|
|
156
|
+
// 23.f. Set internalSlots.[[RoundingPriority]] to "morePrecision".
|
|
157
|
+
internalSlots.roundingPriority = "morePrecision";
|
|
158
|
+
} else if (roundingPriority === "morePrecision") {
|
|
159
|
+
// 24. Else if roundingPriority is "morePrecision", then
|
|
160
|
+
// 24.a. Set internalSlots.[[RoundingType]] to "morePrecision".
|
|
161
|
+
internalSlots.roundingType = "morePrecision";
|
|
162
|
+
// 24.b. Set internalSlots.[[RoundingPriority]] to "morePrecision".
|
|
163
|
+
internalSlots.roundingPriority = "morePrecision";
|
|
164
|
+
} else if (roundingPriority === "lessPrecision") {
|
|
165
|
+
// 25. Else if roundingPriority is "lessPrecision", then
|
|
166
|
+
// 25.a. Set internalSlots.[[RoundingType]] to "lessPrecision".
|
|
167
|
+
internalSlots.roundingType = "lessPrecision";
|
|
168
|
+
// 25.b. Set internalSlots.[[RoundingPriority]] to "lessPrecision".
|
|
169
|
+
internalSlots.roundingPriority = "lessPrecision";
|
|
170
|
+
} else if (hasSd) {
|
|
171
|
+
// 26. Else if hasSd is true, then
|
|
172
|
+
// 26.a. Set internalSlots.[[RoundingType]] to "significantDigits".
|
|
173
|
+
internalSlots.roundingType = "significantDigits";
|
|
174
|
+
// 26.b. Set internalSlots.[[RoundingPriority]] to "auto".
|
|
175
|
+
internalSlots.roundingPriority = "auto";
|
|
176
|
+
} else {
|
|
177
|
+
// 27. Else,
|
|
178
|
+
// 27.a. Set internalSlots.[[RoundingType]] to "fractionDigits".
|
|
179
|
+
internalSlots.roundingType = "fractionDigits";
|
|
180
|
+
// 27.b. Set internalSlots.[[RoundingPriority]] to "auto".
|
|
181
|
+
internalSlots.roundingPriority = "auto";
|
|
182
|
+
}
|
|
183
|
+
// 28. If roundingIncrement is not 1, then
|
|
184
|
+
if (roundingIncrement !== 1) {
|
|
185
|
+
// 28.a. Assert: internalSlots.[[RoundingType]] is "fractionDigits".
|
|
186
|
+
invariant(internalSlots.roundingType === "fractionDigits", "Invalid roundingType", TypeError);
|
|
187
|
+
// 28.b. Assert: internalSlots.[[MaximumFractionDigits]] is equal to internalSlots.[[MinimumFractionDigits]].
|
|
188
|
+
invariant(internalSlots.maximumFractionDigits === internalSlots.minimumFractionDigits, "With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.", RangeError);
|
|
189
|
+
}
|
|
179
190
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NumberFormatInternal, NumberFormatOptions } from
|
|
1
|
+
import { type NumberFormatInternal, type NumberFormatOptions } from "../types/number.js";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
* https://tc39.es/ecma402/#sec-setnumberformatunitoptions
|
|
4
|
+
*/
|
|
5
5
|
export declare function SetNumberFormatUnitOptions(internalSlots: NumberFormatInternal, options?: NumberFormatOptions | undefined): void;
|
|
@@ -1,50 +1,64 @@
|
|
|
1
|
-
import { GetOption } from
|
|
2
|
-
import { IsWellFormedCurrencyCode } from
|
|
3
|
-
import { IsWellFormedUnitIdentifier } from
|
|
4
|
-
import
|
|
1
|
+
import { GetOption } from "../GetOption.js";
|
|
2
|
+
import { IsWellFormedCurrencyCode } from "../IsWellFormedCurrencyCode.js";
|
|
3
|
+
import { IsWellFormedUnitIdentifier } from "../IsWellFormedUnitIdentifier.js";
|
|
4
|
+
import "../types/number.js";
|
|
5
|
+
import { invariant } from "../utils.js";
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export function SetNumberFormatUnitOptions(internalSlots, options) {
|
|
9
|
-
|
|
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
|
-
|
|
7
|
+
* https://tc39.es/ecma402/#sec-setnumberformatunitoptions
|
|
8
|
+
*/
|
|
9
|
+
export function SetNumberFormatUnitOptions(internalSlots, options = Object.create(null)) {
|
|
10
|
+
// 1. Let style be ? GetOption(options, "style", "string", « "decimal", "percent", "currency", "unit" », "decimal").
|
|
11
|
+
const style = GetOption(options, "style", "string", [
|
|
12
|
+
"decimal",
|
|
13
|
+
"percent",
|
|
14
|
+
"currency",
|
|
15
|
+
"unit"
|
|
16
|
+
], "decimal");
|
|
17
|
+
// 2. Set internalSlots.[[Style]] to style.
|
|
18
|
+
internalSlots.style = style;
|
|
19
|
+
// 3. Let currency be ? GetOption(options, "currency", "string", undefined, undefined).
|
|
20
|
+
const currency = GetOption(options, "currency", "string", undefined, undefined);
|
|
21
|
+
// 4. If currency is not undefined, then
|
|
22
|
+
// a. If the result of IsWellFormedCurrencyCode(currency) is false, throw a RangeError exception.
|
|
23
|
+
invariant(currency === undefined || IsWellFormedCurrencyCode(currency), "Malformed currency code", RangeError);
|
|
24
|
+
// 5. If style is "currency" and currency is undefined, throw a TypeError exception.
|
|
25
|
+
invariant(style !== "currency" || currency !== undefined, "currency cannot be undefined", TypeError);
|
|
26
|
+
// 6. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", « "code", "symbol", "narrowSymbol", "name" », "symbol").
|
|
27
|
+
const currencyDisplay = GetOption(options, "currencyDisplay", "string", [
|
|
28
|
+
"code",
|
|
29
|
+
"symbol",
|
|
30
|
+
"narrowSymbol",
|
|
31
|
+
"name"
|
|
32
|
+
], "symbol");
|
|
33
|
+
// 7. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard").
|
|
34
|
+
const currencySign = GetOption(options, "currencySign", "string", ["standard", "accounting"], "standard");
|
|
35
|
+
// 8. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
|
|
36
|
+
const unit = GetOption(options, "unit", "string", undefined, undefined);
|
|
37
|
+
// 9. If unit is not undefined, then
|
|
38
|
+
// a. If the result of IsWellFormedUnitIdentifier(unit) is false, throw a RangeError exception.
|
|
39
|
+
invariant(unit === undefined || IsWellFormedUnitIdentifier(unit), "Invalid unit argument for Intl.NumberFormat()", RangeError);
|
|
40
|
+
// 10. If style is "unit" and unit is undefined, throw a TypeError exception.
|
|
41
|
+
invariant(style !== "unit" || unit !== undefined, "unit cannot be undefined", TypeError);
|
|
42
|
+
// 11. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short").
|
|
43
|
+
const unitDisplay = GetOption(options, "unitDisplay", "string", [
|
|
44
|
+
"short",
|
|
45
|
+
"narrow",
|
|
46
|
+
"long"
|
|
47
|
+
], "short");
|
|
48
|
+
// 12. If style is "currency", then
|
|
49
|
+
if (style === "currency") {
|
|
50
|
+
// a. Set internalSlots.[[Currency]] to the result of converting currency to upper case as specified in 6.1.
|
|
51
|
+
internalSlots.currency = currency.toUpperCase();
|
|
52
|
+
// b. Set internalSlots.[[CurrencyDisplay]] to currencyDisplay.
|
|
53
|
+
internalSlots.currencyDisplay = currencyDisplay;
|
|
54
|
+
// c. Set internalSlots.[[CurrencySign]] to currencySign.
|
|
55
|
+
internalSlots.currencySign = currencySign;
|
|
56
|
+
}
|
|
57
|
+
// 13. If style is "unit", then
|
|
58
|
+
if (style === "unit") {
|
|
59
|
+
// a. Set internalSlots.[[Unit]] to unit.
|
|
60
|
+
internalSlots.unit = unit;
|
|
61
|
+
// b. Set internalSlots.[[UnitDisplay]] to unitDisplay.
|
|
62
|
+
internalSlots.unitDisplay = unitDisplay;
|
|
63
|
+
}
|
|
50
64
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import { RawNumberFormatResult, UnsignedRoundingModeType } from
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
import { type RawNumberFormatResult, type UnsignedRoundingModeType } from "../types/number.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
* https://tc39.es/ecma402/#sec-torawfixed
|
|
5
|
+
* @param x a finite non-negative Number or BigInt
|
|
6
|
+
* @param minFraction an integer between 0 and 20
|
|
7
|
+
* @param maxFraction an integer between 0 and 20
|
|
8
|
+
*/
|
|
9
9
|
export declare function ToRawFixed(x: Decimal, minFraction: number, maxFraction: number, roundingIncrement: number, unsignedRoundingMode: UnsignedRoundingModeType): RawNumberFormatResult;
|