@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.
@@ -21,6 +21,16 @@
21
21
  }
22
22
  return Object(arg);
23
23
  }
24
+ /**
25
+ * https://tc39.es/ecma262/#sec-tostring
26
+ */
27
+ function toString(o) {
28
+ // Only symbol is irregular...
29
+ if (typeof o === 'symbol') {
30
+ throw TypeError('Cannot convert a Symbol value to a string');
31
+ }
32
+ return String(o);
33
+ }
24
34
  /**
25
35
  * https://tc39.es/ecma402/#sec-getoption
26
36
  * @param opts
@@ -40,10 +50,10 @@
40
50
  value = Boolean(value);
41
51
  }
42
52
  if (type === 'string') {
43
- value = String(value);
53
+ value = toString(value);
44
54
  }
45
55
  if (values !== undefined && !values.filter(function (val) { return val == value; }).length) {
46
- throw new RangeError(value + " in not within " + values);
56
+ throw new RangeError(value + " is not within " + values.join(', '));
47
57
  }
48
58
  return value;
49
59
  }
@@ -117,7 +127,10 @@
117
127
  if (typeof getCanonicalLocales === 'function') {
118
128
  return getCanonicalLocales(locales);
119
129
  }
120
- return Intl.NumberFormat.supportedLocalesOf(locales || '');
130
+ // NOTE: we must NOT call `supportedLocalesOf` of a formatjs polyfill, or their implementation
131
+ // will even eventually call this method recursively. Here we use `Intl.DateTimeFormat` since it
132
+ // is not polyfilled by `@formatjs`.
133
+ return Intl.DateTimeFormat.supportedLocalesOf(locales || '');
121
134
  }
122
135
 
123
136
  var __extends = (undefined && undefined.__extends) || (function () {
@@ -461,7 +474,7 @@
461
474
  }
462
475
  return unit;
463
476
  }
464
- var NUMBERING_SYSTEM_REGEX = /[a-z0-9]{3,8}(-[a-z0-9]{3,8})*/gi;
477
+ var NUMBERING_SYSTEM_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
465
478
  /**
466
479
  * https://tc39.es/proposal-intl-relative-time/#sec-makepartslist
467
480
  * @param pattern
@@ -525,7 +538,7 @@
525
538
  // Step 6.a: NaN == NaN
526
539
  return x !== x && y !== y;
527
540
  }
528
- function toString(arg) {
541
+ function toString$1(arg) {
529
542
  return arg + '';
530
543
  }
531
544
  /**
@@ -556,11 +569,11 @@
556
569
  var patterns = fields[entry];
557
570
  var numeric = getInternalSlot(internalSlotMap, rtf, 'numeric');
558
571
  if (numeric === 'auto') {
559
- if (toString(value) in patterns) {
572
+ if (toString$1(value) in patterns) {
560
573
  return [
561
574
  {
562
575
  type: 'literal',
563
- value: patterns[toString(value)],
576
+ value: patterns[toString$1(value)],
564
577
  },
565
578
  ];
566
579
  }
@@ -625,7 +638,7 @@
625
638
  if (!getInternalSlot(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, 'initializedRelativeTimeFormat')) {
626
639
  throw new TypeError('format was called on a invalid context');
627
640
  }
628
- return partitionRelativeTimePattern(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, Number(value), toString(unit))
641
+ return partitionRelativeTimePattern(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, Number(value), toString$1(unit))
629
642
  .map(function (el) { return el.value; })
630
643
  .join('');
631
644
  };
@@ -636,7 +649,7 @@
636
649
  if (!getInternalSlot(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, 'initializedRelativeTimeFormat')) {
637
650
  throw new TypeError('formatToParts was called on a invalid context');
638
651
  }
639
- return partitionRelativeTimePattern(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, Number(value), toString(unit));
652
+ return partitionRelativeTimePattern(RelativeTimeFormat.__INTERNAL_SLOT_MAP__, this, Number(value), toString$1(unit));
640
653
  };
641
654
  RelativeTimeFormat.prototype.resolvedOptions = function () {
642
655
  if (typeof this !== 'object') {