@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
package/262.js CHANGED
@@ -1,400 +1,400 @@
1
- import { Decimal } from 'decimal.js';
2
- import { ZERO } from './constants.js';
3
- import { invariant } from './utils.js';
1
+ import { Decimal } from "decimal.js";
2
+ import { ZERO } from "./constants.js";
3
+ import { invariant } from "./utils.js";
4
4
  /**
5
- * https://tc39.es/ecma262/#sec-tostring
6
- */
5
+ * https://tc39.es/ecma262/#sec-tostring
6
+ */
7
7
  export function ToString(o) {
8
- // Only symbol is irregular...
9
- if (typeof o === 'symbol') {
10
- throw TypeError('Cannot convert a Symbol value to a string');
11
- }
12
- return String(o);
8
+ // Only symbol is irregular...
9
+ if (typeof o === "symbol") {
10
+ throw TypeError("Cannot convert a Symbol value to a string");
11
+ }
12
+ return String(o);
13
13
  }
14
14
  /**
15
- * https://tc39.es/ecma262/#sec-tonumber
16
- * @param val
17
- */
15
+ * https://tc39.es/ecma262/#sec-tonumber
16
+ * @param val
17
+ */
18
18
  export function ToNumber(arg) {
19
- if (typeof arg === 'number') {
20
- return new Decimal(arg);
21
- }
22
- invariant(typeof arg !== 'bigint' && typeof arg !== 'symbol', 'BigInt and Symbol are not supported', TypeError);
23
- if (arg === undefined) {
24
- return new Decimal(NaN);
25
- }
26
- if (arg === null || arg === 0) {
27
- return ZERO;
28
- }
29
- if (arg === true) {
30
- return new Decimal(1);
31
- }
32
- if (typeof arg === 'string') {
33
- try {
34
- return new Decimal(arg);
35
- }
36
- catch (_a) {
37
- return new Decimal(NaN);
38
- }
39
- }
40
- invariant(typeof arg === 'object', 'object expected', TypeError);
41
- var primValue = ToPrimitive(arg, 'number');
42
- invariant(typeof primValue !== 'object', 'object expected', TypeError);
43
- return ToNumber(primValue);
19
+ if (typeof arg === "number") {
20
+ return new Decimal(arg);
21
+ }
22
+ // Support bigint values by converting to string first
23
+ // https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.select
24
+ if (typeof arg === "bigint") {
25
+ return new Decimal(arg.toString());
26
+ }
27
+ invariant(typeof arg !== "symbol", "Symbol is not supported", TypeError);
28
+ if (arg === undefined) {
29
+ return new Decimal(NaN);
30
+ }
31
+ if (arg === null || arg === 0) {
32
+ return ZERO;
33
+ }
34
+ if (arg === true) {
35
+ return new Decimal(1);
36
+ }
37
+ if (typeof arg === "string") {
38
+ try {
39
+ return new Decimal(arg);
40
+ } catch {
41
+ return new Decimal(NaN);
42
+ }
43
+ }
44
+ invariant(typeof arg === "object", "object expected", TypeError);
45
+ let primValue = ToPrimitive(arg, "number");
46
+ invariant(typeof primValue !== "object", "object expected", TypeError);
47
+ return ToNumber(primValue);
44
48
  }
45
49
  /**
46
- * https://tc39.es/ecma262/#sec-tointeger
47
- * @param n
48
- */
50
+ * https://tc39.es/ecma262/#sec-tointeger
51
+ * @param n
52
+ */
49
53
  function ToInteger(n) {
50
- var number = ToNumber(n);
51
- if (number.isNaN() || number.isZero()) {
52
- return ZERO;
53
- }
54
- if (number.isFinite()) {
55
- return number;
56
- }
57
- var integer = number.abs().floor();
58
- if (number.isNegative()) {
59
- integer = integer.negated();
60
- }
61
- return integer;
54
+ const number = ToNumber(n);
55
+ if (number.isNaN() || number.isZero()) {
56
+ return ZERO;
57
+ }
58
+ if (number.isFinite()) {
59
+ return number;
60
+ }
61
+ let integer = number.abs().floor();
62
+ if (number.isNegative()) {
63
+ integer = integer.negated();
64
+ }
65
+ return integer;
62
66
  }
