@formatjs/intl-durationformat 0.13.0 → 0.13.1

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.
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LookupSupportedLocales, ResolveLocale } from "@formatjs/intl-localematcher";
2
- import { BigDecimal, Decimal } from "@formatjs/bigdecimal";
2
+ import { BigDecimal } from "@formatjs/bigdecimal";
3
3
  // node_modules/.aspect_rules_js/@formatjs_generated+cldr.number@0.0.0/node_modules/@formatjs_generated/cldr.number/numbering-systems.js
4
4
  const numberingSystemNames = [
5
5
  "adlm",
@@ -101,40 +101,75 @@ const numberingSystemNames = [
101
101
  "wcho"
102
102
  ];
103
103
  // packages/ecma402-abstract/IsUnicodeLocaleIdentifierType.js
104
+ const typeApply = Reflect.apply;
105
+ const typeExec = RegExp.prototype.exec;
106
+ const typePattern = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*(?![\s\S])/i;
104
107
  /** Tests the Unicode locale identifier `type` grammar, not locale support. */
105
108
  function IsUnicodeLocaleIdentifierType(value) {
106
- return /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*(?![\s\S])/i.test(value);
109
+ return typeApply(typeExec, typePattern, [value]) !== null;
107
110
  }
108
111
  // packages/ecma262-abstract/OrdinaryHasInstance.js
109
- function IsCallable(fn) {
110
- return typeof fn === "function";
112
+ const apply$3 = Reflect.apply;
113
+ const hasInstance = Function.prototype[Symbol.hasInstance];
114
+ /** ECMA-262 §7.3.21, via §20.2.3.6 step 2. */
115
+ function OrdinaryHasInstance(constructor, instance) {
116
+ return apply$3(hasInstance, constructor, [instance]);
111
117
  }
112
- /**
113
- * https://tc39.es/ecma262/#sec-ordinaryhasinstance
114
- */
115
- function OrdinaryHasInstance(C, O, internalSlots) {
116
- if (!IsCallable(C)) return false;
117
- if (internalSlots?.boundTargetFunction) return O instanceof internalSlots?.boundTargetFunction;
118
- if (O === null || typeof O !== "object" && typeof O !== "function") return false;
119
- let P = C.prototype;
120
- if (P === null || typeof P !== "object" && typeof P !== "function") throw new TypeError("OrdinaryHasInstance called on an object with an invalid prototype property.");
121
- return Object.prototype.isPrototypeOf.call(P, O);
118
+ // packages/ecma262-abstract/intrinsics.js
119
+ const floor = Math.floor;
120
+ const bigIntFrom = BigInt;
121
+ const objectFrom = Object;
122
+ const mathAbs = Math.abs;
123
+ const numberIsInteger = Number.isInteger;
124
+ const numberIsFinite = Number.isFinite;
125
+ Number.isSafeInteger;
126
+ const ErrorConstructor = Error;
127
+ const TypeErrorConstructor$1 = TypeError;
128
+ const RangeErrorConstructor = RangeError;
129
+ const arrayApply = Reflect.apply;
130
+ Array.prototype.every;
131
+ const some = Array.prototype.some;
132
+ function arraySome(values, predicate) {
133
+ return arrayApply(some, values, [predicate]);
134
+ }
135
+ Array.prototype.includes;
136
+ Array.prototype.indexOf;
137
+ const defineProperty$1 = Object.defineProperty;
138
+ function setDataProperty(target, key, value) {
139
+ defineProperty$1(target, key, {
140
+ __proto__: null,
141
+ value,
142
+ writable: true,
143
+ enumerable: true,
144
+ configurable: true
145
+ });
122
146
  }
123
147
  // packages/ecma262-abstract/ToObject.js
124
148
  /**
125
149
  * https://tc39.es/ecma262/#sec-toobject
126
150
  */
127
151
  function ToObject(arg) {
128
- if (arg == null) throw new TypeError("undefined/null cannot be converted to object");
129
- return Object(arg);
152
+ if (arg === void 0 || arg === null) throw new TypeErrorConstructor$1("undefined/null cannot be converted to object");
153
+ return objectFrom(arg);
130
154
  }
131
155
  // packages/ecma402-abstract/CanonicalizeLocaleList.js
156
+ let canonicalIntl = globalThis.Intl;
157
+ const canonicalDescriptor = Object.getOwnPropertyDescriptor;
158
+ const canonicalApply = Reflect.apply;
159
+ function ownCanonicalProvider() {
160
+ const descriptor = canonicalIntl && canonicalDescriptor(canonicalIntl, "getCanonicalLocales");
161
+ return (descriptor && canonicalDescriptor(descriptor, "value"))?.value;
162
+ }
163
+ let canonicalProvider = ownCanonicalProvider();
132
164
  /**
133
165
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
134
166
  * @param locales
135
167
  */
136
168
  function CanonicalizeLocaleList(locales) {
137
- return Intl.getCanonicalLocales(locales);
169
+ if (canonicalIntl === void 0) canonicalIntl = globalThis.Intl;
170
+ const candidate = ownCanonicalProvider();
171
+ if (typeof candidate === "function") canonicalProvider = candidate;
172
+ return canonicalApply(canonicalProvider, canonicalIntl, [locales]);
138
173
  }
139
174
  // packages/ecma402-abstract/DefaultNumberOption.js
140
175
  /**
@@ -149,8 +184,8 @@ function CanonicalizeLocaleList(locales) {
149
184
  function DefaultNumberOption(inputVal, min, max, fallback) {
150
185
  if (inputVal === void 0) return fallback;
151
186
  const val = +inputVal;
152
- if (isNaN(val) || val < min || val > max) throw new RangeError(`${val} is outside of range [${min}, ${max}]`);
153
- return Math.floor(val);
187
+ if (val !== val || val < min || val > max) throw new RangeErrorConstructor(`${val} is outside of range [${min}, ${max}]`);
188
+ return floor(val);
154
189
  }
155
190
  // packages/ecma402-abstract/GetNumberOption.js
156
191
  /**
@@ -165,15 +200,24 @@ function GetNumberOption(options, property, minimum, maximum, fallback) {
165
200
  const val = options[property];
166
201
  return DefaultNumberOption(val, minimum, maximum, fallback);
167
202
  }
203
+ // packages/ecma262-abstract/IsObject.js
204
+ /** Includes browser host objects such as document.all. */
205
+ function IsObject(value) {
206
+ return value !== null && (typeof value === "object" || typeof value === "function" || typeof value === "undefined" && value !== void 0);
207
+ }
168
208
  // packages/ecma262-abstract/ToString.js
209
+ const StringConstructor = String;
210
+ const TypeErrorConstructor = TypeError;
169
211
  /**
170
212
  * https://tc39.es/ecma262/#sec-tostring
171
213
  */
172
214
  function ToString(o) {
173
- if (typeof o === "symbol") throw TypeError("Cannot convert a Symbol value to a string");
174
- return String(o);
215
+ if (typeof o === "symbol") throw TypeErrorConstructor("Cannot convert a Symbol value to a string");
216
+ return StringConstructor(o);
175
217
  }
176
218
  // packages/ecma402-abstract/GetOption.js
219
+ const optionApply = Reflect.apply;
220
+ const optionJoin = Array.prototype.join;
177
221
  /**
178
222
  * https://tc39.es/ecma402/#sec-getoption
179
223
  * @param opts
@@ -183,13 +227,13 @@ function ToString(o) {
183
227
  * @param fallback
184
228
  */
185
229
  function GetOption(opts, prop, type, values, fallback) {
186
- if (opts === null || typeof opts !== "object" && typeof opts !== "function") throw new TypeError("Options must be an object");
230
+ if (!IsObject(opts)) throw new TypeErrorConstructor$1("Options must be an object");
187
231
  let value = opts[prop];
188
232
  if (value !== void 0) {
189
- if (type !== "boolean" && type !== "string") throw new TypeError("invalid type");
233
+ if (type !== "boolean" && type !== "string") throw new TypeErrorConstructor$1("invalid type");
190
234
  if (type === "boolean") value = Boolean(value);
191
235
  if (type === "string") value = ToString(value);
192
- if (values !== void 0 && !values.filter((val) => val == value).length) throw new RangeError(`${value} is not within ${values.join(", ")}`);
236
+ if (values !== void 0 && !arraySome(values, (val) => val == value)) throw new RangeErrorConstructor(`${value} is not within ${optionApply(optionJoin, values, [", "])}`);
193
237
  return value;
194
238
  }
195
239
  return fallback;
@@ -211,6 +255,13 @@ function SupportedLocales(availableLocales, requestedLocales, options) {
211
255
  return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
212
256
  }
213
257
  // node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
258
+ const apply$2 = Reflect.apply;
259
+ const bind = Function.prototype.bind;
260
+ const slice = Array.prototype.slice;
261
+ const stringify = JSON.stringify;
262
+ const create = Object.create;
263
+ const defineProperty = Object.defineProperty;
264
+ const setPrototypeOf = Object.setPrototypeOf;
214
265
  function memoize(fn, options) {
215
266
  const cache = options && options.cache ? options.cache : cacheDefault;
216
267
  const serializer = options && options.serializer ? options.serializer : serializerDefault;
@@ -226,23 +277,29 @@ function monadic(fn, cache, serializer, arg) {
226
277
  const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
227
278
  let computedValue = cache.get(cacheKey);
228
279
  if (typeof computedValue === "undefined") {
229
- computedValue = fn.call(this, arg);
280
+ computedValue = apply$2(fn, this, [arg]);
230
281
  cache.set(cacheKey, computedValue);
231
282
  }
232
283
  return computedValue;
233
284
  }
234
285
  function variadic(fn, cache, serializer) {
235
- const args = Array.prototype.slice.call(arguments, 3);
286
+ const args = apply$2(slice, arguments, [3]);
287
+ if (serializer === serializerDefault) setPrototypeOf(args, null);
236
288
  const cacheKey = serializer(args);
237
289
  let computedValue = cache.get(cacheKey);
238
290
  if (typeof computedValue === "undefined") {
239
- computedValue = fn.apply(this, args);
291
+ computedValue = apply$2(fn, this, args);
240
292
  cache.set(cacheKey, computedValue);
241
293
  }
242
294
  return computedValue;
243
295
  }
244
296
  function assemble(fn, context, strategy, cache, serialize) {
245
- return strategy.bind(context, fn, cache, serialize);
297
+ return apply$2(bind, strategy, [
298
+ context,
299
+ fn,
300
+ cache,
301
+ serialize
302
+ ]);
246
303
  }
247
304
  function strategyDefault(fn, options) {
248
305
  const strategy = fn.length === 1 ? monadic : variadic;
@@ -255,11 +312,18 @@ function strategyMonadic(fn, options) {
255
312
  return assemble(fn, this, monadic, options.cache.create(), options.serializer);
256
313
  }
257
314
  const serializerDefault = function() {
258
- return JSON.stringify(arguments);
315
+ setPrototypeOf(arguments, null);
316
+ return stringify(arguments);
259
317
  };
260
318
  var ObjectWithoutPrototypeCache = class {
261
319
  constructor() {
262
- this.cache = Object.create(null);
320
+ defineProperty(this, "cache", {
321
+ __proto__: null,
322
+ value: create(null),
323
+ writable: true,
324
+ enumerable: true,
325
+ configurable: true
326
+ });
263
327
  }
264
328
  get(key) {
265
329
  return this.cache[key];
@@ -276,12 +340,90 @@ const strategies = {
276
340
  monadic: strategyMonadic
277
341
  };
278
342
  // packages/ecma402-abstract/utils.js
279
- function invariant(condition, message, Err = Error) {
343
+ function invariant(condition, message, Err = ErrorConstructor) {
280
344
  if (!condition) throw new Err(message);
281
345
  }
282
- const createMemoizedNumberFormat = memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
346
+ memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
283
347
  memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
284
- const createMemoizedListFormat = memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
348
+ memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
349
+ const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
350
+ const formatterMemoizeOptions = {
351
+ __proto__: null,
352
+ strategy: strategies.variadic
353
+ };
354
+ let providerIntl = globalThis.Intl;
355
+ function ownIntlProvider(name) {
356
+ const descriptor = providerIntl && getOwnPropertyDescriptor(providerIntl, name);
357
+ return (descriptor && getOwnPropertyDescriptor(descriptor, "value"))?.value;
358
+ }
359
+ let numberFormatProvider = ownIntlProvider("NumberFormat");
360
+ let listFormatProvider = ownIntlProvider("ListFormat");
361
+ function getNumberFormatProvider() {
362
+ const candidate = ownIntlProvider("NumberFormat");
363
+ if (typeof candidate === "function") numberFormatProvider = candidate;
364
+ return numberFormatProvider;
365
+ }
366
+ function getListFormatProvider() {
367
+ const candidate = ownIntlProvider("ListFormat");
368
+ if (typeof candidate === "function") listFormatProvider = candidate;
369
+ return listFormatProvider;
370
+ }
371
+ const getFormatterPrototype = Object.getPrototypeOf;
372
+ const formatterPartsMethods = /* @__PURE__ */ new WeakMap();
373
+ const formatterPartsOwners = /* @__PURE__ */ new WeakMap();
374
+ const getPartsMethod = formatterPartsMethods.get.bind(formatterPartsMethods);
375
+ const setPartsMethod = formatterPartsMethods.set.bind(formatterPartsMethods);
376
+ const getPartsOwner = formatterPartsOwners.get.bind(formatterPartsOwners);
377
+ const setPartsOwner = formatterPartsOwners.set.bind(formatterPartsOwners);
378
+ function findFormatterPartsMethod(Constructor) {
379
+ const cached = getPartsMethod(Constructor);
380
+ if (cached) return cached;
381
+ let prototype = getOwnPropertyDescriptor(Constructor, "prototype")?.value;
382
+ while (prototype != null) {
383
+ const inherited = getPartsOwner(prototype);
384
+ if (inherited) {
385
+ setPartsMethod(Constructor, inherited);
386
+ return inherited;
387
+ }
388
+ const descriptor = getOwnPropertyDescriptor(prototype, "formatToParts");
389
+ const value = descriptor && getOwnPropertyDescriptor(descriptor, "value");
390
+ if (value && typeof value.value === "function") {
391
+ setPartsMethod(Constructor, value.value);
392
+ setPartsOwner(prototype, value.value);
393
+ return value.value;
394
+ }
395
+ prototype = getFormatterPrototype(prototype);
396
+ }
397
+ }
398
+ function getFormatterPartsMethod(Constructor) {
399
+ const method = findFormatterPartsMethod(Constructor);
400
+ if (!method) throw new TypeErrorConstructor$1("Missing supplied formatter parts method");
401
+ return method;
402
+ }
403
+ if (typeof numberFormatProvider === "function") findFormatterPartsMethod(numberFormatProvider);
404
+ if (typeof listFormatProvider === "function") findFormatterPartsMethod(listFormatProvider);
405
+ const numberFormatMemoizers = /* @__PURE__ */ new WeakMap();
406
+ const getNumberFormatMemoizer = numberFormatMemoizers.get.bind(numberFormatMemoizers);
407
+ const setNumberFormatMemoizer = numberFormatMemoizers.set.bind(numberFormatMemoizers);
408
+ const listFormatMemoizers = /* @__PURE__ */ new WeakMap();
409
+ const getListFormatMemoizer = listFormatMemoizers.get.bind(listFormatMemoizers);
410
+ const setListFormatMemoizer = listFormatMemoizers.set.bind(listFormatMemoizers);
411
+ function createMemoizedNumberFormatForConstructor(Constructor) {
412
+ let factory = getNumberFormatMemoizer(Constructor);
413
+ if (!factory) {
414
+ factory = memoize((...args) => new Constructor(args[0], args[1]), formatterMemoizeOptions);
415
+ setNumberFormatMemoizer(Constructor, factory);
416
+ }
417
+ return factory;
418
+ }
419
+ function createMemoizedListFormatForConstructor(Constructor) {
420
+ let factory = getListFormatMemoizer(Constructor);
421
+ if (!factory) {
422
+ factory = memoize((...args) => new Constructor(args[0], args[1]), formatterMemoizeOptions);
423
+ setListFormatMemoizer(Constructor, factory);
424
+ }
425
+ return factory;
426
+ }
285
427
  // packages/ecma402-abstract/DurationFormat/GetDurationUnitOptions.js
286
428
  function GetDurationUnitOptions(unit, options, baseStyle, stylesList, digitalBase, prevStyle, twoDigitHours = false) {
287
429
  let style = GetOption(options, unit, "string", stylesList, void 0);
@@ -303,9 +445,9 @@ function GetDurationUnitOptions(unit, options, baseStyle, stylesList, digitalBas
303
445
  displayDefault = "auto";
304
446
  }
305
447
  const display = GetOption(options, `${unit}Display`, "string", ["always", "auto"], displayDefault);
306
- if (display === "always" && style === "fractional") throw new RangeError("Fractional units cannot use always display");
307
- if (prevStyle === "fractional" && style !== "fractional") throw new RangeError("Fractional units must be followed by fractional units");
308
- if ((prevStyle === "numeric" || prevStyle === "2-digit") && style !== "fractional" && style !== "numeric" && style !== "2-digit") throw new RangeError("Can't mix numeric and non-numeric styles");
448
+ if (display === "always" && style === "fractional") throw new RangeErrorConstructor("Fractional units cannot use always display");
449
+ if (prevStyle === "fractional" && style !== "fractional") throw new RangeErrorConstructor("Fractional units must be followed by fractional units");
450
+ if ((prevStyle === "numeric" || prevStyle === "2-digit") && style !== "fractional" && style !== "numeric" && style !== "2-digit") throw new RangeErrorConstructor("Can't mix numeric and non-numeric styles");
309
451
  if (twoDigitHours && unit === "hours") style = "2-digit";
310
452
  if ((unit === "minutes" || unit === "seconds") && (prevStyle === "numeric" || prevStyle === "2-digit")) style = "2-digit";
311
453
  return {
@@ -388,22 +530,42 @@ const TABLE_2 = [
388
530
  ];
389
531
  // packages/intl-durationformat/get_internal_slots.ts
390
532
  const internalSlotMap = /* @__PURE__ */ new WeakMap();
533
+ const getSlots = internalSlotMap.get.bind(internalSlotMap);
534
+ const setSlots = internalSlotMap.set.bind(internalSlotMap);
535
+ const createSlots = Object.create;
391
536
  function getInternalSlots(x) {
392
- let internalSlots = internalSlotMap.get(x);
537
+ let internalSlots = getSlots(x);
393
538
  if (!internalSlots) {
394
- internalSlots = Object.create(null);
395
- internalSlotMap.set(x, internalSlots);
539
+ internalSlots = createSlots(null);
540
+ setSlots(x, internalSlots);
396
541
  }
397
542
  return internalSlots;
398
543
  }
399
544
  // packages/intl-durationformat/abstract/PartitionDurationFormatPattern.ts
545
+ const apply$1 = Reflect.apply;
546
+ const stringListIterator = Array.prototype[Symbol.iterator];
547
+ const stringListIteratorNext = Object.getPrototypeOf(apply$1(stringListIterator, [], [])).next;
548
+ const formatterProviders = /* @__PURE__ */ new WeakMap();
549
+ const getFormatterProviders = formatterProviders.get.bind(formatterProviders);
550
+ const setFormatterProviders = formatterProviders.set.bind(formatterProviders);
551
+ function initializeDurationFormatProviders(df) {
552
+ const NumberFormat = getNumberFormatProvider();
553
+ const ListFormat = getListFormatProvider();
554
+ setFormatterProviders(df, {
555
+ numberFormat: createMemoizedNumberFormatForConstructor(NumberFormat),
556
+ listFormat: createMemoizedListFormatForConstructor(ListFormat),
557
+ numberFormatToParts: getFormatterPartsMethod(NumberFormat),
558
+ listFormatToParts: getFormatterPartsMethod(ListFormat)
559
+ });
560
+ }
400
561
  function PartitionDurationFormatPattern(df, duration) {
401
562
  const result = [];
402
563
  let done = false;
403
564
  let separated = false;
404
565
  let signDisplayed = true;
405
- const negative = TABLE_2.some((row) => duration[row.valueField] < 0);
566
+ const negative = arraySome(TABLE_2, (row) => duration[row.valueField] < 0);
406
567
  const internalSlots = getInternalSlots(df);
568
+ const providers = getFormatterProviders(df);
407
569
  let dataLocale = internalSlots.dataLocale;
408
570
  const dataLocaleData = DurationFormat.localeData[dataLocale];
409
571
  if (!dataLocaleData) throw new TypeError("Invalid locale");
@@ -411,20 +573,20 @@ function PartitionDurationFormatPattern(df, duration) {
411
573
  const separator = dataLocaleData.digitalFormat[numberingSystem] ?? dataLocaleData.digitalFormat.default;
412
574
  for (let i = 0; i < TABLE_2.length && !done; i++) {
413
575
  const row = TABLE_2[i];
414
- let value = new BigDecimal(BigInt(duration[row.valueField]));
576
+ let value = new BigDecimal(bigIntFrom(duration[row.valueField]));
415
577
  const style = internalSlots[row.styleSlot];
416
578
  const display = internalSlots[row.displaySlot];
417
579
  const { unit, numberFormatUnit } = row;
418
- const nfOpts = Object.create(null);
580
+ const nfOpts = { __proto__: null };
419
581
  if (unit === "seconds" || unit === "milliseconds" || unit === "microseconds") {
420
582
  let nextStyle;
421
583
  if (unit === "seconds") nextStyle = internalSlots.milliseconds;
422
584
  else if (unit === "milliseconds") nextStyle = internalSlots.microseconds;
423
585
  else nextStyle = internalSlots.nanoseconds;
424
586
  if (nextStyle === "numeric" || nextStyle === "fractional") {
425
- if (unit === "seconds") value = value.plus(new BigDecimal(BigInt(duration.milliseconds)).div(1e3)).plus(new BigDecimal(BigInt(duration.microseconds)).div(1e6)).plus(new BigDecimal(BigInt(duration.nanoseconds)).div(1e9));
426
- else if (unit === "milliseconds") value = value.plus(new BigDecimal(BigInt(duration.microseconds)).div(1e3)).plus(new BigDecimal(BigInt(duration.nanoseconds)).div(1e6));
427
- else value = value.plus(new BigDecimal(BigInt(duration.nanoseconds)).div(1e3));
587
+ if (unit === "seconds") value = value.plus(new BigDecimal(bigIntFrom(duration.milliseconds)).div(bigIntFrom(1e3))).plus(new BigDecimal(bigIntFrom(duration.microseconds)).div(bigIntFrom(1e6))).plus(new BigDecimal(bigIntFrom(duration.nanoseconds)).div(bigIntFrom(1e9)));
588
+ else if (unit === "milliseconds") value = value.plus(new BigDecimal(bigIntFrom(duration.microseconds)).div(bigIntFrom(1e3))).plus(new BigDecimal(bigIntFrom(duration.nanoseconds)).div(bigIntFrom(1e6)));
589
+ else value = value.plus(new BigDecimal(bigIntFrom(duration.nanoseconds)).div(bigIntFrom(1e3)));
428
590
  if (internalSlots.fractionalDigits === void 0) {
429
591
  nfOpts.maximumFractionDigits = 9;
430
592
  nfOpts.minimumFractionDigits = 0;
@@ -450,56 +612,71 @@ function PartitionDurationFormatPattern(df, duration) {
450
612
  nfOpts.unit = numberFormatUnit;
451
613
  nfOpts.unitDisplay = style;
452
614
  }
453
- const nf = createMemoizedNumberFormat(internalSlots.locale, nfOpts);
615
+ const nf = providers.numberFormat(internalSlots.locale, nfOpts);
454
616
  let list;
455
617
  if (!separated) list = [];
456
618
  else {
457
619
  list = result[result.length - 1];
458
- list.push({
620
+ setDataProperty(list, `${list.length}`, {
459
621
  type: "literal",
460
622
  value: separator
461
623
  });
462
624
  }
463
- nf.formatToParts(value.isZero() && value.isNegative() ? -0 : value).forEach(({ type, value }) => {
464
- list.push({
625
+ let parts = apply$1(providers.numberFormatToParts, nf, [value.isZero() && value.isNegative() ? -0 : value]);
626
+ for (let index = 0; index < parts.length; index++) {
627
+ const { type, value } = parts[index];
628
+ setDataProperty(list, `${list.length}`, {
465
629
  type,
466
630
  value,
467
631
  unit: numberFormatUnit
468
632
  });
469
- });
633
+ }
470
634
  if (!separated) {
471
635
  if (style === "2-digit" || style === "numeric") separated = true;
472
- result.push(list);
636
+ setDataProperty(result, `${result.length}`, list);
473
637
  }
474
638
  } else separated = false;
475
639
  }
476
- const lfOpts = Object.create(null);
640
+ const lfOpts = { __proto__: null };
477
641
  lfOpts.type = "unit";
478
642
  let listStyle = internalSlots.style;
479
643
  if (listStyle === "digital") listStyle = "short";
480
644
  lfOpts.style = listStyle;
481
- const lf = createMemoizedListFormat(internalSlots.locale, lfOpts);
645
+ const lf = providers.listFormat(internalSlots.locale, lfOpts);
482
646
  const strings = [];
483
- for (const parts of result) {
647
+ for (let index = 0; index < result.length; index++) {
648
+ const parts = result[index];
484
649
  let string = "";
485
- for (const { value } of parts) string += value;
486
- strings.push(string);
650
+ for (let partIndex = 0; partIndex < parts.length; partIndex++) string += parts[partIndex].value;
651
+ setDataProperty(strings, `${strings.length}`, string);
487
652
  }
488
- let formatted = lf.formatToParts(strings);
653
+ setDataProperty(strings, Symbol.iterator, () => {
654
+ const iterator = apply$1(stringListIterator, strings, []);
655
+ return {
656
+ __proto__: null,
657
+ next() {
658
+ return apply$1(stringListIteratorNext, iterator, []);
659
+ }
660
+ };
661
+ });
662
+ let formatted = apply$1(providers.listFormatToParts, lf, [strings]);
489
663
  let resultIndex = 0;
490
664
  let resultLength = result.length;
491
- let flattened = [];
492
- for (const { type, value } of formatted) if (type === "element") {
493
- invariant(resultIndex < resultLength, "Index out of bounds");
494
- let parts = result[resultIndex];
495
- for (const part of parts) flattened.push(part);
496
- resultIndex++;
497
- } else {
498
- invariant(type === "literal", "Type must be literal");
499
- flattened.push({
500
- type: "literal",
501
- value
502
- });
665
+ const flattened = [];
666
+ for (let index = 0; index < formatted.length; index++) {
667
+ const { type, value } = formatted[index];
668
+ if (type === "element") {
669
+ invariant(resultIndex < resultLength, "Index out of bounds");
670
+ let parts = result[resultIndex];
671
+ for (let index = 0; index < parts.length; index++) setDataProperty(flattened, `${flattened.length}`, parts[index]);
672
+ resultIndex++;
673
+ } else {
674
+ invariant(type === "literal", "Type must be literal");
675
+ setDataProperty(flattened, `${flattened.length}`, {
676
+ type: "literal",
677
+ value
678
+ });
679
+ }
503
680
  }
504
681
  return flattened;
505
682
  }
@@ -518,7 +695,8 @@ const TABLE_1 = [
518
695
  ];
519
696
  // packages/ecma402-abstract/DurationFormat/DurationRecordSign.js
520
697
  function DurationRecordSign(record) {
521
- for (const key of TABLE_1) {
698
+ for (let index = 0; index < TABLE_1.length; index++) {
699
+ const key = TABLE_1[index];
522
700
  if (record[key] < 0) return -1;
523
701
  if (record[key] > 0) return 1;
524
702
  }
@@ -527,42 +705,51 @@ function DurationRecordSign(record) {
527
705
  // packages/ecma402-abstract/DurationFormat/IsValidDurationRecord.js
528
706
  function IsValidDurationRecord(record) {
529
707
  const sign = DurationRecordSign(record);
530
- for (const key of TABLE_1) {
531
- const v = record[key];
532
- if (!Number.isFinite(v)) return false;
708
+ for (let index = 0; index < TABLE_1.length; index++) {
709
+ const v = record[TABLE_1[index]];
710
+ if (!numberIsFinite(v)) return false;
533
711
  if (v < 0 && sign > 0) return false;
534
712
  if (v > 0 && sign < 0) return false;
535
713
  }
536
- if ([
714
+ if (arraySome([
537
715
  "years",
538
716
  "months",
539
717
  "weeks"
540
- ].some((unit) => Math.abs(record[unit]) >= 2 ** 32)) return false;
541
- const billion = BigInt(1e9);
542
- const normalizedNanoseconds = BigInt(record.days) * BigInt(86400) * billion + BigInt(record.hours) * BigInt(3600) * billion + BigInt(record.minutes) * BigInt(60) * billion + BigInt(record.seconds) * billion + BigInt(record.milliseconds) * BigInt(1e6) + BigInt(record.microseconds) * BigInt(1e3) + BigInt(record.nanoseconds);
543
- const limit = BigInt(2 ** 53) * billion;
718
+ ], (unit) => mathAbs(record[unit]) >= 2 ** 32)) return false;
719
+ const billion = bigIntFrom(1e9);
720
+ const normalizedNanoseconds = bigIntFrom(record.days) * bigIntFrom(86400) * billion + bigIntFrom(record.hours) * bigIntFrom(3600) * billion + bigIntFrom(record.minutes) * bigIntFrom(60) * billion + bigIntFrom(record.seconds) * billion + bigIntFrom(record.milliseconds) * bigIntFrom(1e6) + bigIntFrom(record.microseconds) * bigIntFrom(1e3) + bigIntFrom(record.nanoseconds);
721
+ const limit = bigIntFrom(2 ** 53) * billion;
544
722
  return normalizedNanoseconds > -limit && normalizedNanoseconds < limit;
545
723
  }
546
724
  // packages/ecma262-abstract/ToNumber.js
547
- /**
548
- * ECMA-262 §7.1.4 ToNumber, steps 2, 8–10.
549
- * https://tc39.es/ecma262/#sec-tonumber
550
- * https://github.com/tc39/ecma262/blob/dcf59856a8184792a9e42f0ffb7dc064094a5dcc/spec.html#L5183-L5191
551
- */
725
+ /** ECMA-262 §7.1.4, via §13.5.4.1 step 2. */
552
726
  function ToNumber(arg) {
553
- return new Decimal(+arg);
727
+ return +arg;
554
728
  }
555
729
  // packages/ecma402-abstract/DurationFormat/ToIntegerIfIntegral.js
730
+ /** ECMA-402 §13.5.2 steps 1–3. */
556
731
  function ToIntegerIfIntegral(arg) {
557
732
  const number = ToNumber(arg);
558
- invariant(number.isInteger(), "Duration field is not an integer", RangeError);
559
- return number.isZero() ? 0 : number.toNumber();
733
+ if (!numberIsInteger(number)) throw new RangeErrorConstructor("Duration field is not an integer");
734
+ return number === 0 ? 0 : number;
560
735
  }
561
736
  // packages/ecma402-abstract/DurationFormat/ToDurationRecord.js
737
+ const durationPropertyNames = [
738
+ "days",
739
+ "hours",
740
+ "microseconds",
741
+ "milliseconds",
742
+ "minutes",
743
+ "months",
744
+ "nanoseconds",
745
+ "seconds",
746
+ "weeks",
747
+ "years"
748
+ ];
562
749
  function ToDurationRecord(input) {
563
- if ((typeof input !== "object" || input === null) && typeof input !== "function") {
564
- if (typeof input === "string") throw new RangeError("Invalid duration format");
565
- throw new TypeError("Invalid duration");
750
+ if (!IsObject(input)) {
751
+ if (typeof input === "string") throw new RangeErrorConstructor("Invalid duration format");
752
+ throw new TypeErrorConstructor$1("Invalid duration");
566
753
  }
567
754
  const result = {
568
755
  years: 0,
@@ -577,26 +764,16 @@ function ToDurationRecord(input) {
577
764
  nanoseconds: 0
578
765
  };
579
766
  let anyDefined = false;
580
- for (const field of [
581
- "days",
582
- "hours",
583
- "microseconds",
584
- "milliseconds",
585
- "minutes",
586
- "months",
587
- "nanoseconds",
588
- "seconds",
589
- "weeks",
590
- "years"
591
- ]) {
767
+ for (let index = 0; index < durationPropertyNames.length; index++) {
768
+ const field = durationPropertyNames[index];
592
769
  const value = input[field];
593
770
  if (value !== void 0) {
594
771
  anyDefined = true;
595
772
  result[field] = ToIntegerIfIntegral(value);
596
773
  }
597
774
  }
598
- if (!anyDefined) throw new TypeError("Invalid duration format");
599
- if (!IsValidDurationRecord(result)) throw new RangeError("Invalid duration format");
775
+ if (!anyDefined) throw new TypeErrorConstructor$1("Invalid duration format");
776
+ if (!IsValidDurationRecord(result)) throw new RangeErrorConstructor("Invalid duration format");
600
777
  return result;
601
778
  }
602
779
  // packages/ecma402-abstract/DurationFormat/ToTemporalDurationRecord.js
@@ -616,11 +793,11 @@ const apply = Reflect.apply;
616
793
  const readers = [];
617
794
  function registerTemporalDurationNamespace(namespace) {
618
795
  const constructor = namespace?.Duration;
619
- if (!constructor || readers.some((reader) => reader.constructor === constructor)) return;
796
+ if (!constructor || arraySome(readers, (reader) => reader.constructor === constructor)) return;
620
797
  const from = constructor.from, prototype = constructor.prototype;
621
798
  if (typeof from !== "function" || prototype === null || typeof prototype !== "object" && typeof prototype !== "function") return;
622
799
  const getters = fields.map((field) => Object.getOwnPropertyDescriptor(prototype, field)?.get);
623
- if (getters.some((getter) => typeof getter !== "function")) return;
800
+ if (arraySome(getters, (getter) => typeof getter !== "function")) return;
624
801
  readers.push({
625
802
  constructor,
626
803
  from,
@@ -634,14 +811,15 @@ function ToTemporalDurationRecord(input) {
634
811
  const reader = readers[readers.length - 1];
635
812
  input = apply(reader.from, reader.constructor, [input]);
636
813
  }
637
- if (input !== null && (typeof input === "object" || typeof input === "function")) for (const reader of readers) {
814
+ if (input !== null && (typeof input === "object" || typeof input === "function")) for (let index = 0; index < readers.length; index++) {
815
+ const reader = readers[index];
638
816
  let years;
639
817
  try {
640
818
  years = apply(reader.getters[0], input, []);
641
819
  } catch {
642
820
  continue;
643
821
  }
644
- const record = Object.create(null);
822
+ const record = { __proto__: null };
645
823
  record.years = years;
646
824
  for (let index = 1; index < fields.length; index++) record[fields[index]] = apply(reader.getters[index], input, []);
647
825
  return record;
@@ -1355,20 +1533,63 @@ const TIME_SEPARATORS = {
1355
1533
  };
1356
1534
  // packages/intl-durationformat/core.ts
1357
1535
  const numberingSystemsByConstructor = /* @__PURE__ */ new WeakMap();
1536
+ const getNumberingSystems = numberingSystemsByConstructor.get.bind(numberingSystemsByConstructor);
1537
+ const setNumberingSystems = numberingSystemsByConstructor.set.bind(numberingSystemsByConstructor);
1538
+ const createObject = Object.create;
1539
+ const providerApply = Reflect.apply;
1540
+ const providerDescriptor = Object.getOwnPropertyDescriptor;
1541
+ const providerPrototype = Object.getPrototypeOf;
1542
+ const resolvedMethods = /* @__PURE__ */ new WeakMap();
1543
+ const getResolvedMethod = resolvedMethods.get.bind(resolvedMethods);
1544
+ const setResolvedMethod = resolvedMethods.set.bind(resolvedMethods);
1545
+ function numberFormatResolvedOptions(Constructor) {
1546
+ let prototype = Constructor.prototype;
1547
+ while (prototype !== null) {
1548
+ const cached = getResolvedMethod(prototype);
1549
+ if (cached) return cached;
1550
+ const descriptor = providerDescriptor(prototype, "resolvedOptions");
1551
+ const value = descriptor && providerDescriptor(descriptor, "value");
1552
+ if (typeof value?.value === "function") {
1553
+ const method = value.value;
1554
+ setResolvedMethod(prototype, method);
1555
+ return method;
1556
+ }
1557
+ prototype = providerPrototype(prototype);
1558
+ }
1559
+ }
1560
+ const initialNumberFormat = getNumberFormatProvider();
1561
+ if (typeof initialNumberFormat === "function") numberFormatResolvedOptions(initialNumberFormat);
1562
+ const NumberingSet = Set;
1563
+ const numberingAdd = Set.prototype.add;
1564
+ const numberingValues = Set.prototype.values;
1565
+ const numberingNext = providerPrototype(new NumberingSet().values()).next;
1566
+ function numberingUnion(first, second) {
1567
+ const unique = new NumberingSet();
1568
+ for (let index = 0; index < first.length; index++) providerApply(numberingAdd, unique, [first[index]]);
1569
+ for (let index = 0; index < second.length; index++) providerApply(numberingAdd, unique, [second[index]]);
1570
+ const iterator = providerApply(numberingValues, unique, []);
1571
+ const result = [];
1572
+ for (;;) {
1573
+ const next = providerApply(numberingNext, iterator, []);
1574
+ if (next.done) return result;
1575
+ setDataProperty(result, `${result.length}`, next.value);
1576
+ }
1577
+ }
1358
1578
  function supportedNumberingSystems() {
1359
- const NumberFormat = Intl.NumberFormat;
1360
- let systems = numberingSystemsByConstructor.get(NumberFormat);
1579
+ const NumberFormat = getNumberFormatProvider();
1580
+ let systems = getNumberingSystems(NumberFormat);
1361
1581
  if (!systems) {
1362
- systems = numberingSystemNames.filter((numberingSystem) => {
1363
- const options = Object.create(null);
1582
+ systems = [];
1583
+ const resolvedOptions = numberFormatResolvedOptions(NumberFormat);
1584
+ for (let index = 0; index < numberingSystemNames.length; index++) {
1585
+ const numberingSystem = numberingSystemNames[index];
1586
+ const options = createObject(null);
1364
1587
  options.numberingSystem = numberingSystem;
1365
1588
  try {
1366
- return new NumberFormat("en", options).resolvedOptions().numberingSystem === numberingSystem;
1367
- } catch {
1368
- return false;
1369
- }
1370
- });
1371
- if (systems.length) numberingSystemsByConstructor.set(NumberFormat, systems);
1589
+ if (resolvedOptions && providerApply(resolvedOptions, new NumberFormat("en", options), []).numberingSystem === numberingSystem) setDataProperty(systems, `${systems.length}`, numberingSystem);
1590
+ } catch {}
1591
+ }
1592
+ if (systems.length) setNumberingSystems(NumberFormat, systems);
1372
1593
  }
1373
1594
  return systems;
1374
1595
  }
@@ -1528,13 +1749,13 @@ var DurationFormat = class DurationFormat {
1528
1749
  registerTemporalDurationNamespace(namespace);
1529
1750
  }
1530
1751
  constructor(locales, options) {
1531
- if (!(this && this instanceof DurationFormat ? this.constructor : void 0)) throw new TypeError("Intl.DurationFormat must be called with 'new'");
1752
+ if (!new.target) throw new TypeErrorConstructor$1("Intl.DurationFormat must be called with 'new'");
1532
1753
  const requestedLocales = CanonicalizeLocaleList(locales);
1533
- const opt = Object.create(null);
1534
- const opts = options === void 0 ? Object.create(null) : ToObject(options);
1754
+ const opt = createObject(null);
1755
+ const opts = options === void 0 ? createObject(null) : ToObject(options);
1535
1756
  const matcher = GetOption(opts, "localeMatcher", "string", ["best fit", "lookup"], "best fit");
1536
1757
  const numberingSystem = GetOption(opts, "numberingSystem", "string", void 0, void 0);
1537
- if (numberingSystem !== void 0 && !IsUnicodeLocaleIdentifierType(numberingSystem)) throw RangeError(`Invalid numberingSystems: ${numberingSystem}`);
1758
+ if (numberingSystem !== void 0 && !IsUnicodeLocaleIdentifierType(numberingSystem)) throw RangeErrorConstructor(`Invalid numberingSystems: ${numberingSystem}`);
1538
1759
  opt.nu = numberingSystem;
1539
1760
  opt.localeMatcher = matcher;
1540
1761
  const { localeData, availableLocales } = DurationFormat;
@@ -1553,14 +1774,15 @@ var DurationFormat = class DurationFormat {
1553
1774
  internalSlots.style = style;
1554
1775
  internalSlots.dataLocale = r.dataLocale;
1555
1776
  let prevStyle = "";
1556
- TABLE_3.forEach((row) => {
1557
- const { styleSlot, displaySlot, unit, values: valueList, digitalDefault: digitalBase } = row;
1777
+ for (let index = 0; index < TABLE_3.length; index++) {
1778
+ const { styleSlot, displaySlot, unit, values: valueList, digitalDefault: digitalBase } = TABLE_3[index];
1558
1779
  const unitOptions = GetDurationUnitOptions(unit, opts, style, valueList, digitalBase, prevStyle);
1559
1780
  internalSlots[styleSlot] = unitOptions.style;
1560
1781
  internalSlots[displaySlot] = unitOptions.display;
1561
1782
  if (unit === "hours" || unit === "minutes" || unit === "seconds" || unit === "milliseconds" || unit === "microseconds") prevStyle = unitOptions.style;
1562
- });
1783
+ }
1563
1784
  internalSlots.fractionalDigits = GetNumberOption(opts, "fractionalDigits", 0, 9, void 0);
1785
+ initializeDurationFormatProviders(this);
1564
1786
  }
1565
1787
  resolvedOptions() {
1566
1788
  if (typeof this !== "object" || !OrdinaryHasInstance(DurationFormat, this)) throw TypeError("Method Intl.DurationFormat.prototype.resolvedOptions called on incompatible receiver");
@@ -1582,13 +1804,14 @@ var DurationFormat = class DurationFormat {
1582
1804
  const record = ToTemporalDurationRecord(duration);
1583
1805
  const parts = PartitionDurationFormatPattern(this, record);
1584
1806
  const result = [];
1585
- for (const { type, unit, value } of parts) {
1807
+ for (let index = 0; index < parts.length; index++) {
1808
+ const { type, unit, value } = parts[index];
1586
1809
  const obj = {
1587
1810
  type,
1588
1811
  value
1589
1812
  };
1590
- if (unit) obj.unit = unit;
1591
- result.push(obj);
1813
+ if (unit) setDataProperty(obj, "unit", unit);
1814
+ setDataProperty(result, `${result.length}`, obj);
1592
1815
  }
1593
1816
  return result;
1594
1817
  }
@@ -1597,7 +1820,7 @@ var DurationFormat = class DurationFormat {
1597
1820
  const record = ToTemporalDurationRecord(duration);
1598
1821
  const parts = PartitionDurationFormatPattern(this, record);
1599
1822
  let result = "";
1600
- for (const { value } of parts) result += value;
1823
+ for (let index = 0; index < parts.length; index++) result += parts[index].value;
1601
1824
  return result;
1602
1825
  }
1603
1826
  static supportedLocalesOf(locales, options) {
@@ -1615,7 +1838,7 @@ var DurationFormat = class DurationFormat {
1615
1838
  all[locale] = {
1616
1839
  get nu() {
1617
1840
  const defaults = TIME_SEPARATORS.localeData[locale].nu;
1618
- return [.../* @__PURE__ */ new Set([...defaults, ...supportedNumberingSystems()])];
1841
+ return numberingUnion(defaults, supportedNumberingSystems());
1619
1842
  },
1620
1843
  digitalFormat: {
1621
1844
  default: TIME_SEPARATORS.default,