@formatjs/intl-relativetimeformat 4.5.7 → 4.5.11

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.
@@ -18,6 +18,16 @@
18
18
  }
19
19
  return Object(arg);
20
20
  }
21
+ /**
22
+ * https://tc39.es/ecma262/#sec-tostring
23
+ */
24
+ function toString(o) {
25
+ // Only symbol is irregular...
26
+ if (typeof o === 'symbol') {
27
+ throw TypeError('Cannot convert a Symbol value to a string');
28
+ }
29
+ return String(o);
30
+ }
21
31
  /**
22
32
  * https://tc39.es/ecma402/#sec-getoption
23
33
  * @param opts
@@ -37,10 +47,10 @@
37
47
  value = Boolean(value);
38
48
  }
39
49
  if (type === 'string') {
40
- value = String(value);
50
+ value = toString(value);
41
51
  }
42
52
  if (values !== undefined && !values.filter(function (val) { return val == value; }).length) {
43
- throw new RangeError(value + " in not within " + values);
53
+ throw new RangeError(value + " is not within " + values.join(', '));
44
54
  }
45
55
  return value;
46
56
  }
@@ -114,7 +124,10 @@
114
124
  if (typeof getCanonicalLocales === 'function') {
115
125
  return getCanonicalLocales(locales);
116
126
  }
117
- return Intl.NumberFormat.supportedLocalesOf(locales || '');
127
+ // NOTE: we must NOT call `supportedLocalesOf` of a formatjs polyfill, or their implementation
128
+ // will even eventually call this method recursively. Here we use `Intl.DateTimeFormat` since it
129
+ // is not polyfilled by `@formatjs`.
130
+ return Intl.DateTimeFormat.supportedLocalesOf(locales || '');
118
131
  }
119
132
 
120
133
  var __extends = (undefined && undefined.__extends) || (function () {
@@ -458,7 +471,7 @@
458
471
  }
459
472
  return unit;
460
473
  }
461
- var NUMBERING_SYSTEM_REGEX = /[a-z0-9]{3,8}(-[a-z0-9]{3,8})*/gi;
474
+ var NUMBERING_SYSTEM_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
462
475
  /**
463
476
  * https://tc39.es/proposal-intl-relative-time/#sec-makepartslist
464
477
  * @param pattern
@@ -522,7 +535,7 @@
522
535
  // Step 6.a: NaN == NaN
523
536
  return x !== x && y !== y;
524
537
  }
525
- function toString(arg) {
538
+ function toString$1(arg) {
526
539
  return arg + '';
527
540
  }
528
541
  /**
@@ -553,11 +566,11 @@
553
566
  var patterns = fields[entry];
554
567
  var numeric = getInternalSlot(internalSlotMap, rtf, 'numeric');
555
568
  if (numeric === 'auto') {
556
- if (toString(value) in patterns) {
569
+ if (toString$1(value) in patterns) {
557
570
  return [
558
571
  {
559
572
  type: 'literal',
560
- value: patterns[toString(value)],
573
+ value: patterns[toString$1(value)],
561
574
  },
562
575
  ];
563
576
  }
@@ -622,7 +635,7 @@
622
635
  if (!getInternalSlot(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, 'initializedRelativeTimeFormat')) {
623
636
  throw new TypeError('format was called on a invalid context');
624
637
  }
625
- return partitionRelativeTimePattern(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, Number(value), toString(unit))
638
+ return partitionRelativeTimePattern(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, Number(value), toString$1(unit))
626
639
  .map(function (el) { return el.value; })
627
640
  .join('');
628
641
  };
@@ -633,7 +646,7 @@
633
646
  if (!getInternalSlot(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, 'initializedRelativeTimeFormat')) {
634
647
  throw new TypeError('formatToParts was called on a invalid context');
635
648
  }
636
- return partitionRelativeTimePattern(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, Number(value), toString(unit));
649
+ return partitionRelativeTimePattern(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, Number(value), toString$1(unit));
637
650
  };
638
651
  RelativeTimeFormat.prototype.resolvedOptions = function () {
639
652
  if (typeof this !== 'object') {