63
67
  /**
64
- * https://tc39.es/ecma262/#sec-timeclip
65
- * @param time
66
- */
68
+ * https://tc39.es/ecma262/#sec-timeclip
69
+ * @param time
70
+ */
67
71
  export function TimeClip(time) {
68
- if (!time.isFinite()) {
69
- return new Decimal(NaN);
70
- }
71
- if (time.abs().greaterThan(8.64 * 1e15)) {
72
- return new Decimal(NaN);
73
- }
74
- return ToInteger(time);
72
+ if (!time.isFinite()) {
73
+ return new Decimal(NaN);
74
+ }
75
+ if (time.abs().greaterThan(8.64 * 0x38d7ea4c68000)) {
76
+ return new Decimal(NaN);
77
+ }
78
+ return ToInteger(time);
75
79
  }
76
80
  /**
77
- * https://tc39.es/ecma262/#sec-toobject
78
- * @param arg
79
- */
81
+ * https://tc39.es/ecma262/#sec-toobject
82
+ * @param arg
83
+ */
80
84
  export function ToObject(arg) {
81
- if (arg == null) {
82
- throw new TypeError('undefined/null cannot be converted to object');
83
- }
84
- return Object(arg);
85
+ if (arg == null) {
86
+ throw new TypeError("undefined/null cannot be converted to object");
87
+ }
88
+ return Object(arg);
85
89
  }
86
90
  /**
87
- * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-samevalue
88
- * @param x
89
- * @param y
90
- */
91
+ * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-samevalue
92
+ * @param x
93
+ * @param y
94
+ */
91
95
  export function SameValue(x, y) {
92
- if (Object.is) {
93
- return Object.is(x, y);
94
- }
95
- // SameValue algorithm
96
- if (x === y) {
97
- // Steps 1-5, 7-10
98
- // Steps 6.b-6.e: +0 != -0
99
- return x !== 0 || 1 / x === 1 / y;
100
- }
101
- // Step 6.a: NaN == NaN
102
- return x !== x && y !== y;
96
+ if (Object.is) {
97
+ return Object.is(x, y);
98
+ }
99
+ // SameValue algorithm
100
+ if (x === y) {
101
+ // Steps 1-5, 7-10
102
+ // Steps 6.b-6.e: +0 != -0
103
+ return x !== 0 || 1 / x === 1 / y;
104
+ }
105
+ // Step 6.a: NaN == NaN
106
+ return x !== x && y !== y;
103
107
  }
104
108
  /**
105
- * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-arraycreate
106
- * @param len
107
- */
109
+ * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-arraycreate
110
+ * @param len
111
+ */
108
112
  export function ArrayCreate(len) {
109
- return Array.from({ length: len });
113
+ return Array.from({ length: len });
110
114
  }
111
115
  /**
112
- * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-hasownproperty
113
- * @param o
114
- * @param prop
115
- */
116
+ * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-hasownproperty
117
+ * @param o
118
+ * @param prop
119
+ */
116
120
  export function HasOwnProperty(o, prop) {
117
- return Object.prototype.hasOwnProperty.call(o, prop);
121
+ return Object.prototype.hasOwnProperty.call(o, prop);
118
122
  }
119
123
  /**
120
- * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-type
121
- * @param x
122
- */
124
+ * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-type
125
+ * @param x
126
+ */
123
127
  export function Type(x) {
124
- if (x === null) {
125
- return 'Null';
126
- }
127
- if (typeof x === 'undefined') {
128
- return 'Undefined';
129
- }
130
- if (typeof x === 'function' || typeof x === 'object') {
131
- return 'Object';
132
- }
133
- if (typeof x === 'number') {
134
- return 'Number';
135
- }
136
- if (typeof x === 'boolean') {
137
- return 'Boolean';
138
- }
139
- if (typeof x === 'string') {
140
- return 'String';
141
- }
142
- if (typeof x === 'symbol') {
143
- return 'Symbol';
144
- }
145
- if (typeof x === 'bigint') {
146
- return 'BigInt';
147
- }
128
+ if (x === null) {
129
+ return "Null";
130
+ }
131
+ if (typeof x === "undefined") {
132
+ return "Undefined";
133
+ }
134
+ if (typeof x === "function" || typeof x === "object") {
135
+ return "Object";
136
+ }
137
+ if (typeof x === "number") {
138
+ return "Number";
139
+ }
140
+ if (typeof x === "boolean") {
141
+ return "Boolean";
142
+ }
143
+ if (typeof x === "string") {
144
+ return "String";
145
+ }
146
+ if (typeof x === "symbol") {
147
+ return "Symbol";
148
+ }
149
+ if (typeof x === "bigint") {
150
+ return "BigInt";
151
+ }
148
152
  }
