@formatjs/ecma402-abstract 2.0.0 → 2.2.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 (47) hide show
  1. package/262.d.ts +1 -1
  2. package/262.js +23 -24
  3. package/CanonicalizeLocaleList.js +1 -2
  4. package/CanonicalizeTimeZoneName.js +1 -2
  5. package/CoerceOptionsToObject.js +1 -2
  6. package/DefaultNumberOption.js +1 -2
  7. package/GetNumberOption.js +1 -2
  8. package/GetOption.js +1 -2
  9. package/GetOptionsObject.js +1 -2
  10. package/GetStringOrBooleanOption.js +1 -2
  11. package/IsSanctionedSimpleUnitIdentifier.js +3 -3
  12. package/IsValidTimeZoneName.js +1 -2
  13. package/IsWellFormedCurrencyCode.js +1 -2
  14. package/IsWellFormedUnitIdentifier.js +1 -2
  15. package/NumberFormat/ApplyUnsignedRoundingMode.js +1 -2
  16. package/NumberFormat/CollapseNumberRange.js +1 -2
  17. package/NumberFormat/ComputeExponent.js +1 -2
  18. package/NumberFormat/ComputeExponentForMagnitude.js +1 -2
  19. package/NumberFormat/CurrencyDigits.js +1 -2
  20. package/NumberFormat/FormatApproximately.js +1 -2
  21. package/NumberFormat/FormatNumericRange.js +1 -2
  22. package/NumberFormat/FormatNumericRangeToParts.js +1 -2
  23. package/NumberFormat/FormatNumericToParts.js +1 -2
  24. package/NumberFormat/FormatNumericToString.js +1 -2
  25. package/NumberFormat/GetUnsignedRoundingMode.js +1 -2
  26. package/NumberFormat/InitializeNumberFormat.js +1 -2
  27. package/NumberFormat/PartitionNumberPattern.js +1 -2
  28. package/NumberFormat/PartitionNumberRangePattern.js +1 -2
  29. package/NumberFormat/SetNumberFormatDigitOptions.js +1 -2
  30. package/NumberFormat/SetNumberFormatUnitOptions.js +1 -2
  31. package/NumberFormat/ToRawFixed.js +1 -2
  32. package/NumberFormat/ToRawPrecision.js +1 -2
  33. package/NumberFormat/format_to_parts.js +1 -1
  34. package/PartitionPattern.js +1 -2
  35. package/SupportedLocales.js +1 -2
  36. package/data.js +1 -2
  37. package/index.d.ts +2 -2
  38. package/index.js +8 -3
  39. package/lib/262.d.ts +1 -1
  40. package/lib/NumberFormat/PartitionNumberPattern.d.ts +1 -1
  41. package/lib/index.d.ts +2 -2
  42. package/lib/index.js +2 -2
  43. package/lib/utils.d.ts +5 -0
  44. package/lib/utils.js +52 -0
  45. package/package.json +4 -3
  46. package/utils.d.ts +5 -0
  47. package/utils.js +63 -11
package/262.d.ts CHANGED
@@ -71,7 +71,7 @@ export declare function InLeapYear(t: number): 0 | 1;
71
71
  * https://tc39.es/ecma262/#sec-month-number
72
72
  * @param t
73
73
  */
74
- export declare function MonthFromTime(t: number): 0 | 1 | 2 | 3 | 4 | 8 | 5 | 6 | 10 | 7 | 9 | 11;
74
+ export declare function MonthFromTime(t: number): 0 | 1 | 2 | 3 | 4 | 8 | 5 | 6 | 10 | 7 | 11 | 9;
75
75
  export declare function DateFromTime(t: number): number;
76
76
  export declare function HourFromTime(t: number): number;
77
77
  export declare function MinFromTime(t: number): number;
package/262.js CHANGED
@@ -1,6 +1,28 @@
1
1
  "use strict";
2
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;
3
+ exports.ToString = ToString;
4
+ exports.ToNumber = ToNumber;
5
+ exports.TimeClip = TimeClip;
6
+ exports.ToObject = ToObject;
7
+ exports.SameValue = SameValue;
8
+ exports.ArrayCreate = ArrayCreate;
9
+ exports.HasOwnProperty = HasOwnProperty;
10
+ exports.Type = Type;
11
+ exports.Day = Day;
12
+ exports.WeekDay = WeekDay;
13
+ exports.DayFromYear = DayFromYear;
14
+ exports.TimeFromYear = TimeFromYear;
15
+ exports.YearFromTime = YearFromTime;
16
+ exports.DaysInYear = DaysInYear;
17
+ exports.DayWithinYear = DayWithinYear;
18
+ exports.InLeapYear = InLeapYear;
19
+ exports.MonthFromTime = MonthFromTime;
20
+ exports.DateFromTime = DateFromTime;
21
+ exports.HourFromTime = HourFromTime;
22
+ exports.MinFromTime = MinFromTime;
23
+ exports.SecFromTime = SecFromTime;
24
+ exports.OrdinaryHasInstance = OrdinaryHasInstance;
25
+ exports.msFromTime = msFromTime;
4
26
  /**
5
27
  * https://tc39.es/ecma262/#sec-tostring
6
28
  */
@@ -11,7 +33,6 @@ function ToString(o) {
11
33
  }
12
34
  return String(o);
13
35
  }
