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