@formatjs/ecma402-abstract 1.17.4 → 1.18.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 (59) hide show
  1. package/DefaultNumberOption.d.ts +1 -1
  2. package/DefaultNumberOption.js +16 -8
  3. package/GetNumberOption.d.ts +1 -1
  4. package/GetNumberOption.js +0 -1
  5. package/GetOption.d.ts +1 -1
  6. package/LICENSE.md +1 -1
  7. package/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
  8. package/NumberFormat/SetNumberFormatDigitOptions.js +2 -3
  9. package/lib/262.js +23 -49
  10. package/lib/CanonicalizeLocaleList.js +1 -5
  11. package/lib/CanonicalizeTimeZoneName.js +1 -5
  12. package/lib/CoerceOptionsToObject.js +3 -7
  13. package/lib/DefaultNumberOption.d.ts +1 -1
  14. package/lib/DefaultNumberOption.js +16 -12
  15. package/lib/GetNumberOption.d.ts +1 -1
  16. package/lib/GetNumberOption.js +3 -8
  17. package/lib/GetOption.d.ts +1 -1
  18. package/lib/GetOption.js +3 -7
  19. package/lib/GetOptionsObject.js +1 -5
  20. package/lib/GetStringOrBooleanOption.js +3 -7
  21. package/lib/IsSanctionedSimpleUnitIdentifier.js +5 -10
  22. package/lib/IsValidTimeZoneName.js +1 -5
  23. package/lib/IsWellFormedCurrencyCode.js +1 -5
  24. package/lib/IsWellFormedUnitIdentifier.js +5 -9
  25. package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +1 -5
  26. package/lib/NumberFormat/CollapseNumberRange.js +1 -5
  27. package/lib/NumberFormat/ComputeExponent.js +9 -13
  28. package/lib/NumberFormat/ComputeExponentForMagnitude.js +1 -5
  29. package/lib/NumberFormat/CurrencyDigits.js +3 -7
  30. package/lib/NumberFormat/FormatApproximately.js +1 -5
  31. package/lib/NumberFormat/FormatNumericRange.js +3 -7
  32. package/lib/NumberFormat/FormatNumericRangeToParts.js +3 -7
  33. package/lib/NumberFormat/FormatNumericToParts.js +5 -9
  34. package/lib/NumberFormat/FormatNumericToString.js +11 -15
  35. package/lib/NumberFormat/GetUnsignedRoundingMode.js +1 -5
  36. package/lib/NumberFormat/InitializeNumberFormat.js +27 -31
  37. package/lib/NumberFormat/PartitionNumberPattern.js +11 -16
  38. package/lib/NumberFormat/PartitionNumberRangePattern.js +8 -12
  39. package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
  40. package/lib/NumberFormat/SetNumberFormatDigitOptions.js +11 -16
  41. package/lib/NumberFormat/SetNumberFormatUnitOptions.js +12 -16
  42. package/lib/NumberFormat/ToRawFixed.js +4 -8
  43. package/lib/NumberFormat/ToRawPrecision.js +7 -11
  44. package/lib/NumberFormat/digit-mapping.generated.js +1 -4
  45. package/lib/NumberFormat/format_to_parts.js +8 -11
  46. package/lib/PartitionPattern.js +3 -7
  47. package/lib/SupportedLocales.js +8 -12
  48. package/lib/data.js +3 -7
  49. package/lib/index.js +42 -56
  50. package/lib/regex.generated.js +1 -4
  51. package/lib/types/core.js +1 -2
  52. package/lib/types/date-time.js +2 -5
  53. package/lib/types/displaynames.js +1 -2
  54. package/lib/types/list.js +1 -2
  55. package/lib/types/number.js +1 -2
  56. package/lib/types/plural-rules.js +1 -2
  57. package/lib/types/relative-time.js +1 -2
  58. package/lib/utils.js +10 -22
  59. package/package.json +2 -2