14
- exports.ToString = ToString;
15
36
  /**
16
37
  * https://tc39.es/ecma262/#sec-tonumber
17
38
  * @param val
@@ -34,7 +55,6 @@ function ToNumber(val) {
34
55
  }
35
56
  return Number(val);
36
57
  }
37
- exports.ToNumber = ToNumber;
38
58
  /**
39
59
  * https://tc39.es/ecma262/#sec-tointeger
40
60
  * @param n
@@ -69,7 +89,6 @@ function TimeClip(time) {
69
89
  }
70
90
  return ToInteger(time);
71
91
  }
72
- exports.TimeClip = TimeClip;
73
92
  /**
74
93
  * https://tc39.es/ecma262/#sec-toobject
75
94
  * @param arg
@@ -80,7 +99,6 @@ function ToObject(arg) {
80
99
  }
81
100
  return Object(arg);
82
101
  }
83
- exports.ToObject = ToObject;
84
102
  /**
85
103
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-samevalue
86
104
  * @param x
@@ -99,7 +117,6 @@ function SameValue(x, y) {
99
117
  // Step 6.a: NaN == NaN
100
118
  return x !== x && y !== y;
101
119
  }
102
- exports.SameValue = SameValue;
103
120
  /**
104
121
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-arraycreate
105
122
  * @param len
@@ -107,7 +124,6 @@ exports.SameValue = SameValue;
107
124
  function ArrayCreate(len) {
108
125
  return new Array(len);
109
126
  }
110
- exports.ArrayCreate = ArrayCreate;
111
127
  /**
112
128
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-hasownproperty
113
129
  * @param o
@@ -116,7 +132,6 @@ exports.ArrayCreate = ArrayCreate;
116
132
  function HasOwnProperty(o, prop) {
117
133
  return Object.prototype.hasOwnProperty.call(o, prop);
118
134
  }
119
- exports.HasOwnProperty = HasOwnProperty;
120
135
  /**
121
136
  * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-type
122
137
  * @param x
@@ -147,7 +162,6 @@ function Type(x) {
147
162
  return 'BigInt';
148
163
  }
149
164
  }
150
- exports.Type = Type;
151
165
  var MS_PER_DAY = 86400000;
152
166
  /**
153
167
  * https://www.ecma-international.org/ecma-262/11.0/index.html#eqn-modulo
@@ -165,7 +179,6 @@ function mod(x, y) {
165
179
  function Day(t) {
166
180
  return Math.floor(t / MS_PER_DAY);
167
181
  }
168
- exports.Day = Day;
169
182
  /**
170
183
  * https://tc39.es/ecma262/#sec-week-day
171
184
  * @param t
@@ -173,7 +186,6 @@ exports.Day = Day;
173
186
  function WeekDay(t) {
174
187
  return mod(Day(t) + 4, 7);
175
188
  }
176
- exports.WeekDay = WeekDay;
177
189
  /**
178
190
  * https://tc39.es/ecma262/#sec-year-number
179
191
  * @param y
@@ -181,7 +193,6 @@ exports.WeekDay = WeekDay;
181
193
  function DayFromYear(y) {
182
194
  return Date.UTC(y, 0) / MS_PER_DAY;
183
195
  }
184
- exports.DayFromYear = DayFromYear;
185
196
  /**
186
197
  * https://tc39.es/ecma262/#sec-year-number
187
198
  * @param y
@@ -189,7 +200,6 @@ exports.DayFromYear = DayFromYear;
189
200
  function TimeFromYear(y) {
190
201
  return Date.UTC(y, 0);
191
202
  }
192
- exports.TimeFromYear = TimeFromYear;
193
203
  /**
194
204
  * https://tc39.es/ecma262/#sec-year-number
195
205
  * @param t
@@ -197,7 +207,6 @@ exports.TimeFromYear = TimeFromYear;
197
207
  function YearFromTime(t) {
198
208
  return new Date(t).getUTCFullYear();
199
209
  }
200
- exports.YearFromTime = YearFromTime;
201
210
  function DaysInYear(y) {
202
211
  if (y % 4 !== 0) {
203
212
  return 365;
@@ -210,15 +219,12 @@ function DaysInYear(y) {
210
219
  }
211
220
  return 366;
212
221
  }
213
- exports.DaysInYear = DaysInYear;
214
222
  function DayWithinYear(t) {
215
223
  return Day(t) - DayFromYear(YearFromTime(t));
216
224
  }
217
- exports.DayWithinYear = DayWithinYear;
218
225
  function InLeapYear(t) {
219
226
  return DaysInYear(YearFromTime(t)) === 365 ? 0 : 1;
220
227
  }
221
- exports.InLeapYear = InLeapYear;
222
228
  /**
223
229
  * https://tc39.es/ecma262/#sec-month-number
224
230
  * @param t
@@ -264,7 +270,6 @@ function MonthFromTime(t) {
264
270
  }
265
271
  throw new Error('Invalid time');
266
272
  }
267
- exports.MonthFromTime = MonthFromTime;
268
273
  function DateFromTime(t) {
269
274
  var dwy = DayWithinYear(t);
270
275
  var mft = MonthFromTime(t);
@@ -307,7 +312,6 @@ function DateFromTime(t) {
307
312
  }
308
313
  throw new Error('Invalid time');
309
314
  }
310
- exports.DateFromTime = DateFromTime;
311
315
  var HOURS_PER_DAY = 24;
312
316
  var MINUTES_PER_HOUR = 60;
313
317
  var SECONDS_PER_MINUTE = 60;
@@ -317,15 +321,12 @@ var MS_PER_HOUR = MS_PER_MINUTE * MINUTES_PER_HOUR;
317
321
  function HourFromTime(t) {
318
322
  return mod(Math.floor(t / MS_PER_HOUR), HOURS_PER_DAY);
319
323
  }
320
- exports.HourFromTime = HourFromTime;
321
324
  function MinFromTime(t) {
322
325
  return mod(Math.floor(t / MS_PER_MINUTE), MINUTES_PER_HOUR);
323
326
  }
324
- exports.MinFromTime = MinFromTime;
325
327
  function SecFromTime(t) {
326
328
  return mod(Math.floor(t / MS_PER_SECOND), SECONDS_PER_MINUTE);
327
329
  }
328
- exports.SecFromTime = SecFromTime;
329
330
  function IsCallable(fn) {
330
331
  return typeof fn === 'function';
331
332
  }
@@ -355,8 +356,6 @@ function OrdinaryHasInstance(C, O, internalSlots) {
355
356
  }
356
357
  return Object.prototype.isPrototypeOf.call(P, O);
357
358
  }
358
- exports.OrdinaryHasInstance = OrdinaryHasInstance;
359
359
  function msFromTime(t) {
360
360
  return mod(t, MS_PER_SECOND);
361
361
  }
362
- exports.msFromTime = msFromTime;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CanonicalizeLocaleList = void 0;
3
+ exports.CanonicalizeLocaleList = CanonicalizeLocaleList;
4
4
  /**
5
5
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
6
6
  * @param locales
@@ -9,4 +9,3 @@ function CanonicalizeLocaleList(locales) {
9
9
  // TODO
10
10
  return Intl.getCanonicalLocales(locales);
11
11
  }
12
- exports.CanonicalizeLocaleList = CanonicalizeLocaleList;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CanonicalizeTimeZoneName = void 0;
3
+ exports.CanonicalizeTimeZoneName = CanonicalizeTimeZoneName;
4
4
  /**
5
5
  * https://tc39.es/ecma402/#sec-canonicalizetimezonename
6
6
  * @param tz
@@ -18,4 +18,3 @@ function CanonicalizeTimeZoneName(tz, _a) {
18
18
  }
19
19
  return ianaTimeZone;
20
20
  }
21
- exports.CanonicalizeTimeZoneName = CanonicalizeTimeZoneName;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CoerceOptionsToObject = void 0;
3
+ exports.CoerceOptionsToObject = CoerceOptionsToObject;
4
4
  var _262_1 = require("./262");
5
5
  /**
6
6
  * https://tc39.es/ecma402/#sec-coerceoptionstoobject
@@ -13,4 +13,3 @@ function CoerceOptionsToObject(options) {
13
13
  }
14
14
  return (0, _262_1.ToObject)(options);
15
15
  }
16
- exports.CoerceOptionsToObject = CoerceOptionsToObject;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultNumberOption = void 0;
3
+ exports.DefaultNumberOption = DefaultNumberOption;
4
4
  /**
5
5
  * https://tc39.es/ecma402/#sec-defaultnumberoption
6
6
  * @param val
@@ -19,4 +19,3 @@ function DefaultNumberOption(inputVal, min, max, fallback) {
19
19
  }
20
20
  return Math.floor(val);
21
21
  }
22
- exports.DefaultNumberOption = DefaultNumberOption;
@@ -8,10 +8,9 @@
8
8
  * @param fallback
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.GetNumberOption = void 0;
11
+ exports.GetNumberOption = GetNumberOption;
12
12
  var DefaultNumberOption_1 = require("./DefaultNumberOption");
13
13
  function GetNumberOption(options, property, minimum, maximum, fallback) {
14
14
  var val = options[property];
15
15
  return (0, DefaultNumberOption_1.DefaultNumberOption)(val, minimum, maximum, fallback);
16
16
  }
17
- exports.GetNumberOption = GetNumberOption;
package/GetOption.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetOption = void 0;
3
+ exports.GetOption = GetOption;
4
4
  var _262_1 = require("./262");
5
5
  /**
6
6
  * https://tc39.es/ecma402/#sec-getoption
@@ -32,4 +32,3 @@ function GetOption(opts, prop, type, values, fallback) {
32
32
  }
33
33
  return fallback;
34
34
  }
35
- exports.GetOption = GetOption;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetOptionsObject = void 0;
3
+ exports.GetOptionsObject = GetOptionsObject;
4
4
  /**
5
5
  * https://tc39.es/ecma402/#sec-getoptionsobject
6
6
  * @param options
@@ -15,4 +15,3 @@ function GetOptionsObject(options) {
15
15
  }
16
16
  throw new TypeError('Options must be an object');
17
17
  }
18
- exports.GetOptionsObject = GetOptionsObject;
@@ -9,7 +9,7 @@
9
9
  * @param fallback
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GetStringOrBooleanOption = void 0;
12
+ exports.GetStringOrBooleanOption = GetStringOrBooleanOption;
13
13
  var _262_1 = require("./262");
14
14
  function GetStringOrBooleanOption(opts, prop, values, trueValue, falsyValue, fallback) {
15
15
  var value = opts[prop];
@@ -32,4 +32,3 @@ function GetStringOrBooleanOption(opts, prop, values, trueValue, falsyValue, fal
32
32
  }
33
33
  return value;
34
34
  }
35
- exports.GetStringOrBooleanOption = GetStringOrBooleanOption;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsSanctionedSimpleUnitIdentifier = exports.SIMPLE_UNITS = exports.removeUnitNamespace = exports.SANCTIONED_UNITS = void 0;
3
+ exports.SIMPLE_UNITS = exports.SANCTIONED_UNITS = void 0;
4
+ exports.removeUnitNamespace = removeUnitNamespace;
5
+ exports.IsSanctionedSimpleUnitIdentifier = IsSanctionedSimpleUnitIdentifier;
4
6
  /**
5
7
  * https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
6
8
  */
