@formatjs/ecma402-abstract 2.3.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/262.d.ts +1 -1
  2. package/262.js +42 -68
  3. package/CanonicalizeLocaleList.js +1 -4
  4. package/CanonicalizeTimeZoneName.js +1 -4
  5. package/CoerceOptionsToObject.js +3 -6
  6. package/DefaultNumberOption.js +1 -4
  7. package/GetNumberOption.js +3 -6
  8. package/GetOption.js +3 -6
  9. package/GetOptionsObject.js +1 -4
  10. package/GetStringOrBooleanOption.js +3 -6
  11. package/IsSanctionedSimpleUnitIdentifier.js +5 -10
  12. package/IsValidTimeZoneName.js +1 -4
  13. package/IsWellFormedCurrencyCode.js +1 -4
  14. package/IsWellFormedUnitIdentifier.js +5 -8
  15. package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -2
  16. package/NumberFormat/ApplyUnsignedRoundingMode.js +5 -8
  17. package/NumberFormat/CollapseNumberRange.d.ts +1 -1
  18. package/NumberFormat/CollapseNumberRange.js +1 -4
  19. package/NumberFormat/ComputeExponent.d.ts +2 -2
  20. package/NumberFormat/ComputeExponent.js +8 -12
  21. package/NumberFormat/ComputeExponentForMagnitude.d.ts +2 -2
  22. package/NumberFormat/ComputeExponentForMagnitude.js +6 -10
  23. package/NumberFormat/CurrencyDigits.js +3 -6
  24. package/NumberFormat/FormatApproximately.d.ts +1 -1
  25. package/NumberFormat/FormatApproximately.js +1 -4
  26. package/NumberFormat/FormatNumeric.d.ts +2 -2
  27. package/NumberFormat/FormatNumeric.js +3 -6
  28. package/NumberFormat/FormatNumericRange.d.ts +2 -2
  29. package/NumberFormat/FormatNumericRange.js +3 -6
  30. package/NumberFormat/FormatNumericRangeToParts.d.ts +2 -2
  31. package/NumberFormat/FormatNumericRangeToParts.js +3 -6
  32. package/NumberFormat/FormatNumericToParts.d.ts +2 -2
  33. package/NumberFormat/FormatNumericToParts.js +5 -8
  34. package/NumberFormat/FormatNumericToString.d.ts +2 -2
  35. package/NumberFormat/FormatNumericToString.js +16 -19
  36. package/NumberFormat/GetUnsignedRoundingMode.d.ts +1 -1
  37. package/NumberFormat/GetUnsignedRoundingMode.js +1 -4
  38. package/NumberFormat/InitializeNumberFormat.d.ts +1 -1
  39. package/NumberFormat/InitializeNumberFormat.js +23 -26
  40. package/NumberFormat/PartitionNumberPattern.d.ts +2 -2
  41. package/NumberFormat/PartitionNumberPattern.js +12 -16
  42. package/NumberFormat/PartitionNumberRangePattern.d.ts +2 -2
  43. package/NumberFormat/PartitionNumberRangePattern.js +12 -15
  44. package/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
  45. package/NumberFormat/SetNumberFormatDigitOptions.js +18 -21
  46. package/NumberFormat/SetNumberFormatUnitOptions.d.ts +1 -1
  47. package/NumberFormat/SetNumberFormatUnitOptions.js +15 -18
  48. package/NumberFormat/ToRawFixed.d.ts +2 -2
  49. package/NumberFormat/ToRawFixed.js +10 -14
  50. package/NumberFormat/ToRawPrecision.d.ts +2 -2
  51. package/NumberFormat/ToRawPrecision.js +19 -23
  52. package/NumberFormat/digit-mapping.generated.js +1 -4
  53. package/NumberFormat/format_to_parts.d.ts +2 -2
  54. package/NumberFormat/format_to_parts.js +18 -22
  55. package/PartitionPattern.js +3 -6
  56. package/SupportedLocales.js +8 -11
  57. package/ToIntlMathematicalValue.d.ts +1 -1
  58. package/ToIntlMathematicalValue.js +12 -16
  59. package/constants.d.ts +1 -1
  60. package/constants.js +4 -8
  61. package/data.js +3 -6
  62. package/index.d.ts +47 -47
  63. package/index.js +45 -66
  64. package/package.json +13 -11
  65. package/regex.generated.js +1 -4
  66. package/types/core.js +1 -2
  67. package/types/date-time.js +2 -5
  68. package/types/displaynames.d.ts +1 -1
  69. package/types/displaynames.js +1 -2
  70. package/types/list.d.ts +1 -1
  71. package/types/list.js +1 -2
  72. package/types/number.d.ts +3 -3
  73. package/types/number.js +1 -2
  74. package/types/plural-rules.d.ts +2 -2
  75. package/types/plural-rules.js +1 -2
  76. package/types/relative-time.d.ts +2 -2
  77. package/types/relative-time.js +1 -2
  78. package/utils.js +28 -40
  79. package/lib/262.d.ts +0 -93
  80. package/lib/262.js +0 -400
  81. package/lib/CanonicalizeLocaleList.d.ts +0 -5
  82. package/lib/CanonicalizeLocaleList.js +0 -8
  83. package/lib/CanonicalizeTimeZoneName.d.ts +0 -8
  84. package/lib/CanonicalizeTimeZoneName.js +0 -17
  85. package/lib/CoerceOptionsToObject.d.ts +0 -6
  86. package/lib/CoerceOptionsToObject.js +0 -12
  87. package/lib/DefaultNumberOption.d.ts +0 -8
  88. package/lib/DefaultNumberOption.js +0 -18
  89. package/lib/GetNumberOption.d.ts +0 -9
  90. package/lib/GetNumberOption.js +0 -13
  91. package/lib/GetOption.d.ts +0 -9
  92. package/lib/GetOption.js +0 -31
  93. package/lib/GetOptionsObject.d.ts +0 -6
  94. package/lib/GetOptionsObject.js +0 -14
  95. package/lib/GetStringOrBooleanOption.d.ts +0 -10
  96. package/lib/GetStringOrBooleanOption.js +0 -31
  97. package/lib/IsSanctionedSimpleUnitIdentifier.d.ts +0 -13
  98. package/lib/IsSanctionedSimpleUnitIdentifier.js +0 -63
  99. package/lib/IsValidTimeZoneName.d.ts +0 -9
  100. package/lib/IsValidTimeZoneName.js +0 -17
  101. package/lib/IsWellFormedCurrencyCode.d.ts +0 -4
  102. package/lib/IsWellFormedCurrencyCode.js +0 -21
  103. package/lib/IsWellFormedUnitIdentifier.d.ts +0 -5
  104. package/lib/IsWellFormedUnitIdentifier.js +0 -28
  105. package/lib/NumberFormat/ApplyUnsignedRoundingMode.d.ts +0 -3
  106. package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +0 -33
  107. package/lib/NumberFormat/CollapseNumberRange.d.ts +0 -8
  108. package/lib/NumberFormat/CollapseNumberRange.js +0 -50
  109. package/lib/NumberFormat/ComputeExponent.d.ts +0 -10
  110. package/lib/NumberFormat/ComputeExponent.js +0 -34
  111. package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts +0 -8
  112. package/lib/NumberFormat/ComputeExponentForMagnitude.js +0 -65
  113. package/lib/NumberFormat/CurrencyDigits.d.ts +0 -6
  114. package/lib/NumberFormat/CurrencyDigits.js +0 -10
  115. package/lib/NumberFormat/FormatApproximately.d.ts +0 -5
  116. package/lib/NumberFormat/FormatApproximately.js +0 -9
  117. package/lib/NumberFormat/FormatNumeric.d.ts +0 -3
  118. package/lib/NumberFormat/FormatNumeric.js +0 -5
  119. package/lib/NumberFormat/FormatNumericRange.d.ts +0 -8
  120. package/lib/NumberFormat/FormatNumericRange.js +0 -11
  121. package/lib/NumberFormat/FormatNumericRangeToParts.d.ts +0 -8
  122. package/lib/NumberFormat/FormatNumericRangeToParts.js +0 -16
  123. package/lib/NumberFormat/FormatNumericToParts.d.ts +0 -5
  124. package/lib/NumberFormat/FormatNumericToParts.js +0 -14
  125. package/lib/NumberFormat/FormatNumericToString.d.ts +0 -9
  126. package/lib/NumberFormat/FormatNumericToString.js +0 -84
  127. package/lib/NumberFormat/GetUnsignedRoundingMode.d.ts +0 -2
  128. package/lib/NumberFormat/GetUnsignedRoundingMode.js +0 -28
  129. package/lib/NumberFormat/InitializeNumberFormat.d.ts +0 -12
  130. package/lib/NumberFormat/InitializeNumberFormat.js +0 -66
  131. package/lib/NumberFormat/PartitionNumberPattern.d.ts +0 -6
  132. package/lib/NumberFormat/PartitionNumberPattern.js +0 -126
  133. package/lib/NumberFormat/PartitionNumberRangePattern.d.ts +0 -8
  134. package/lib/NumberFormat/PartitionNumberRangePattern.js +0 -40
  135. package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +0 -5
  136. package/lib/NumberFormat/SetNumberFormatDigitOptions.js +0 -179
  137. package/lib/NumberFormat/SetNumberFormatUnitOptions.d.ts +0 -5
  138. package/lib/NumberFormat/SetNumberFormatUnitOptions.js +0 -50
  139. package/lib/NumberFormat/ToRawFixed.d.ts +0 -9
  140. package/lib/NumberFormat/ToRawFixed.js +0 -119
  141. package/lib/NumberFormat/ToRawPrecision.d.ts +0 -9
  142. package/lib/NumberFormat/ToRawPrecision.js +0 -148
  143. package/lib/NumberFormat/digit-mapping.generated.d.ts +0 -1
  144. package/lib/NumberFormat/digit-mapping.generated.js +0 -782
  145. package/lib/NumberFormat/format_to_parts.d.ts +0 -24
  146. package/lib/NumberFormat/format_to_parts.js +0 -447
  147. package/lib/PartitionPattern.d.ts +0 -9
  148. package/lib/PartitionPattern.js +0 -36
  149. package/lib/SupportedLocales.d.ts +0 -9
  150. package/lib/SupportedLocales.js +0 -20
  151. package/lib/ToIntlMathematicalValue.d.ts +0 -2
  152. package/lib/ToIntlMathematicalValue.js +0 -27
  153. package/lib/constants.d.ts +0 -4
  154. package/lib/constants.js +0 -4
  155. package/lib/data.d.ts +0 -5
  156. package/lib/data.js +0 -13
  157. package/lib/index.d.ts +0 -47
  158. package/lib/index.js +0 -45
  159. package/lib/regex.generated.d.ts +0 -1
  160. package/lib/regex.generated.js +0 -2
  161. package/lib/types/core.d.ts +0 -10
  162. package/lib/types/core.js +0 -1
  163. package/lib/types/date-time.d.ts +0 -135
  164. package/lib/types/date-time.js +0 -6
  165. package/lib/types/displaynames.d.ts +0 -65
  166. package/lib/types/displaynames.js +0 -1
  167. package/lib/types/list.d.ts +0 -18
  168. package/lib/types/list.js +0 -1
  169. package/lib/types/number.d.ts +0 -173
  170. package/lib/types/number.js +0 -1
  171. package/lib/types/plural-rules.d.ts +0 -16
  172. package/lib/types/plural-rules.js +0 -1
  173. package/lib/types/relative-time.d.ts +0 -40
  174. package/lib/types/relative-time.js +0 -1
  175. package/lib/utils.d.ts +0 -30
  176. package/lib/utils.js +0 -135