149
- var MS_PER_DAY = 86400000;
153
+ const MS_PER_DAY = 864e5;
150
154
  /**
151
- * https://www.ecma-international.org/ecma-262/11.0/index.html#eqn-modulo
152
- * @param x
153
- * @param y
154
- * @return k of the same sign as y
155
- */
155
+ * https://www.ecma-international.org/ecma-262/11.0/index.html#eqn-modulo
156
+ * @param x
157
+ * @param y
158
+ * @return k of the same sign as y
159
+ */
156
160
  function mod(x, y) {
157
- return x - Math.floor(x / y) * y;
161
+ return x - Math.floor(x / y) * y;
158
162
  }
159
163
  /**
160
- * https://tc39.es/ecma262/#eqn-Day
161
- * @param t
162
- */
164
+ * https://tc39.es/ecma262/#eqn-Day
165
+ * @param t
166
+ */
163
167
  export function Day(t) {
164
- return Math.floor(t / MS_PER_DAY);
168
+ return Math.floor(t / MS_PER_DAY);
165
169
  }
166
170
  /**
167
- * https://tc39.es/ecma262/#sec-week-day
168
- * @param t
169
- */
171
+ * https://tc39.es/ecma262/#sec-week-day
172
+ * @param t
173
+ */
170
174
  export function WeekDay(t) {
171
- return mod(Day(t) + 4, 7);
175
+ return mod(Day(t) + 4, 7);
172
176
  }
173
177
  /**
174
- * https://tc39.es/ecma262/#sec-year-number
175
- * @param y
176
- */
178
+ * https://tc39.es/ecma262/#sec-year-number
179
+ * @param y
180
+ */
177
181
  export function DayFromYear(y) {
178
- if (y < 100) {
179
- // Date.UTC parses 0 - 99 as 1900 - 1999
180
- var date = new Date(0);
181
- date.setUTCFullYear(y, 0, 1);
182
- date.setUTCHours(0, 0, 0, 0);
183
- return date.getTime() / MS_PER_DAY;
184
- }
185
- return Date.UTC(y, 0) / MS_PER_DAY;
182
+ if (y < 100) {
183
+ // Date.UTC parses 0 - 99 as 1900 - 1999
184
+ const date = new Date(0);
185
+ date.setUTCFullYear(y, 0, 1);
186
+ date.setUTCHours(0, 0, 0, 0);
187
+ return date.getTime() / MS_PER_DAY;
188
+ }
189
+ return Date.UTC(y, 0) / MS_PER_DAY;
186
190
  }
187
191
  /**
188
- * https://tc39.es/ecma262/#sec-year-number
189
- * @param y
190
- */
192
+ * https://tc39.es/ecma262/#sec-year-number
193
+ * @param y
194
+ */
191
195
  export function TimeFromYear(y) {
192
- return Date.UTC(y, 0);
196
+ return Date.UTC(y, 0);
193
197
  }
194
198
  /**
195
- * https://tc39.es/ecma262/#sec-year-number
196
- * @param t
197
- */
199
+ * https://tc39.es/ecma262/#sec-year-number
200
+ * @param t
201
+ */
198
202
  export function YearFromTime(t) {
199
- return new Date(t).getUTCFullYear();
203
+ return new Date(t).getUTCFullYear();
200
204
  }
201
205
  export function DaysInYear(y) {
202
- if (y % 4 !== 0) {
203
- return 365;
204
- }
205
- if (y % 100 !== 0) {
206
- return 366;
207
- }
208
- if (y % 400 !== 0) {
209
- return 365;
210
- }
211
- return 366;
206
+ if (y % 4 !== 0) {
207
+ return 365;
208
+ }
209
+ if (y % 100 !== 0) {
210
+ return 366;
211
+ }
212
+ if (y % 400 !== 0) {
213
+ return 365;
214
+ }
215
+ return 366;
212
216
  }