@@ -54,7 +56,6 @@ exports.SANCTIONED_UNITS = [
54
56
  function removeUnitNamespace(unit) {
55
57
  return unit.slice(unit.indexOf('-') + 1);
56
58
  }
57
- exports.removeUnitNamespace = removeUnitNamespace;
58
59
  /**
59
60
  * https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
60
61
  */
@@ -65,4 +66,3 @@ exports.SIMPLE_UNITS = exports.SANCTIONED_UNITS.map(removeUnitNamespace);
65
66
  function IsSanctionedSimpleUnitIdentifier(unitIdentifier) {
66
67
  return exports.SIMPLE_UNITS.indexOf(unitIdentifier) > -1;
67
68
  }
68
- exports.IsSanctionedSimpleUnitIdentifier = IsSanctionedSimpleUnitIdentifier;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsValidTimeZoneName = void 0;
3
+ exports.IsValidTimeZoneName = IsValidTimeZoneName;
4
4
  /**
5
5
  * https://tc39.es/ecma402/#sec-isvalidtimezonename
6
6
  * @param tz
@@ -18,4 +18,3 @@ function IsValidTimeZoneName(tz, _a) {
18
18
  });
19
19
  return zoneNames.has(uppercasedTz) || linkNames.has(uppercasedTz);
20
20
  }
21
- exports.IsValidTimeZoneName = IsValidTimeZoneName;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsWellFormedCurrencyCode = void 0;
3
+ exports.IsWellFormedCurrencyCode = IsWellFormedCurrencyCode;
4
4
  /**
5
5
  * This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
6
6
  * @param str string to convert
@@ -22,4 +22,3 @@ function IsWellFormedCurrencyCode(currency) {
22
22
  }
23
23
  return true;
24
24
  }
25
- exports.IsWellFormedCurrencyCode = IsWellFormedCurrencyCode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsWellFormedUnitIdentifier = void 0;
3
+ exports.IsWellFormedUnitIdentifier = IsWellFormedUnitIdentifier;
4
4
  var IsSanctionedSimpleUnitIdentifier_1 = require("./IsSanctionedSimpleUnitIdentifier");
5
5
  /**
6
6
  * This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
@@ -29,4 +29,3 @@ function IsWellFormedUnitIdentifier(unit) {
29
29
  }
30
30
  return true;
31
31
  }
32
- exports.IsWellFormedUnitIdentifier = IsWellFormedUnitIdentifier;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApplyUnsignedRoundingMode = void 0;
3
+ exports.ApplyUnsignedRoundingMode = ApplyUnsignedRoundingMode;
4
4
  function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
5
5
  if (x === r1)
6
6
  return r1;
@@ -39,4 +39,3 @@ function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
39
39
  }
40
40
  return r2;
41
41
  }
42
- exports.ApplyUnsignedRoundingMode = ApplyUnsignedRoundingMode;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CollapseNumberRange = void 0;
3
+ exports.CollapseNumberRange = CollapseNumberRange;
4
4
  /**
5
5
  * https://tc39.es/ecma402/#sec-collapsenumberrange
6
6
  */
7
7
  function CollapseNumberRange(result) {
8
8
  return result;
9
9
  }
10
- exports.CollapseNumberRange = CollapseNumberRange;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComputeExponent = void 0;
3
+ exports.ComputeExponent = ComputeExponent;
4
4
  var utils_1 = require("../utils");
5
5
  var ComputeExponentForMagnitude_1 = require("./ComputeExponentForMagnitude");
6
6
  var FormatNumericToString_1 = require("./FormatNumericToString");
@@ -40,4 +40,3 @@ function ComputeExponent(numberFormat, x, _a) {
40
40
  magnitude + 1,
41
41
  ];
42
42
  }