@@ -5,4 +5,4 @@
5
5
  * @param max
6
6
  * @param fallback
7
7
  */
8
- export declare function DefaultNumberOption(val: any, min: number, max: number, fallback: number): number;
8
+ export declare function DefaultNumberOption<F extends number | undefined>(inputVal: unknown, min: number, max: number, fallback: F): F extends number ? number : number | undefined;
@@ -1,14 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultNumberOption = void 0;
4
- function DefaultNumberOption(val, min, max, fallback) {
5
- if (val !== undefined) {
6
- val = Number(val);
7
- if (isNaN(val) || val < min || val > max) {
8
- throw new RangeError("".concat(val, " is outside of range [").concat(min, ", ").concat(max, "]"));
9
- }
10
- return Math.floor(val);
4
+ /**
5
+ * https://tc39.es/ecma402/#sec-defaultnumberoption
6
+ * @param val
7
+ * @param min
8
+ * @param max
9
+ * @param fallback
10
+ */
11
+ function DefaultNumberOption(inputVal, min, max, fallback) {
12
+ if (inputVal === undefined) {
13
+ // @ts-expect-error
14
+ return fallback;
11
15
  }
12
- return fallback;
16
+ var val = Number(inputVal);
17
+ if (isNaN(val) || val < min || val > max) {
18
+ throw new RangeError("".concat(val, " is outside of range [").concat(min, ", ").concat(max, "]"));
19
+ }
20
+ return Math.floor(val);
13
21
  }
14
22
  exports.DefaultNumberOption = DefaultNumberOption;
@@ -6,4 +6,4 @@
6
6
  * @param max
7
7
  * @param fallback
8
8
  */
9
- export declare function GetNumberOption<T extends object, K extends keyof T>(options: T, property: K, minimum: number, maximum: number, fallback: number): number;
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;
@@ -12,7 +12,6 @@ exports.GetNumberOption = void 0;
12
12
  var DefaultNumberOption_1 = require("./DefaultNumberOption");
13
13
  function GetNumberOption(options, property, minimum, maximum, fallback) {
14
14
  var val = options[property];
15
- // @ts-expect-error
16
15
  return (0, DefaultNumberOption_1.DefaultNumberOption)(val, minimum, maximum, fallback);
17
16
  }
18
17
  exports.GetNumberOption = GetNumberOption;
package/GetOption.d.ts CHANGED
@@ -6,4 +6,4 @@
6
6
  * @param values
7
7
  * @param fallback
8
8
  */
9
- export declare function GetOption<T extends object, K extends keyof T, F>(opts: T, prop: K, type: 'string' | 'boolean', values: T[K][] | undefined, fallback: F): Exclude<T[K], undefined> | F;
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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 FormatJS
3
+ Copyright (c) 2023 FormatJS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
@@ -1,4 +1,4 @@
1
- import { NumberFormatDigitOptions, NumberFormatNotation, NumberFormatDigitInternalSlots } from '../types/number';
1
+ import { NumberFormatDigitInternalSlots, NumberFormatDigitOptions, NumberFormatNotation } from '../types/number';
2
2
  /**
3
3
  * https://tc39.es/ecma402/#sec-setnfdigitoptions
4
4
  */
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SetNumberFormatDigitOptions = void 0;
4
- var GetNumberOption_1 = require("../GetNumberOption");
5
4
  var DefaultNumberOption_1 = require("../DefaultNumberOption");
5
+ var GetNumberOption_1 = require("../GetNumberOption");
6
6
  var GetOption_1 = require("../GetOption");
7
7
  /**
8
8
  * https://tc39.es/ecma402/#sec-setnfdigitoptions
@@ -39,11 +39,10 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
39
39
  }
40
40
  if (needFd) {
41
41
  if (hasFd) {
42
- // @ts-expect-error
43
42
  mnfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mnfd, 0, 20, undefined);
44
- // @ts-expect-error
45
43
  mxfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mxfd, 0, 20, undefined);
46
44
  if (mnfd === undefined) {
45
+ // @ts-expect-error
47
46
  mnfd = Math.min(mnfdDefault, mxfd);
48
47
  }
49
48
  else if (mxfd === undefined) {
package/lib/262.js CHANGED
@@ -1,22 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.msFromTime = exports.OrdinaryHasInstance = exports.SecFromTime = exports.MinFromTime = exports.HourFromTime = exports.DateFromTime = exports.MonthFromTime = exports.InLeapYear = exports.DayWithinYear = exports.DaysInYear = exports.YearFromTime = exports.TimeFromYear = exports.DayFromYear = exports.WeekDay = exports.Day = exports.Type = exports.HasOwnProperty = exports.ArrayCreate = exports.SameValue = exports.ToObject = exports.TimeClip = exports.ToNumber = exports.ToString = void 0;
4
1
  /**
5
2
  * https://tc39.es/ecma262/#sec-tostring
6
3
  */
7
- function ToString(o) {
4
+ export function ToString(o) {
8
5
  // Only symbol is irregular...
9
6
  if (typeof o === 'symbol') {
10
7
  throw TypeError('Cannot convert a Symbol value to a string');
11
8
  }
12
9
  return String(o);
13
10
  }
14
- exports.ToString = ToString;
15
11
  /**
16
12
  * https://tc39.es/ecma262/#sec-tonumber
17
13
  * @param val
18
14
  */
19
- function ToNumber(val) {
15
+ export function ToNumber(val) {
20
16
  if (val === undefined) {
21
17
  return NaN;
22
18
  }
@@ -34,7 +30,6 @@ function ToNumber(val) {
34
30
  }
35
31
  return Number(val);
36
32
  }
37
- exports.ToNumber = ToNumber;
38
33
  /**
39
34
  * https://tc39.es/ecma262/#sec-tointeger
40
35
  * @param n
@@ -60,7 +55,7 @@ function ToInteger(n) {
60
55
  * https://tc39.es/ecma262/#sec-timeclip
61
56
  * @param time
62
57
  */
63
- function TimeClip(time) {
58
+ export function TimeClip(time) {
64
59
  if (!isFinite(time)) {
65
60
  return NaN;
66
61
  }
@@ -69,24 +64,22 @@ function TimeClip(time) {
69
64
  }
70
65
  return ToInteger(time);
71
66
  }
72
- exports.TimeClip = TimeClip;
73
67
  /**
74
68
  * https://tc39.es/ecma262/#sec-toobject
75
69
  * @param arg
76
70
  */
77
- function ToObject(arg) {
71
+ export function ToObject(arg) {
78
72
  if (arg == null) {
79
73
  throw new TypeError('undefined/null cannot be converted to object');
80
74
  }
81
75
  return Object(arg);
82
76
  }
83
- exports.ToObject = ToObject;
84
77
  /**
85
78
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-samevalue
86
79
  * @param x
87
80
  * @param y
88
81
  */
89
- function SameValue(x, y) {
82
+ export function SameValue(x, y) {
90
83
  if (Object.is) {
91
84
  return Object.is(x, y);
92
85
  }
@@ -99,29 +92,26 @@ function SameValue(x, y) {
99
92
  // Step 6.a: NaN == NaN
100
93
  return x !== x && y !== y;
101
94
  }
102
- exports.SameValue = SameValue;
103
95
  /**
104
96
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-arraycreate
105
97
  * @param len
106
98
  */
107
- function ArrayCreate(len) {
99
+ export function ArrayCreate(len) {
108
100
  return new Array(len);
109
101
  }
110
- exports.ArrayCreate = ArrayCreate;
111
102
  /**
112
103
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-hasownproperty
113
104
  * @param o
114
105
  * @param prop
115
106
  */
116
- function HasOwnProperty(o, prop) {
107
+ export function HasOwnProperty(o, prop) {
117
108
  return Object.prototype.hasOwnProperty.call(o, prop);
118
109
  }
119
- exports.HasOwnProperty = HasOwnProperty;
120
110
  /**
121
111
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-type
122
112
  * @param x
123
113
  */
124
- function Type(x) {
114
+ export function Type(x) {
125
115
  if (x === null) {
126
116
  return 'Null';
127
117
  }
@@ -147,7 +137,6 @@ function Type(x) {
147
137
  return 'BigInt';
148
138
  }
149
139
  }
150
- exports.Type = Type;
151
140
  var MS_PER_DAY = 86400000;
152
141
  /**
153
142
  * https://www.ecma-international.org/ecma-262/11.0/index.html#eqn-modulo
@@ -162,43 +151,38 @@ function mod(x, y) {
162
151
  * https://tc39.es/ecma262/#eqn-Day
163
152
  * @param t
164
153
  */
165
- function Day(t) {
154
+ export function Day(t) {
166
155
  return Math.floor(t / MS_PER_DAY);
167
156
  }
168
- exports.Day = Day;
169
157
  /**
170
158
  * https://tc39.es/ecma262/#sec-week-day
171
159
  * @param t
172
160
  */
173
- function WeekDay(t) {
161
+ export function WeekDay(t) {
174
162
  return mod(Day(t) + 4, 7);
175
163
  }
176
- exports.WeekDay = WeekDay;
177
164
  /**
178
165
  * https://tc39.es/ecma262/#sec-year-number
179
166
  * @param y
180
167
  */
181
- function DayFromYear(y) {
168
+ export function DayFromYear(y) {
182
169
  return Date.UTC(y, 0) / MS_PER_DAY;
183
170
  }
184
- exports.DayFromYear = DayFromYear;
185
171
  /**
186
172
  * https://tc39.es/ecma262/#sec-year-number
187
173
  * @param y
188
174
  */
189
- function TimeFromYear(y) {
175
+ export function TimeFromYear(y) {
190
176
  return Date.UTC(y, 0);
191
177
  }
192
- exports.TimeFromYear = TimeFromYear;
193
178
  /**
194
179
  * https://tc39.es/ecma262/#sec-year-number
195
180
  * @param t
196
181
  */
197
- function YearFromTime(t) {
182
+ export function YearFromTime(t) {
198
183
  return new Date(t).getUTCFullYear();
199
184
  }
200
- exports.YearFromTime = YearFromTime;
201
- function DaysInYear(y) {
185
+ export function DaysInYear(y) {
202
186
  if (y % 4 !== 0) {
203
187
  return 365;
204
188
  }
@@ -210,20 +194,17 @@ function DaysInYear(y) {
210
194
  }
211
195
  return 366;
212
196
  }
213
- exports.DaysInYear = DaysInYear;
214
- function DayWithinYear(t) {
197
+ export function DayWithinYear(t) {
215
198
  return Day(t) - DayFromYear(YearFromTime(t));
216
199
  }
217
- exports.DayWithinYear = DayWithinYear;
218
- function InLeapYear(t) {
200
+ export function InLeapYear(t) {
219
201
  return DaysInYear(YearFromTime(t)) === 365 ? 0 : 1;
220
202
  }
221
- exports.InLeapYear = InLeapYear;
222
203
  /**
223
204
  * https://tc39.es/ecma262/#sec-month-number
224
205
  * @param t
225
206
  */
226
- function MonthFromTime(t) {
207
+ export function MonthFromTime(t) {
227
208
  var dwy = DayWithinYear(t);
228
209
  var leap = InLeapYear(t);
229
210
  if (dwy >= 0 && dwy < 31) {
@@ -264,8 +245,7 @@ function MonthFromTime(t) {
264
245
  }
265
246
  throw new Error('Invalid time');
266
247
  }
267
- exports.MonthFromTime = MonthFromTime;
268
- function DateFromTime(t) {
248
+ export function DateFromTime(t) {
269
249
  var dwy = DayWithinYear(t);
270
250
  var mft = MonthFromTime(t);
271
251
  var leap = InLeapYear(t);
@@ -307,25 +287,21 @@ function DateFromTime(t) {
307
287
  }
308
288
  throw new Error('Invalid time');
309
289
  }
310
- exports.DateFromTime = DateFromTime;
311
290
  var HOURS_PER_DAY = 24;
312
291
  var MINUTES_PER_HOUR = 60;
313
292
  var SECONDS_PER_MINUTE = 60;
314
293
  var MS_PER_SECOND = 1e3;
315
294
  var MS_PER_MINUTE = MS_PER_SECOND * SECONDS_PER_MINUTE;
316
295
  var MS_PER_HOUR = MS_PER_MINUTE * MINUTES_PER_HOUR;
317
- function HourFromTime(t) {
296
+ export function HourFromTime(t) {
318
297
  return mod(Math.floor(t / MS_PER_HOUR), HOURS_PER_DAY);
319
298
  }
320
- exports.HourFromTime = HourFromTime;
321
- function MinFromTime(t) {
299
+ export function MinFromTime(t) {
322
300
  return mod(Math.floor(t / MS_PER_MINUTE), MINUTES_PER_HOUR);
323
301
  }
324
- exports.MinFromTime = MinFromTime;
325
- function SecFromTime(t) {
302
+ export function SecFromTime(t) {
326
303
  return mod(Math.floor(t / MS_PER_SECOND), SECONDS_PER_MINUTE);
327
304
  }
328
- exports.SecFromTime = SecFromTime;
329
305
  function IsCallable(fn) {
330
306
  return typeof fn === 'function';
331
307
  }
@@ -338,7 +314,7 @@ function IsCallable(fn) {
338
314
  * @param O object
339
315
  * @param internalSlots internalSlots
340
316
  */
341
- function OrdinaryHasInstance(C, O, internalSlots) {
317
+ export function OrdinaryHasInstance(C, O, internalSlots) {
342
318
  if (!IsCallable(C)) {
343
319
  return false;
344
320
  }
@@ -355,8 +331,6 @@ function OrdinaryHasInstance(C, O, internalSlots) {
355
331
  }
356
332
  return Object.prototype.isPrototypeOf.call(P, O);
357
333
  }
358
- exports.OrdinaryHasInstance = OrdinaryHasInstance;
359
- function msFromTime(t) {
334
+ export function msFromTime(t) {
360
335
  return mod(t, MS_PER_SECOND);
361
336
  }
362
- exports.msFromTime = msFromTime;
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CanonicalizeLocaleList = void 0;
4
1
  /**
5
2
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
6
3
  * @param locales
7
4
  */
8
- function CanonicalizeLocaleList(locales) {
5
+ export function CanonicalizeLocaleList(locales) {
9
6
  // TODO
10
7
  return Intl.getCanonicalLocales(locales);
11
8
  }
12
- exports.CanonicalizeLocaleList = CanonicalizeLocaleList;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CanonicalizeTimeZoneName = void 0;
4
1
  /**
5
2
  * https://tc39.es/ecma402/#sec-canonicalizetimezonename
6
3
  * @param tz
7
4
  */
8
- function CanonicalizeTimeZoneName(tz, _a) {
5
+ export function CanonicalizeTimeZoneName(tz, _a) {
9
6
  var tzData = _a.tzData, uppercaseLinks = _a.uppercaseLinks;
10
7
  var uppercasedTz = tz.toUpperCase();
11
8
  var uppercasedZones = Object.keys(tzData).reduce(function (all, z) {
@@ -18,4 +15,3 @@ function CanonicalizeTimeZoneName(tz, _a) {
18
15
  }
19
16
  return ianaTimeZone;
20
17
  }
21
- exports.CanonicalizeTimeZoneName = CanonicalizeTimeZoneName;
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CoerceOptionsToObject = void 0;
4
- var _262_1 = require("./262");
1
+ import { ToObject } from './262';
5
2
  /**
6
3
  * https://tc39.es/ecma402/#sec-coerceoptionstoobject
7
4
  * @param options
8
5
  * @returns
9
6
  */
10
- function CoerceOptionsToObject(options) {
7
+ export function CoerceOptionsToObject(options) {
11
8
  if (typeof options === 'undefined') {
12
9
  return Object.create(null);
13
10
  }
14
- return (0, _262_1.ToObject)(options);
11
+ return ToObject(options);
15
12
  }
16
- exports.CoerceOptionsToObject = CoerceOptionsToObject;
@@ -5,4 +5,4 @@
5
5
  * @param max
6
6
  * @param fallback
7
7
  */
8
- export declare function DefaultNumberOption(val: any, min: number, max: number, fallback: number): number;
8
+ export declare function DefaultNumberOption<F extends number | undefined>(inputVal: unknown, min: number, max: number, fallback: F): F extends number ? number : number | undefined;
@@ -1,14 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultNumberOption = void 0;
4
- function DefaultNumberOption(val, min, max, fallback) {
5
- if (val !== undefined) {
6
- val = Number(val);
7
- if (isNaN(val) || val < min || val > max) {
8
- throw new RangeError("".concat(val, " is outside of range [").concat(min, ", ").concat(max, "]"));
9
- }
10
- return Math.floor(val);
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;
11
12
  }
12
- return fallback;
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);
13
18
  }
14
- exports.DefaultNumberOption = DefaultNumberOption;
@@ -6,4 +6,4 @@
6
6
  * @param max
7
7
  * @param fallback
8
8
  */
9
- export declare function GetNumberOption<T extends object, K extends keyof T>(options: T, property: K, minimum: number, maximum: number, fallback: number): number;
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,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * https://tc39.es/ecma402/#sec-getnumberoption
4
3
  * @param options
@@ -7,12 +6,8 @@
7
6
  * @param max
8
7
  * @param fallback
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.GetNumberOption = void 0;
12
- var DefaultNumberOption_1 = require("./DefaultNumberOption");
13
- function GetNumberOption(options, property, minimum, maximum, fallback) {
9
+ import { DefaultNumberOption } from './DefaultNumberOption';
10
+ export function GetNumberOption(options, property, minimum, maximum, fallback) {
14
11
  var val = options[property];
15
- // @ts-expect-error
16
- return (0, DefaultNumberOption_1.DefaultNumberOption)(val, minimum, maximum, fallback);
12
+ return DefaultNumberOption(val, minimum, maximum, fallback);
17
13
  }
18
- exports.GetNumberOption = GetNumberOption;
@@ -6,4 +6,4 @@
6
6
  * @param values
7
7
  * @param fallback
8
8
  */
9
- export declare function GetOption<T extends object, K extends keyof T, F>(opts: T, prop: K, type: 'string' | 'boolean', values: T[K][] | undefined, fallback: F): Exclude<T[K], undefined> | F;
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 CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetOption = void 0;
4
- var _262_1 = require("./262");
1
+ import { ToString } from './262';
5
2
  /**
6
3
  * https://tc39.es/ecma402/#sec-getoption
7
4
  * @param opts
@@ -10,7 +7,7 @@ var _262_1 = require("./262");
10
7
  * @param values
11
8
  * @param fallback
12
9
  */
13
- function GetOption(opts, prop, type, values, fallback) {
10
+ export function GetOption(opts, prop, type, values, fallback) {
14
11
  if (typeof opts !== 'object') {
15
12
  throw new TypeError('Options must be an object');
16
13
  }
@@ -23,7 +20,7 @@ function GetOption(opts, prop, type, values, fallback) {
23
20
  value = Boolean(value);
24
21
  }
25
22
  if (type === 'string') {
26
- value = (0, _262_1.ToString)(value);
23
+ value = ToString(value);
27
24
  }
28
25
  if (values !== undefined && !values.filter(function (val) { return val == value; }).length) {
29
26
  throw new RangeError("".concat(value, " is not within ").concat(values.join(', ')));
@@ -32,4 +29,3 @@ function GetOption(opts, prop, type, values, fallback) {
32
29
  }
33
30
  return fallback;
34
31
  }
35
- exports.GetOption = GetOption;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetOptionsObject = void 0;
4
1
  /**
5
2
  * https://tc39.es/ecma402/#sec-getoptionsobject
6
3
  * @param options
7
4
  * @returns
8
5
  */
9
- function GetOptionsObject(options) {
6
+ export function GetOptionsObject(options) {
10
7
  if (typeof options === 'undefined') {
11
8
  return Object.create(null);
12
9
  }
@@ -15,4 +12,3 @@ function GetOptionsObject(options) {
15
12
  }
16
13
  throw new TypeError('Options must be an object');
17
14
  }
18
- exports.GetOptionsObject = GetOptionsObject;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * https://tc39.es/ecma402/#sec-getstringorbooleanoption
4
3
  * @param opts
@@ -8,10 +7,8 @@
8
7
  * @param falsyValue
9
8
  * @param fallback
10
9
  */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GetStringOrBooleanOption = void 0;
13
- var _262_1 = require("./262");
14
- function GetStringOrBooleanOption(opts, prop, values, trueValue, falsyValue, fallback) {
10
+ import { ToString } from './262';
11
+ export function GetStringOrBooleanOption(opts, prop, values, trueValue, falsyValue, fallback) {
15
12
  var value = opts[prop];
16
13
  if (value === undefined) {
17
14
  return fallback;
@@ -23,7 +20,7 @@ function GetStringOrBooleanOption(opts, prop, values, trueValue, falsyValue, fal
23
20
  if (valueBoolean === false) {
24
21
  return falsyValue;
25
22
  }
26
- value = (0, _262_1.ToString)(value);
23
+ value = ToString(value);
27
24
  if (value === 'true' || value === 'false') {
28
25
  return fallback;
29
26
  }
@@ -32,4 +29,3 @@ function GetStringOrBooleanOption(opts, prop, values, trueValue, falsyValue, fal
32
29
  }
33
30
  return value;
34
31
  }
35
- exports.GetStringOrBooleanOption = GetStringOrBooleanOption;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsSanctionedSimpleUnitIdentifier = exports.SIMPLE_UNITS = exports.removeUnitNamespace = exports.SANCTIONED_UNITS = void 0;
4
1
  /**
5
2
  * https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
6
3
  */
7
- exports.SANCTIONED_UNITS = [
4
+ export var SANCTIONED_UNITS = [
8
5
  'angle-degree',
9
6
  'area-acre',
10
7
  'area-hectare',
@@ -51,18 +48,16 @@ exports.SANCTIONED_UNITS = [
51
48
  ];
52
49
  // In CLDR, the unit name always follows the form `namespace-unit` pattern.
53
50
  // For example: `digital-bit` instead of `bit`. This function removes the namespace prefix.
54
- function removeUnitNamespace(unit) {
51
+ export function removeUnitNamespace(unit) {
55
52
  return unit.slice(unit.indexOf('-') + 1);
56
53
  }
57
- exports.removeUnitNamespace = removeUnitNamespace;
58
54
  /**
59
55
  * https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
60
56
  */
61
- exports.SIMPLE_UNITS = exports.SANCTIONED_UNITS.map(removeUnitNamespace);
57
+ export var SIMPLE_UNITS = SANCTIONED_UNITS.map(removeUnitNamespace);
62
58
  /**
63
59
  * https://tc39.es/ecma402/#sec-issanctionedsimpleunitidentifier
64
60
  */
65
- function IsSanctionedSimpleUnitIdentifier(unitIdentifier) {
66
- return exports.SIMPLE_UNITS.indexOf(unitIdentifier) > -1;
61
+ export function IsSanctionedSimpleUnitIdentifier(unitIdentifier) {
62
+ return SIMPLE_UNITS.indexOf(unitIdentifier) > -1;
67
63
  }
68
- exports.IsSanctionedSimpleUnitIdentifier = IsSanctionedSimpleUnitIdentifier;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsValidTimeZoneName = void 0;
4
1
  /**
5
2
  * https://tc39.es/ecma402/#sec-isvalidtimezonename
6
3
  * @param tz
7
4
  * @param implDetails implementation details
8
5
  */
9
- function IsValidTimeZoneName(tz, _a) {
6
+ export function IsValidTimeZoneName(tz, _a) {
10
7
  var tzData = _a.tzData, uppercaseLinks = _a.uppercaseLinks;
11
8
  var uppercasedTz = tz.toUpperCase();
12
9
  var zoneNames = new Set();
@@ -20,4 +17,3 @@ function IsValidTimeZoneName(tz, _a) {
20
17
  });
21
18
  return zoneNames.has(uppercasedTz) || linkNames.has(uppercasedTz);
22
19
  }
23
- exports.IsValidTimeZoneName = IsValidTimeZoneName;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsWellFormedCurrencyCode = void 0;
4
1
  /**
5
2
  * This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
6
3
  * @param str string to convert
@@ -12,7 +9,7 @@ var NOT_A_Z_REGEX = /[^A-Z]/;
12
9
  /**
13
10
  * https://tc39.es/ecma402/#sec-iswellformedcurrencycode
14
11
  */
15
- function IsWellFormedCurrencyCode(currency) {
12
+ export function IsWellFormedCurrencyCode(currency) {
16
13
  currency = toUpperCase(currency);
17
14
  if (currency.length !== 3) {
18
15
  return false;
@@ -22,4 +19,3 @@ function IsWellFormedCurrencyCode(currency) {
22
19
  }
23
20
  return true;
24
21
  }
25
- exports.IsWellFormedCurrencyCode = IsWellFormedCurrencyCode;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsWellFormedUnitIdentifier = void 0;
4
- var IsSanctionedSimpleUnitIdentifier_1 = require("./IsSanctionedSimpleUnitIdentifier");
1
+ import { IsSanctionedSimpleUnitIdentifier } from './IsSanctionedSimpleUnitIdentifier';
5
2
  /**
6
3
  * This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
7
4
  * @param str string to convert
@@ -13,9 +10,9 @@ function toLowerCase(str) {
13
10
  * https://tc39.es/ecma402/#sec-iswellformedunitidentifier
14
11
  * @param unit
15
12
  */
16
- function IsWellFormedUnitIdentifier(unit) {
13
+ export function IsWellFormedUnitIdentifier(unit) {
17
14
  unit = toLowerCase(unit);
18
- if ((0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(unit)) {
15
+ if (IsSanctionedSimpleUnitIdentifier(unit)) {
19
16
  return true;
20
17
  }
21
18
  var units = unit.split('-per-');
@@ -23,10 +20,9 @@ function IsWellFormedUnitIdentifier(unit) {
23
20
  return false;
24
21
  }
25
22
  var numerator = units[0], denominator = units[1];
26
- if (!(0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(numerator) ||
27
- !(0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(denominator)) {
23
+ if (!IsSanctionedSimpleUnitIdentifier(numerator) ||
24
+ !IsSanctionedSimpleUnitIdentifier(denominator)) {
28
25
  return false;
29
26
  }
30
27
  return true;
31
28
  }
32
- exports.IsWellFormedUnitIdentifier = IsWellFormedUnitIdentifier;