213
217
  export function DayWithinYear(t) {
214
- return Day(t) - DayFromYear(YearFromTime(t));
218
+ return Day(t) - DayFromYear(YearFromTime(t));
215
219
  }
216
220
  export function InLeapYear(t) {
217
- return DaysInYear(YearFromTime(t)) === 365 ? 0 : 1;
221
+ return DaysInYear(YearFromTime(t)) === 365 ? 0 : 1;
218
222
  }
219
223
  /**
220
- * https://tc39.es/ecma262/#sec-month-number
221
- * @param t
222
- */
224
+ * https://tc39.es/ecma262/#sec-month-number
225
+ * @param t
226
+ */
223
227
  export function MonthFromTime(t) {
224
- var dwy = DayWithinYear(t);
225
- var leap = InLeapYear(t);
226
- if (dwy >= 0 && dwy < 31) {
227
- return 0;
228
- }
229
- if (dwy < 59 + leap) {
230
- return 1;
231
- }
232
- if (dwy < 90 + leap) {
233
- return 2;
234
- }
235
- if (dwy < 120 + leap) {
236
- return 3;
237
- }
238
- if (dwy < 151 + leap) {
239
- return 4;
240
- }
241
- if (dwy < 181 + leap) {
242
- return 5;
243
- }
244
- if (dwy < 212 + leap) {
245
- return 6;
246
- }
247
- if (dwy < 243 + leap) {
248
- return 7;
249
- }
250
- if (dwy < 273 + leap) {
251
- return 8;
252
- }
253
- if (dwy < 304 + leap) {
254
- return 9;
255
- }
256
- if (dwy < 334 + leap) {
257
- return 10;
258
- }
259
- if (dwy < 365 + leap) {
260
- return 11;
261
- }
262
- throw new Error('Invalid time');
228
+ const dwy = DayWithinYear(t);
229
+ const leap = InLeapYear(t);
230
+ if (dwy >= 0 && dwy < 31) {
231
+ return 0;
232
+ }
233
+ if (dwy < 59 + leap) {
234
+ return 1;
235
+ }
236
+ if (dwy < 90 + leap) {
237
+ return 2;
238
+ }
239
+ if (dwy < 120 + leap) {
240
+ return 3;
241
+ }
242
+ if (dwy < 151 + leap) {
243
+ return 4;
244
+ }
245
+ if (dwy < 181 + leap) {
246
+ return 5;
247
+ }
248
+ if (dwy < 212 + leap) {
249
+ return 6;
250
+ }
251
+ if (dwy < 243 + leap) {
252
+ return 7;
253
+ }
254
+ if (dwy < 273 + leap) {
255
+ return 8;
256
+ }
257
+ if (dwy < 304 + leap) {
258
+ return 9;
259
+ }
260
+ if (dwy < 334 + leap) {
261
+ return 10;
262
+ }
263
+ if (dwy < 365 + leap) {
264
+ return 11;
265
+ }
266
+ throw new Error("Invalid time");
263
267
  }