43
- exports.ComputeExponent = ComputeExponent;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComputeExponentForMagnitude = void 0;
3
+ exports.ComputeExponentForMagnitude = ComputeExponentForMagnitude;
4
4
  /**
5
5
  * The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
6
6
  * number of the given magnitude (power of ten of the most significant digit) according to the
@@ -61,4 +61,3 @@ function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
61
61
  }
62
62
  }
63
63
  }
64
- exports.ComputeExponentForMagnitude = ComputeExponentForMagnitude;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CurrencyDigits = void 0;
3
+ exports.CurrencyDigits = CurrencyDigits;
4
4
  var _262_1 = require("../262");
5
5
  /**
6
6
  * https://tc39.es/ecma402/#sec-currencydigits
@@ -11,4 +11,3 @@ function CurrencyDigits(c, _a) {
11
11
  ? currencyDigitsData[c]
12
12
  : 2;
13
13
  }
14
- exports.CurrencyDigits = CurrencyDigits;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatApproximately = void 0;
3
+ exports.FormatApproximately = FormatApproximately;
4
4
  /**
5
5
  * https://tc39.es/ecma402/#sec-formatapproximately
6
6
  */
@@ -12,4 +12,3 @@ function FormatApproximately(numberFormat, result, _a) {
12
12
  result.push({ type: 'approximatelySign', value: approximatelySign });
13
13
  return result;
14
14
  }
15
- exports.FormatApproximately = FormatApproximately;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatNumericRange = void 0;
3
+ exports.FormatNumericRange = FormatNumericRange;
4
4
  var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