package/lib/262.js DELETED
@@ -1,400 +0,0 @@
1
- import { Decimal } from 'decimal.js';
2
- import { ZERO } from './constants';
3
- import { invariant } from './utils';
4
- /**
5
- * https://tc39.es/ecma262/#sec-tostring
6
- */
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);
13
- }
14
- /**
15
- * https://tc39.es/ecma262/#sec-tonumber
16
- * @param val
17
- */
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 (e) {
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);
44
- }
45
- /**
46
- * https://tc39.es/ecma262/#sec-tointeger
47
- * @param n
48
- */
49
- 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;
62
- }
63
- /**
64
- * https://tc39.es/ecma262/#sec-timeclip
65
- * @param time
66
- */
67
- 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);
75
- }
76
- /**
77
- * https://tc39.es/ecma262/#sec-toobject
78
- * @param arg
79
- */
80
- 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
- }
86
- /**
87
- * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-samevalue
88
- * @param x
89
- * @param y
90
- */
91
- 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;
103
- }
104
- /**
105
- * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-arraycreate
106
- * @param len
107
- */
108
- export function ArrayCreate(len) {
109
- return new Array(len);
110
- }
111
- /**
112
- * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-hasownproperty
113
- * @param o
114
- * @param prop
115
- */
116
- export function HasOwnProperty(o, prop) {
117
- return Object.prototype.hasOwnProperty.call(o, prop);
118
- }
119
- /**
120
- * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-type
121
- * @param x
122
- */
123
- 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
- }
148
- }
149
- var MS_PER_DAY = 86400000;
150
- /**
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
- */
156
- function mod(x, y) {
157
- return x - Math.floor(x / y) * y;
158
- }
159
- /**
160
- * https://tc39.es/ecma262/#eqn-Day
161
- * @param t
162
- */
163
- export function Day(t) {
164
- return Math.floor(t / MS_PER_DAY);
165
- }
166
- /**
167
- * https://tc39.es/ecma262/#sec-week-day
168
- * @param t
169
- */
170
- export function WeekDay(t) {
171
- return mod(Day(t) + 4, 7);
172
- }
173
- /**
174
- * https://tc39.es/ecma262/#sec-year-number
175
- * @param y
176
- */
177
- 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;
186
- }
187
- /**
188
- * https://tc39.es/ecma262/#sec-year-number
189
- * @param y
190
- */
191
- export function TimeFromYear(y) {
192
- return Date.UTC(y, 0);
193
- }
194
- /**
195
- * https://tc39.es/ecma262/#sec-year-number
196
- * @param t
197
- */
198
- export function YearFromTime(t) {
199
- return new Date(t).getUTCFullYear();
200
- }
201
- 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;
212
- }
213
- export function DayWithinYear(t) {
214
- return Day(t) - DayFromYear(YearFromTime(t));
215
- }
216
- export function InLeapYear(t) {
217
- return DaysInYear(YearFromTime(t)) === 365 ? 0 : 1;
218
- }
219
- /**
220
- * https://tc39.es/ecma262/#sec-month-number
221
- * @param t
222
- */
223
- 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');
263
- }
264
- 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');
305
- }
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;
312
- export function HourFromTime(t) {
313
- return mod(Math.floor(t / MS_PER_HOUR), HOURS_PER_DAY);
314
- }
315
- export function MinFromTime(t) {
316
- return mod(Math.floor(t / MS_PER_MINUTE), MINUTES_PER_HOUR);
317
- }
318
- export function SecFromTime(t) {
319
- return mod(Math.floor(t / MS_PER_SECOND), SECONDS_PER_MINUTE);
320
- }
321
- function IsCallable(fn) {
322
- return typeof fn === 'function';
323
- }
324
- /**
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
- */
333
- 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);
349
- }
350
- export function msFromTime(t) {
351
- return mod(t, MS_PER_SECOND);
352
- }
353
- 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');
372
- }
373
- 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;
400
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
3
- * @param locales
4
- */
5
- export declare function CanonicalizeLocaleList(locales?: string | ReadonlyArray<string>): string[];
@@ -1,8 +0,0 @@
1
- /**
2
- * http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
3
- * @param locales
4
- */
5
- export function CanonicalizeLocaleList(locales) {
6
- // TODO
7
- return Intl.getCanonicalLocales(locales);
8
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-canonicalizetimezonename
3
- * @param tz
4
- */
5
- export declare function CanonicalizeTimeZoneName(tz: string, { zoneNames, uppercaseLinks, }: {
6
- zoneNames: readonly string[];
7
- uppercaseLinks: Record<string, string>;
8
- }): string;
@@ -1,17 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-canonicalizetimezonename
3
- * @param tz
4
- */
5
- export function CanonicalizeTimeZoneName(tz, _a) {
6
- var zoneNames = _a.zoneNames, uppercaseLinks = _a.uppercaseLinks;
7
- var uppercasedTz = tz.toUpperCase();
8
- var uppercasedZones = zoneNames.reduce(function (all, z) {
9
- all[z.toUpperCase()] = z;
10
- return all;
11
- }, {});
12
- var ianaTimeZone = uppercaseLinks[uppercasedTz] || uppercasedZones[uppercasedTz];
13
- if (ianaTimeZone === 'Etc/UTC' || ianaTimeZone === 'Etc/GMT') {
14
- return 'UTC';
15
- }
16
- return ianaTimeZone;
17
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-coerceoptionstoobject
3
- * @param options
4
- * @returns
5
- */
6
- export declare function CoerceOptionsToObject<T>(options?: T): T;
@@ -1,12 +0,0 @@
1
- import { ToObject } from './262';
2
- /**
3
- * https://tc39.es/ecma402/#sec-coerceoptionstoobject
4
- * @param options
5
- * @returns
6
- */
7
- export function CoerceOptionsToObject(options) {
8
- if (typeof options === 'undefined') {
9
- return Object.create(null);
10
- }
11
- return ToObject(options);
12
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-defaultnumberoption
3
- * @param val
4
- * @param min
5
- * @param max
6
- * @param fallback
7
- */
8
- export declare function DefaultNumberOption<F extends number | undefined>(inputVal: unknown, min: number, max: number, fallback: F): F extends number ? number : number | undefined;
@@ -1,18 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-defaultnumberoption
3
- * @param val
4
- * @param min
5
- * @param max
6
- * @param fallback
7
- */
8
- export function DefaultNumberOption(inputVal, min, max, fallback) {
9
- if (inputVal === undefined) {
10
- // @ts-expect-error
11
- return fallback;
12
- }
13
- var val = Number(inputVal);
14
- if (isNaN(val) || val < min || val > max) {
15
- throw new RangeError("".concat(val, " is outside of range [").concat(min, ", ").concat(max, "]"));
16
- }
17
- return Math.floor(val);
18
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-getnumberoption
3
- * @param options
4
- * @param property
5
- * @param min
6
- * @param max
7
- * @param fallback
8
- */
9
- export declare function GetNumberOption<T extends object, K extends keyof T, F extends number | undefined>(options: T, property: K, minimum: number, maximum: number, fallback: F): F extends number ? number : number | undefined;
@@ -1,13 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-getnumberoption
3
- * @param options
4
- * @param property
5
- * @param min
6
- * @param max
7
- * @param fallback
8
- */
9
- import { DefaultNumberOption } from './DefaultNumberOption';
10
- export function GetNumberOption(options, property, minimum, maximum, fallback) {
11
- var val = options[property];
12
- return DefaultNumberOption(val, minimum, maximum, fallback);
13
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-getoption
3
- * @param opts
4
- * @param prop
5
- * @param type
6
- * @param values
7
- * @param fallback
8
- */
9
- export declare function GetOption<T extends object, K extends keyof T, F>(opts: T, prop: K, type: 'string' | 'boolean', values: readonly T[K][] | undefined, fallback: F): Exclude<T[K], undefined> | F;
package/lib/GetOption.js DELETED
@@ -1,31 +0,0 @@
1
- import { ToString } from './262';
2
- /**
3
- * https://tc39.es/ecma402/#sec-getoption
4
- * @param opts
5
- * @param prop
6
- * @param type
7
- * @param values
8
- * @param fallback
9
- */
10
- export function GetOption(opts, prop, type, values, fallback) {
11
- if (typeof opts !== 'object') {
12
- throw new TypeError('Options must be an object');
13
- }
14
- var value = opts[prop];
15
- if (value !== undefined) {
16
- if (type !== 'boolean' && type !== 'string') {
17
- throw new TypeError('invalid type');
18
- }
19
- if (type === 'boolean') {
20
- value = Boolean(value);
21
- }
22
- if (type === 'string') {
23
- value = ToString(value);
24
- }
25
- if (values !== undefined && !values.filter(function (val) { return val == value; }).length) {
26
- throw new RangeError("".concat(value, " is not within ").concat(values.join(', ')));
27
- }
28
- return value;
29
- }
30
- return fallback;
31
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-getoptionsobject
3
- * @param options
4
- * @returns
5
- */
6
- export declare function GetOptionsObject<T extends object>(options?: T): T;
@@ -1,14 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-getoptionsobject
3
- * @param options
4
- * @returns
5
- */
6
- export function GetOptionsObject(options) {
7
- if (typeof options === 'undefined') {
8
- return Object.create(null);
9
- }
10
- if (typeof options === 'object') {
11
- return options;
12
- }
13
- throw new TypeError('Options must be an object');
14
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-getstringorbooleanoption
3
- * @param opts
4
- * @param prop
5
- * @param values
6
- * @param trueValue
7
- * @param falsyValue
8
- * @param fallback
9
- */
10
- export declare function GetStringOrBooleanOption<T extends object, K extends keyof T>(opts: T, prop: K, values: T[K][] | undefined, trueValue: T[K] | boolean, falsyValue: T[K] | boolean, fallback: T[K] | boolean): T[K] | boolean;
@@ -1,31 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-getstringorbooleanoption
3
- * @param opts
4
- * @param prop
5
- * @param values
6
- * @param trueValue
7
- * @param falsyValue
8
- * @param fallback
9
- */
10
- import { ToString } from './262';
11
- export function GetStringOrBooleanOption(opts, prop, values, trueValue, falsyValue, fallback) {
12
- var value = opts[prop];
13
- if (value === undefined) {
14
- return fallback;
15
- }
16
- if (value === true) {
17
- return trueValue;
18
- }
19
- var valueBoolean = Boolean(value);
20
- if (valueBoolean === false) {
21
- return falsyValue;
22
- }
23
- value = ToString(value);
24
- if (value === 'true' || value === 'false') {
25
- return fallback;
26
- }
27
- if ((values || []).indexOf(value) === -1) {
28
- throw new RangeError("Invalid value ".concat(value));
29
- }
30
- return value;
31
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
3
- */
4
- export declare const SANCTIONED_UNITS: readonly ["angle-degree", "area-acre", "area-hectare", "concentr-percent", "digital-bit", "digital-byte", "digital-gigabit", "digital-gigabyte", "digital-kilobit", "digital-kilobyte", "digital-megabit", "digital-megabyte", "digital-petabyte", "digital-terabit", "digital-terabyte", "duration-day", "duration-hour", "duration-millisecond", "duration-minute", "duration-month", "duration-second", "duration-week", "duration-year", "length-centimeter", "length-foot", "length-inch", "length-kilometer", "length-meter", "length-mile-scandinavian", "length-mile", "length-millimeter", "length-yard", "mass-gram", "mass-kilogram", "mass-ounce", "mass-pound", "mass-stone", "temperature-celsius", "temperature-fahrenheit", "volume-fluid-ounce", "volume-gallon", "volume-liter", "volume-milliliter"];
5
- export declare function removeUnitNamespace(unit: string): string;
6
- /**
7
- * https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
8
- */
9
- export declare const SIMPLE_UNITS: string[];
10
- /**
11
- * https://tc39.es/ecma402/#sec-issanctionedsimpleunitidentifier
12
- */
13
- export declare function IsSanctionedSimpleUnitIdentifier(unitIdentifier: string): boolean;