264
268
  export function DateFromTime(t) {
265
- var dwy = DayWithinYear(t);
266
- var mft = MonthFromTime(t);
267
- var leap = InLeapYear(t);
268
- if (mft === 0) {
269
- return dwy + 1;
270
- }
271
- if (mft === 1) {
272
- return dwy - 30;
273
- }
274
- if (mft === 2) {
275
- return dwy - 58 - leap;
276
- }
277
- if (mft === 3) {
278
- return dwy - 89 - leap;
279
- }
280
- if (mft === 4) {
281
- return dwy - 119 - leap;
282
- }
283
- if (mft === 5) {
284
- return dwy - 150 - leap;
285
- }
286
- if (mft === 6) {
287
- return dwy - 180 - leap;
288
- }
289
- if (mft === 7) {
290
- return dwy - 211 - leap;
291
- }
292
- if (mft === 8) {
293
- return dwy - 242 - leap;
294
- }
295
- if (mft === 9) {
296
- return dwy - 272 - leap;
297
- }
298
- if (mft === 10) {
299
- return dwy - 303 - leap;
300
- }
301
- if (mft === 11) {
302
- return dwy - 333 - leap;
303
- }
304
- throw new Error('Invalid time');
269
+ const dwy = DayWithinYear(t);
270
+ const mft = MonthFromTime(t);
271
+ const leap = InLeapYear(t);
272
+ if (mft === 0) {
273
+ return dwy + 1;
274
+ }
275
+ if (mft === 1) {
276
+ return dwy - 30;
277
+ }
278
+ if (mft === 2) {
279
+ return dwy - 58 - leap;
280
+ }
281
+ if (mft === 3) {
282
+ return dwy - 89 - leap;
283
+ }
284
+ if (mft === 4) {
285
+ return dwy - 119 - leap;
286
+ }
287
+ if (mft === 5) {
288
+ return dwy - 150 - leap;
289
+ }
290
+ if (mft === 6) {
291
+ return dwy - 180 - leap;
292
+ }
293
+ if (mft === 7) {
294
+ return dwy - 211 - leap;
295
+ }
296
+ if (mft === 8) {
297
+ return dwy - 242 - leap;
298
+ }
299
+ if (mft === 9) {
300
+ return dwy - 272 - leap;
301
+ }
302
+ if (mft === 10) {
303
+ return dwy - 303 - leap;
304
+ }
305
+ if (mft === 11) {
306
+ return dwy - 333 - leap;
307
+ }
308
+ throw new Error("Invalid time");
305
309
  }
306
- var HOURS_PER_DAY = 24;
307
- var MINUTES_PER_HOUR = 60;
308
- var SECONDS_PER_MINUTE = 60;
309
- var MS_PER_SECOND = 1e3;
310
- var MS_PER_MINUTE = MS_PER_SECOND * SECONDS_PER_MINUTE;
311
- var MS_PER_HOUR = MS_PER_MINUTE * MINUTES_PER_HOUR;
310
+ const HOURS_PER_DAY = 24;
311
+ const MINUTES_PER_HOUR = 60;
312
+ const SECONDS_PER_MINUTE = 60;
313
+ const MS_PER_SECOND = 1e3;
314
+ const MS_PER_MINUTE = MS_PER_SECOND * SECONDS_PER_MINUTE;
315
+ const MS_PER_HOUR = MS_PER_MINUTE * MINUTES_PER_HOUR;
312
316
  export function HourFromTime(t) {
313
- return mod(Math.floor(t / MS_PER_HOUR), HOURS_PER_DAY);
317
+ return mod(Math.floor(t / MS_PER_HOUR), HOURS_PER_DAY);
314
318
  }
315
319
  export function MinFromTime(t) {
316
- return mod(Math.floor(t / MS_PER_MINUTE), MINUTES_PER_HOUR);
320
+ return mod(Math.floor(t / MS_PER_MINUTE), MINUTES_PER_HOUR);
317
321
  }
318
322
  export function SecFromTime(t) {
319
- return mod(Math.floor(t / MS_PER_SECOND), SECONDS_PER_MINUTE);
323
+ return mod(Math.floor(t / MS_PER_SECOND), SECONDS_PER_MINUTE);
320
324
  }
321
325
  function IsCallable(fn) {
322
- return typeof fn === 'function';
326
+ return typeof fn === "function";
323
327
  }
324
328
  /**
325
- * The abstract operation OrdinaryHasInstance implements
326
- * the default algorithm for determining if an object O
327
- * inherits from the instance object inheritance path
328
- * provided by constructor C.
329
- * @param C class
330
- * @param O object
331
- * @param internalSlots internalSlots
332
- */
329
+ * The abstract operation OrdinaryHasInstance implements
330
+ * the default algorithm for determining if an object O
331
+ * inherits from the instance object inheritance path
332
+ * provided by constructor C.
333
+ * @param C class
334
+ * @param O object
335
+ * @param internalSlots internalSlots
336
+ */
333
337
  export function OrdinaryHasInstance(C, O, internalSlots) {
334
- if (!IsCallable(C)) {
335
- return false;
336
- }
337
- if (internalSlots === null || internalSlots === void 0 ? void 0 : internalSlots.boundTargetFunction) {
338
- var BC = internalSlots === null || internalSlots === void 0 ? void 0 : internalSlots.boundTargetFunction;
339
- return O instanceof BC;
340
- }
341
- if (typeof O !== 'object') {
342
- return false;
343
- }
344
- var P = C.prototype;
345
- if (typeof P !== 'object') {
346
- throw new TypeError('OrdinaryHasInstance called on an object with an invalid prototype property.');
347
- }
348
- return Object.prototype.isPrototypeOf.call(P, O);
338
+ if (!IsCallable(C)) {
339
+ return false;
340
+ }
341
+ if (internalSlots?.boundTargetFunction) {
342
+ let BC = internalSlots?.boundTargetFunction;
343
+ return O instanceof BC;
344
+ }
345
+ if (typeof O !== "object") {
346
+ return false;
347
+ }
348
+ let P = C.prototype;
349
+ if (typeof P !== "object") {
350
+ throw new TypeError("OrdinaryHasInstance called on an object with an invalid prototype property.");
351
+ }
352
+ return Object.prototype.isPrototypeOf.call(P, O);
349
353
  }