5
5
  /**
6
6
  * https://tc39.es/ecma402/#sec-formatnumericrange
@@ -12,4 +12,3 @@ function FormatNumericRange(numberFormat, x, y, _a) {
12
12
  });
13
13
  return parts.map(function (part) { return part.value; }).join('');
14
14
  }
15
- exports.FormatNumericRange = FormatNumericRange;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatNumericRangeToParts = void 0;
3
+ exports.FormatNumericRangeToParts = FormatNumericRangeToParts;
4
4
  var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
5
5
  /**
6
6
  * https://tc39.es/ecma402/#sec-formatnumericrangetoparts
@@ -17,4 +17,3 @@ function FormatNumericRangeToParts(numberFormat, x, y, _a) {
17
17
  result: index.toString(),
18
18
  }); });
19
19
  }
20
- exports.FormatNumericRangeToParts = FormatNumericRangeToParts;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatNumericToParts = void 0;
3
+ exports.FormatNumericToParts = FormatNumericToParts;
4
4
  var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
5
5
  var _262_1 = require("../262");
6
6
  function FormatNumericToParts(nf, x, implDetails) {
@@ -15,4 +15,3 @@ function FormatNumericToParts(nf, x, implDetails) {
15
15
  }
16
16
  return result;
17
17
  }
18
- exports.FormatNumericToParts = FormatNumericToParts;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatNumericToString = void 0;
3
+ exports.FormatNumericToString = FormatNumericToString;
4
4
  var _262_1 = require("../262");
5
5
  var ToRawPrecision_1 = require("./ToRawPrecision");
6
6
  var utils_1 = require("../utils");
@@ -42,4 +42,3 @@ function FormatNumericToString(intlObject, x) {
42
42
  }
43
43
  return { roundedNumber: x, formattedString: string };
44
44
  }
45
- exports.FormatNumericToString = FormatNumericToString;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetUnsignedRoundingMode = void 0;
3
+ exports.GetUnsignedRoundingMode = GetUnsignedRoundingMode;
4
4
  var negativeMapping = {
5
5
  ceil: 'zero',
6
6
  floor: 'infinity',
@@ -29,4 +29,3 @@ function GetUnsignedRoundingMode(roundingMode, isNegative) {
29
29
  }
30
30
  return positiveMapping[roundingMode];
31
31
  }
32
- exports.GetUnsignedRoundingMode = GetUnsignedRoundingMode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InitializeNumberFormat = void 0;
3
+ exports.InitializeNumberFormat = InitializeNumberFormat;
4
4
  var intl_localematcher_1 = require("@formatjs/intl-localematcher");
5
5
  var CanonicalizeLocaleList_1 = require("../CanonicalizeLocaleList");
6
6
  var CoerceOptionsToObject_1 = require("../CoerceOptionsToObject");
@@ -96,4 +96,3 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
96
96
  ], 'halfExpand');
97
97
  return nf;
98
98
  }
99
- exports.InitializeNumberFormat = InitializeNumberFormat;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartitionNumberPattern = void 0;
3
+ exports.PartitionNumberPattern = PartitionNumberPattern;
4
4
  var tslib_1 = require("tslib");
5
5
  var FormatNumericToString_1 = require("./FormatNumericToString");
6
6
  var _262_1 = require("../262");
@@ -82,4 +82,3 @@ function PartitionNumberPattern(numberFormat, x, _a) {
82
82
  }
83
83
  return (0, format_to_parts_1.default)({ roundedNumber: x, formattedString: n, exponent: exponent, magnitude: magnitude, sign: sign }, internalSlots.dataLocaleData, pl, internalSlots);
84
84
  }
85
- exports.PartitionNumberPattern = PartitionNumberPattern;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartitionNumberRangePattern = void 0;
3
+ exports.PartitionNumberRangePattern = PartitionNumberRangePattern;
4
4
  var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
5
5
  var CollapseNumberRange_1 = require("./CollapseNumberRange");
6
6
  var FormatApproximately_1 = require("./FormatApproximately");
@@ -33,4 +33,3 @@ function PartitionNumberRangePattern(numberFormat, x, y, _a) {
33
33
  result = result.concat(yResult);
34
34
  return (0, CollapseNumberRange_1.CollapseNumberRange)(result);
35
35
  }
36
- exports.PartitionNumberRangePattern = PartitionNumberRangePattern;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SetNumberFormatDigitOptions = void 0;
3
+ exports.SetNumberFormatDigitOptions = SetNumberFormatDigitOptions;
4
4
  var DefaultNumberOption_1 = require("../DefaultNumberOption");
5
5
  var GetNumberOption_1 = require("../GetNumberOption");
6
6
  var GetOption_1 = require("../GetOption");
@@ -81,4 +81,3 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
81
81
  internalSlots.maximumSignificantDigits = 2;
82
82
  }
83
83
  }
84
- exports.SetNumberFormatDigitOptions = SetNumberFormatDigitOptions;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SetNumberFormatUnitOptions = void 0;
3
+ exports.SetNumberFormatUnitOptions = SetNumberFormatUnitOptions;
4
4
  var GetOption_1 = require("../GetOption");
5
5
  var IsWellFormedCurrencyCode_1 = require("../IsWellFormedCurrencyCode");
6
6
  var IsWellFormedUnitIdentifier_1 = require("../IsWellFormedUnitIdentifier");
@@ -40,4 +40,3 @@ function SetNumberFormatUnitOptions(nf, options, _a) {
40
40
  internalSlots.unitDisplay = unitDisplay;
41
41
  }
42
42
  }
43
- exports.SetNumberFormatUnitOptions = SetNumberFormatUnitOptions;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToRawFixed = void 0;
3
+ exports.ToRawFixed = ToRawFixed;
4
4
  var utils_1 = require("../utils");
5
5
  /**
6
6
  * TODO: dedup with intl-pluralrules and support BigInt
@@ -52,4 +52,3 @@ function ToRawFixed(x, minFraction, maxFraction) {
52
52
  }
53
53
  return { formattedString: m, roundedNumber: xFinal, integerDigitsCount: int };
54
54
  }
55
- exports.ToRawFixed = ToRawFixed;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToRawPrecision = void 0;
3
+ exports.ToRawPrecision = ToRawPrecision;
4
4
  var utils_1 = require("../utils");
5
5
  function ToRawPrecision(x, minPrecision, maxPrecision) {
6
6
  var p = maxPrecision;
@@ -75,4 +75,3 @@ function ToRawPrecision(x, minPrecision, maxPrecision) {
75
75
  return magnitude < 0 ? x * Math.pow(10, -magnitude) : x / Math.pow(10, magnitude);
76
76
  }
77
77
  }
78
- exports.ToRawPrecision = ToRawPrecision;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = formatToParts;
3
4
  var regex_generated_1 = require("../regex.generated");
4
5
  var ToRawFixed_1 = require("./ToRawFixed");
5
6
  var digit_mapping_generated_1 = require("./digit-mapping.generated");
@@ -251,7 +252,6 @@ function formatToParts(numberResult, data, pl, options) {
251
252
  }
252
253
  // #endregion
253
254
  }
254
- exports.default = formatToParts;
255
255
  // A subset of https://tc39.es/ecma402/#sec-partitionnotationsubpattern
256
256
  // Plus the exponent parts handling.
257
257
  function paritionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem, useGrouping,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartitionPattern = void 0;
3
+ exports.PartitionPattern = PartitionPattern;
4
4
  var utils_1 = require("./utils");
5
5
  /**
6
6
  * https://tc39.es/ecma402/#sec-partitionpattern
@@ -36,4 +36,3 @@ function PartitionPattern(pattern) {
36
36
  }
37
37
  return result;
38
38
  }
39
- exports.PartitionPattern = PartitionPattern;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SupportedLocales = void 0;
3
+ exports.SupportedLocales = SupportedLocales;
4
4
  var intl_localematcher_1 = require("@formatjs/intl-localematcher");
5
5
  var _262_1 = require("./262");
6
6
  var GetOption_1 = require("./GetOption");
@@ -21,4 +21,3 @@ function SupportedLocales(availableLocales, requestedLocales, options) {
21
21
  }
22
22
  return (0, intl_localematcher_1.LookupSupportedLocales)(Array.from(availableLocales), requestedLocales);
23
23
  }
24
- exports.SupportedLocales = SupportedLocales;
package/data.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMissingLocaleDataError = void 0;
3
+ exports.isMissingLocaleDataError = isMissingLocaleDataError;
4
4
  var tslib_1 = require("tslib");
5
5
  var MissingLocaleDataError = /** @class */ (function (_super) {
6
6
  tslib_1.__extends(MissingLocaleDataError, _super);
@@ -14,4 +14,3 @@ var MissingLocaleDataError = /** @class */ (function (_super) {
14
14
  function isMissingLocaleDataError(e) {
15
15
  return e.type === 'MISSING_LOCALE_DATA';
16
16
  }
17
- exports.isMissingLocaleDataError = isMissingLocaleDataError;
package/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from './NumberFormat/CollapseNumberRange';
14
14
  export * from './NumberFormat/ComputeExponent';
15
15
  export * from './NumberFormat/ComputeExponentForMagnitude';
16
16
  export * from './NumberFormat/CurrencyDigits';
17
+ export { default as _formatToParts } from './NumberFormat/format_to_parts';
17
18
  export * from './NumberFormat/FormatApproximately';
18
19
  export * from './NumberFormat/FormatNumericRange';
19
20
  export * from './NumberFormat/FormatNumericRangeToParts';
@@ -27,7 +28,6 @@ export * from './NumberFormat/SetNumberFormatDigitOptions';
27
28
  export * from './NumberFormat/SetNumberFormatUnitOptions';
28
29
  export * from './NumberFormat/ToRawFixed';
29
30
  export * from './NumberFormat/ToRawPrecision';
30
- export { default as _formatToParts } from './NumberFormat/format_to_parts';
31
31
  export * from './PartitionPattern';
32
32
  export * from './SupportedLocales';
33
33
  export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
@@ -41,4 +41,4 @@ export * from './types/list';
41
41
  export * from './types/number';
42
42
  export * from './types/plural-rules';
43
43
  export * from './types/relative-time';
44
- export { invariant } from './utils';
44
+ export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.invariant = exports.isMissingLocaleDataError = exports.setMultiInternalSlots = exports.setInternalSlot = exports.isLiteralPart = exports.getMultiInternalSlots = exports.getMagnitude = exports.getInternalSlot = exports.defineProperty = exports.createDataProperty = exports._formatToParts = void 0;
3
+ exports.invariant = exports.createMemoizedPluralRules = exports.createMemoizedNumberFormat = exports.createMemoizedLocale = exports.createMemoizedListFormat = exports.createMemoizedDateTimeFormat = exports.isMissingLocaleDataError = exports.setMultiInternalSlots = exports.setInternalSlot = exports.isLiteralPart = exports.getMultiInternalSlots = exports.getMagnitude = exports.getInternalSlot = exports.defineProperty = exports.createDataProperty = exports._formatToParts = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./CanonicalizeLocaleList"), exports);
6
6
  tslib_1.__exportStar(require("./CanonicalizeTimeZoneName"), exports);
@@ -18,6 +18,8 @@ tslib_1.__exportStar(require("./NumberFormat/CollapseNumberRange"), exports);
18
18
  tslib_1.__exportStar(require("./NumberFormat/ComputeExponent"), exports);
19
19
  tslib_1.__exportStar(require("./NumberFormat/ComputeExponentForMagnitude"), exports);
20
20
  tslib_1.__exportStar(require("./NumberFormat/CurrencyDigits"), exports);
21
+ var format_to_parts_1 = require("./NumberFormat/format_to_parts");
22
+ Object.defineProperty(exports, "_formatToParts", { enumerable: true, get: function () { return tslib_1.__importDefault(format_to_parts_1).default; } });
21
23
  tslib_1.__exportStar(require("./NumberFormat/FormatApproximately"), exports);
22
24
  tslib_1.__exportStar(require("./NumberFormat/FormatNumericRange"), exports);
23
25
  tslib_1.__exportStar(require("./NumberFormat/FormatNumericRangeToParts"), exports);
@@ -31,8 +33,6 @@ tslib_1.__exportStar(require("./NumberFormat/SetNumberFormatDigitOptions"), expo
31
33
  tslib_1.__exportStar(require("./NumberFormat/SetNumberFormatUnitOptions"), exports);
32
34
  tslib_1.__exportStar(require("./NumberFormat/ToRawFixed"), exports);
33
35
  tslib_1.__exportStar(require("./NumberFormat/ToRawPrecision"), exports);
34
- var format_to_parts_1 = require("./NumberFormat/format_to_parts");
35
- Object.defineProperty(exports, "_formatToParts", { enumerable: true, get: function () { return tslib_1.__importDefault(format_to_parts_1).default; } });
36
36
  tslib_1.__exportStar(require("./PartitionPattern"), exports);
37
37
  tslib_1.__exportStar(require("./SupportedLocales"), exports);
38
38
  var utils_1 = require("./utils");
@@ -54,4 +54,9 @@ tslib_1.__exportStar(require("./types/number"), exports);
54
54
  tslib_1.__exportStar(require("./types/plural-rules"), exports);
55
55
  tslib_1.__exportStar(require("./types/relative-time"), exports);
56
56
  var utils_2 = require("./utils");
57
+ Object.defineProperty(exports, "createMemoizedDateTimeFormat", { enumerable: true, get: function () { return utils_2.createMemoizedDateTimeFormat; } });
58
+ Object.defineProperty(exports, "createMemoizedListFormat", { enumerable: true, get: function () { return utils_2.createMemoizedListFormat; } });
59
+ Object.defineProperty(exports, "createMemoizedLocale", { enumerable: true, get: function () { return utils_2.createMemoizedLocale; } });
60
+ Object.defineProperty(exports, "createMemoizedNumberFormat", { enumerable: true, get: function () { return utils_2.createMemoizedNumberFormat; } });
61
+ Object.defineProperty(exports, "createMemoizedPluralRules", { enumerable: true, get: function () { return utils_2.createMemoizedPluralRules; } });
57
62
  Object.defineProperty(exports, "invariant", { enumerable: true, get: function () { return utils_2.invariant; } });
package/lib/262.d.ts CHANGED
@@ -71,7 +71,7 @@ export declare function InLeapYear(t: number): 0 | 1;
71
71
  * https://tc39.es/ecma262/#sec-month-number
72
72
  * @param t
73
73
  */
74
- export declare function MonthFromTime(t: number): 0 | 1 | 2 | 3 | 4 | 8 | 5 | 6 | 10 | 7 | 9 | 11;
74
+ export declare function MonthFromTime(t: number): 0 | 1 | 2 | 3 | 4 | 8 | 5 | 6 | 10 | 7 | 11 | 9;
75
75
  export declare function DateFromTime(t: number): number;
76
76
  export declare function HourFromTime(t: number): number;
77
77
  export declare function MinFromTime(t: number): number;
@@ -4,4 +4,4 @@ import { NumberFormatInternal } from '../types/number';
4
4
  */
5
5
  export declare function PartitionNumberPattern(numberFormat: Intl.NumberFormat, x: number, { getInternalSlots, }: {
6
6
  getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
7
- }): import("../types/number").NumberFormatPart[];
7
+ }): import("..").NumberFormatPart[];
package/lib/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from './NumberFormat/CollapseNumberRange';
14
14
  export * from './NumberFormat/ComputeExponent';
15
15
  export * from './NumberFormat/ComputeExponentForMagnitude';
16
16
  export * from './NumberFormat/CurrencyDigits';
17
+ export { default as _formatToParts } from './NumberFormat/format_to_parts';
17
18
  export * from './NumberFormat/FormatApproximately';
18
19
  export * from './NumberFormat/FormatNumericRange';
19
20
  export * from './NumberFormat/FormatNumericRangeToParts';
@@ -27,7 +28,6 @@ export * from './NumberFormat/SetNumberFormatDigitOptions';
27
28
  export * from './NumberFormat/SetNumberFormatUnitOptions';
28
29
  export * from './NumberFormat/ToRawFixed';
29
30
  export * from './NumberFormat/ToRawPrecision';
30
- export { default as _formatToParts } from './NumberFormat/format_to_parts';
31
31
  export * from './PartitionPattern';
32
32
  export * from './SupportedLocales';
33
33
  export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
@@ -41,4 +41,4 @@ export * from './types/list';
41
41
  export * from './types/number';
42
42
  export * from './types/plural-rules';
43
43
  export * from './types/relative-time';
44
- export { invariant } from './utils';
44
+ export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ export * from './NumberFormat/CollapseNumberRange';
14
14
  export * from './NumberFormat/ComputeExponent';
15
15
  export * from './NumberFormat/ComputeExponentForMagnitude';
16
16
  export * from './NumberFormat/CurrencyDigits';
17
+ export { default as _formatToParts } from './NumberFormat/format_to_parts';
17
18
  export * from './NumberFormat/FormatApproximately';
18
19
  export * from './NumberFormat/FormatNumericRange';
19
20
  export * from './NumberFormat/FormatNumericRangeToParts';
@@ -27,7 +28,6 @@ export * from './NumberFormat/SetNumberFormatDigitOptions';
27
28
  export * from './NumberFormat/SetNumberFormatUnitOptions';
28
29
  export * from './NumberFormat/ToRawFixed';
29
30
  export * from './NumberFormat/ToRawPrecision';
30
- export { default as _formatToParts } from './NumberFormat/format_to_parts';
31
31
  export * from './PartitionPattern';
32
32
  export * from './SupportedLocales';
33
33
  export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
@@ -39,4 +39,4 @@ export * from './types/list';
39
39
  export * from './types/number';
40
40
  export * from './types/plural-rules';
41
41
  export * from './types/relative-time';
42
- export { invariant } from './utils';
42
+ export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
package/lib/utils.d.ts CHANGED
@@ -28,3 +28,8 @@ export declare function defineProperty<T extends object>(target: T, name: string
28
28
  export declare function createDataProperty<T extends object>(target: T, name: string | symbol, value: any): void;
29
29
  export declare const UNICODE_EXTENSION_SEQUENCE_REGEX: RegExp;
30
30
  export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
31
+ export declare const createMemoizedNumberFormat: (...args: ConstructorParameters<typeof Intl.NumberFormat>) => Intl.NumberFormat;
32
+ export declare const createMemoizedDateTimeFormat: (...args: ConstructorParameters<typeof Intl.DateTimeFormat>) => Intl.DateTimeFormat;
33
+ export declare const createMemoizedPluralRules: (...args: ConstructorParameters<typeof Intl.PluralRules>) => Intl.PluralRules;
34
+ export declare const createMemoizedLocale: (...args: ConstructorParameters<typeof Intl.Locale>) => Intl.Locale;
35
+ export declare const createMemoizedListFormat: (...args: ConstructorParameters<typeof Intl.ListFormat>) => Intl.ListFormat;
package/lib/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { __spreadArray } from "tslib";
2
+ import { memoize, strategies } from '@formatjs/fast-memoize';
1
3
  /**
2
4
  * Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
3
5
  * @param x number
@@ -90,3 +92,53 @@ export function invariant(condition, message, Err) {
90
92
  throw new Err(message);
91
93
  }
92
94
  }
95
+ export var createMemoizedNumberFormat = memoize(function () {
96
+ var _a;
97
+ var args = [];
98
+ for (var _i = 0; _i < arguments.length; _i++) {
99
+ args[_i] = arguments[_i];
100
+ }
101
+ return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
102
+ }, {
103
+ strategy: strategies.variadic,
104
+ });
105
+ export var createMemoizedDateTimeFormat = memoize(function () {
106
+ var _a;
107
+ var args = [];
108
+ for (var _i = 0; _i < arguments.length; _i++) {
109
+ args[_i] = arguments[_i];
110
+ }
111
+ return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
112
+ }, {
113
+ strategy: strategies.variadic,
114
+ });
115
+ export var createMemoizedPluralRules = memoize(function () {
116
+ var _a;
117
+ var args = [];
118
+ for (var _i = 0; _i < arguments.length; _i++) {
119
+ args[_i] = arguments[_i];
120
+ }
121
+ return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
122
+ }, {
123
+ strategy: strategies.variadic,
124
+ });
125
+ export var createMemoizedLocale = memoize(function () {
126
+ var _a;
127
+ var args = [];
128
+ for (var _i = 0; _i < arguments.length; _i++) {
129
+ args[_i] = arguments[_i];
130
+ }
131
+ return new ((_a = Intl.Locale).bind.apply(_a, __spreadArray([void 0], args, false)))();
132
+ }, {
133
+ strategy: strategies.variadic,
134
+ });
135
+ export var createMemoizedListFormat = memoize(function () {
136
+ var _a;
137
+ var args = [];
138
+ for (var _i = 0; _i < arguments.length; _i++) {
139
+ args[_i] = arguments[_i];
140
+ }
141
+ return new ((_a = Intl.ListFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
142
+ }, {
143
+ strategy: strategies.variadic,
144
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/ecma402-abstract",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "A collection of implementation for ECMAScript abstract operations",
5
5
  "keywords": [
6
6
  "intl",
@@ -14,8 +14,9 @@
14
14
  "format"
15
15
  ],
16
16
  "dependencies": {
17
- "tslib": "^2.4.0",
18
- "@formatjs/intl-localematcher": "0.5.4"
17
+ "tslib": "^2.7.0",
18
+ "@formatjs/intl-localematcher": "0.5.5",
19
+ "@formatjs/fast-memoize": "2.2.1"
19
20
  },
20
21
  "author": "Long Ho <holevietlong@gmail.com",
21
22
  "bugs": {
package/utils.d.ts CHANGED
@@ -28,3 +28,8 @@ export declare function defineProperty<T extends object>(target: T, name: string
28
28
  export declare function createDataProperty<T extends object>(target: T, name: string | symbol, value: any): void;
29
29
  export declare const UNICODE_EXTENSION_SEQUENCE_REGEX: RegExp;
30
30
  export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
31
+ export declare const createMemoizedNumberFormat: (...args: ConstructorParameters<typeof Intl.NumberFormat>) => Intl.NumberFormat;
32
+ export declare const createMemoizedDateTimeFormat: (...args: ConstructorParameters<typeof Intl.DateTimeFormat>) => Intl.DateTimeFormat;
33
+ export declare const createMemoizedPluralRules: (...args: ConstructorParameters<typeof Intl.PluralRules>) => Intl.PluralRules;
34
+ export declare const createMemoizedLocale: (...args: ConstructorParameters<typeof Intl.Locale>) => Intl.Locale;
35
+ export declare const createMemoizedListFormat: (...args: ConstructorParameters<typeof Intl.ListFormat>) => Intl.ListFormat;
package/utils.js CHANGED
@@ -1,6 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.invariant = exports.UNICODE_EXTENSION_SEQUENCE_REGEX = exports.createDataProperty = exports.defineProperty = exports.isLiteralPart = exports.getMultiInternalSlots = exports.getInternalSlot = exports.setMultiInternalSlots = exports.setInternalSlot = exports.repeat = exports.getMagnitude = void 0;
3
+ exports.createMemoizedListFormat = exports.createMemoizedLocale = exports.createMemoizedPluralRules = exports.createMemoizedDateTimeFormat = exports.createMemoizedNumberFormat = exports.UNICODE_EXTENSION_SEQUENCE_REGEX = void 0;
4
+ exports.getMagnitude = getMagnitude;
5
+ exports.repeat = repeat;
6
+ exports.setInternalSlot = setInternalSlot;
7
+ exports.setMultiInternalSlots = setMultiInternalSlots;
8
+ exports.getInternalSlot = getInternalSlot;
9
+ exports.getMultiInternalSlots = getMultiInternalSlots;
10
+ exports.isLiteralPart = isLiteralPart;
11
+ exports.defineProperty = defineProperty;
12
+ exports.createDataProperty = createDataProperty;
13
+ exports.invariant = invariant;
14
+ var tslib_1 = require("tslib");
15
+ var fast_memoize_1 = require("@formatjs/fast-memoize");
4
16
  /**
5
17
  * Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
6
18
  * @param x number
@@ -10,7 +22,6 @@ function getMagnitude(x) {
10
22
  // for very small or very large numbers.
11
23
  return Math.floor(Math.log(x) * Math.LOG10E);
12
24
  }
13
- exports.getMagnitude = getMagnitude;
14
25
  function repeat(s, times) {
15
26
  if (typeof s.repeat === 'function') {
16
27
  return s.repeat(times);
@@ -21,7 +32,6 @@ function repeat(s, times) {
21
32
  }
22
33
  return arr.join('');
23
34
  }
24
- exports.repeat = repeat;
25
35
  function setInternalSlot(map, pl, field, value) {
26
36
  if (!map.get(pl)) {
27
37
  map.set(pl, Object.create(null));
@@ -29,18 +39,15 @@ function setInternalSlot(map, pl, field, value) {
29
39
  var slots = map.get(pl);
30
40
  slots[field] = value;
31
41
  }
32
- exports.setInternalSlot = setInternalSlot;
33
42
  function setMultiInternalSlots(map, pl, props) {
34
43
  for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) {
35
44
  var k = _a[_i];
36
45
  setInternalSlot(map, pl, k, props[k]);
37
46
  }
38
47
  }
39
- exports.setMultiInternalSlots = setMultiInternalSlots;
40
48
  function getInternalSlot(map, pl, field) {
41
49
  return getMultiInternalSlots(map, pl, field)[field];
42
50
  }
43
- exports.getInternalSlot = getInternalSlot;
44
51
  function getMultiInternalSlots(map, pl) {
45
52
  var fields = [];
46
53
  for (var _i = 2; _i < arguments.length; _i++) {
@@ -55,11 +62,9 @@ function getMultiInternalSlots(map, pl) {
55
62
  return all;
56
63
  }, Object.create(null));
57
64
  }
58
- exports.getMultiInternalSlots = getMultiInternalSlots;
59
65
  function isLiteralPart(patternPart) {
60
66
  return patternPart.type === 'literal';
61
67
  }
62
- exports.isLiteralPart = isLiteralPart;
63
68
  /*
64
69
  17 ECMAScript Standard Built-in Objects:
65
70
  Every built-in Function object, including constructors, that is not
@@ -79,7 +84,6 @@ function defineProperty(target, name, _a) {
79
84
  value: value,
80
85
  });
81
86
  }
82
- exports.defineProperty = defineProperty;
83
87
  /**
84
88
  * 7.3.5 CreateDataProperty
85
89
  * @param target
@@ -94,7 +98,6 @@ function createDataProperty(target, name, value) {
94
98
  value: value,
95
99
  });
96
100
  }
97
- exports.createDataProperty = createDataProperty;
98
101
  exports.UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi;
99
102
  function invariant(condition, message, Err) {
100
103
  if (Err === void 0) { Err = Error; }
@@ -102,4 +105,53 @@ function invariant(condition, message, Err) {
102
105
  throw new Err(message);
103
106
  }
104
107
  }
105
- exports.invariant = invariant;
108
+ exports.createMemoizedNumberFormat = (0, fast_memoize_1.memoize)(function () {
109
+ var _a;
110
+ var args = [];
111
+ for (var _i = 0; _i < arguments.length; _i++) {
112
+ args[_i] = arguments[_i];
113
+ }
114
+ return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
115
+ }, {
116
+ strategy: fast_memoize_1.strategies.variadic,
117
+ });
118
+ exports.createMemoizedDateTimeFormat = (0, fast_memoize_1.memoize)(function () {
119
+ var _a;
120
+ var args = [];
121
+ for (var _i = 0; _i < arguments.length; _i++) {
122
+ args[_i] = arguments[_i];
123
+ }
124
+ return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
125
+ }, {
126
+ strategy: fast_memoize_1.strategies.variadic,
127
+ });
128
+ exports.createMemoizedPluralRules = (0, fast_memoize_1.memoize)(function () {
129
+ var _a;
130
+ var args = [];
131
+ for (var _i = 0; _i < arguments.length; _i++) {
132
+ args[_i] = arguments[_i];
133
+ }
134
+ return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
135
+ }, {
136
+ strategy: fast_memoize_1.strategies.variadic,
137
+ });
138
+ exports.createMemoizedLocale = (0, fast_memoize_1.memoize)(function () {
139
+ var _a;
140
+ var args = [];
141
+ for (var _i = 0; _i < arguments.length; _i++) {
142
+ args[_i] = arguments[_i];
143
+ }
144
+ return new ((_a = Intl.Locale).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
145
+ }, {
146
+ strategy: fast_memoize_1.strategies.variadic,
147
+ });
148
+ exports.createMemoizedListFormat = (0, fast_memoize_1.memoize)(function () {
149
+ var _a;
150
+ var args = [];
151
+ for (var _i = 0; _i < arguments.length; _i++) {
152
+ args[_i] = arguments[_i];
153
+ }
154
+ return new ((_a = Intl.ListFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
155
+ }, {
156
+ strategy: fast_memoize_1.strategies.variadic,
157
+ });