350
354
  export function msFromTime(t) {
351
- return mod(t, MS_PER_SECOND);
355
+ return mod(t, MS_PER_SECOND);
352
356
  }
353
357
  function OrdinaryToPrimitive(O, hint) {
354
- var methodNames;
355
- if (hint === 'string') {
356
- methodNames = ['toString', 'valueOf'];
357
- }
358
- else {
359
- methodNames = ['valueOf', 'toString'];
360
- }
361
- for (var _i = 0, methodNames_1 = methodNames; _i < methodNames_1.length; _i++) {
362
- var name_1 = methodNames_1[_i];
363
- var method = O[name_1];
364
- if (IsCallable(method)) {
365
- var result = method.call(O);
366
- if (typeof result !== 'object') {
367
- return result;
368
- }
369
- }
370
- }
371
- throw new TypeError('Cannot convert object to primitive value');
358
+ let methodNames;
359
+ if (hint === "string") {
360
+ methodNames = ["toString", "valueOf"];
361
+ } else {
362
+ methodNames = ["valueOf", "toString"];
363
+ }
364
+ for (const name of methodNames) {
365
+ const method = O[name];
366
+ if (IsCallable(method)) {
367
+ let result = method.call(O);
368
+ if (typeof result !== "object") {
369
+ return result;
370
+ }
371
+ }
372
+ }
373
+ throw new TypeError("Cannot convert object to primitive value");
372
374
  }
373
375
  export function ToPrimitive(input, preferredType) {
374
- if (typeof input === 'object' && input != null) {
375
- var exoticToPrim = Symbol.toPrimitive in input ? input[Symbol.toPrimitive] : undefined;
376
- var hint = void 0;
377
- if (exoticToPrim !== undefined) {
378
- if (preferredType === undefined) {
379
- hint = 'default';
380
- }
381
- else if (preferredType === 'string') {
382
- hint = 'string';
383
- }
384
- else {
385
- invariant(preferredType === 'number', 'preferredType must be "string" or "number"');
386
- hint = 'number';
387
- }
388
- var result = exoticToPrim.call(input, hint);
389
- if (typeof result !== 'object') {
390
- return result;
391
- }
392
- throw new TypeError('Cannot convert exotic object to primitive.');
393
- }
394
- if (preferredType === undefined) {
395
- preferredType = 'number';
396
- }
397
- return OrdinaryToPrimitive(input, preferredType);
398
- }
399
- return input;
376
+ if (typeof input === "object" && input != null) {
377
+ const exoticToPrim = Symbol.toPrimitive in input ? input[Symbol.toPrimitive] : undefined;
378
+ let hint;
379
+ if (exoticToPrim !== undefined) {
380
+ if (preferredType === undefined) {
381
+ hint = "default";
382
+ } else if (preferredType === "string") {
383
+ hint = "string";
384
+ } else {
385
+ invariant(preferredType === "number", "preferredType must be \"string\" or \"number\"");
386
+ hint = "number";
387
+ }
388
+ let result = exoticToPrim.call(input, hint);
389
+ if (typeof result !== "object") {
390
+ return result;
391
+ }
392
+ throw new TypeError("Cannot convert exotic object to primitive.");
393
+ }
394
+ if (preferredType === undefined) {
395
+ preferredType = "number";
396
+ }
397
+ return OrdinaryToPrimitive(input, preferredType);
398
+ }
399
+ return input;
400
400
  }