textbrowser 0.48.0 → 0.48.2

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.
@@ -345,6 +345,33 @@ function buildGetJSON({
345
345
 
346
346
  const getJSON = buildGetJSON();
347
347
 
348
+ function _iterableToArrayLimit(arr, i) {
349
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
350
+ if (null != _i) {
351
+ var _s,
352
+ _e,
353
+ _x,
354
+ _r,
355
+ _arr = [],
356
+ _n = !0,
357
+ _d = !1;
358
+ try {
359
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
360
+ if (Object(_i) !== _i) return;
361
+ _n = !1;
362
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
363
+ } catch (err) {
364
+ _d = !0, _e = err;
365
+ } finally {
366
+ try {
367
+ if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
368
+ } finally {
369
+ if (_d) throw _e;
370
+ }
371
+ }
372
+ return _arr;
373
+ }
374
+ }
348
375
  function ownKeys(object, enumerableOnly) {
349
376
  var keys = Object.keys(object);
350
377
  if (Object.getOwnPropertySymbols) {
@@ -433,7 +460,7 @@ function _defineProperties(target, props) {
433
460
  descriptor.enumerable = descriptor.enumerable || false;
434
461
  descriptor.configurable = true;
435
462
  if ("value" in descriptor) descriptor.writable = true;
436
- Object.defineProperty(target, descriptor.key, descriptor);
463
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
437
464
  }
438
465
  }
439
466
  function _createClass(Constructor, protoProps, staticProps) {
@@ -445,6 +472,7 @@ function _createClass(Constructor, protoProps, staticProps) {
445
472
  return Constructor;
446
473
  }
447
474
  function _defineProperty(obj, key, value) {
475
+ key = _toPropertyKey(key);
448
476
  if (key in obj) {
449
477
  Object.defineProperty(obj, key, {
450
478
  value: value,
@@ -540,30 +568,6 @@ function _arrayWithHoles(arr) {
540
568
  function _iterableToArray(iter) {
541
569
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
542
570
  }
543
- function _iterableToArrayLimit(arr, i) {
544
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
545
- if (_i == null) return;
546
- var _arr = [];
547
- var _n = true;
548
- var _d = false;
549
- var _s, _e;
550
- try {
551
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
552
- _arr.push(_s.value);
553
- if (i && _arr.length === i) break;
554
- }
555
- } catch (err) {
556
- _d = true;
557
- _e = err;
558
- } finally {
559
- try {
560
- if (!_n && _i["return"] != null) _i["return"]();
561
- } finally {
562
- if (_d) throw _e;
563
- }
564
- }
565
- return _arr;
566
- }
567
571
  function _unsupportedIterableToArray(o, minLen) {
568
572
  if (!o) return;
569
573
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -583,17 +587,50 @@ function _nonIterableSpread() {
583
587
  function _nonIterableRest() {
584
588
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
585
589
  }
590
+ function _toPrimitive(input, hint) {
591
+ if (typeof input !== "object" || input === null) return input;
592
+ var prim = input[Symbol.toPrimitive];
593
+ if (prim !== undefined) {
594
+ var res = prim.call(input, hint || "default");
595
+ if (typeof res !== "object") return res;
596
+ throw new TypeError("@@toPrimitive must return a primitive value.");
597
+ }
598
+ return (hint === "string" ? String : Number)(input);
599
+ }
600
+ function _toPropertyKey(arg) {
601
+ var key = _toPrimitive(arg, "string");
602
+ return typeof key === "symbol" ? key : String(key);
603
+ }
586
604
 
587
605
  // We want it to work in the browser, so commenting out
588
606
  // import jsonExtra from 'json5';
589
607
  // import jsonExtra from 'json-6';
590
608
 
609
+ /**
610
+ * @typedef {any} JSON6
611
+ */
612
+
613
+ // @ts-expect-error Need typing for JSON6
591
614
  var _jsonExtra = globalThis.jsonExtra;
615
+
616
+ /**
617
+ * @param {string} str
618
+ * @returns {string}
619
+ */
592
620
  var unescapeBackslashes = function unescapeBackslashes(str) {
593
621
  return str.replace(/\\+/g, function (esc) {
594
622
  return esc.slice(0, esc.length / 2);
595
623
  });
596
624
  };
625
+
626
+ /**
627
+ * @typedef {any} AnyValue
628
+ */
629
+
630
+ /**
631
+ * @param {string} args
632
+ * @returns {AnyValue}
633
+ */
597
634
  var parseJSONExtra = function parseJSONExtra(args) {
598
635
  return _jsonExtra.parse(
599
636
  // Doesn't actually currently allow explicit brackets,
@@ -602,6 +639,36 @@ var parseJSONExtra = function parseJSONExtra(args) {
602
639
  };
603
640
 
604
641
  // Todo: Extract to own library (RegExtras?)
642
+
643
+ /**
644
+ * @callback BetweenMatches
645
+ * @param {string} str
646
+ * @returns {void}
647
+ */
648
+
649
+ /**
650
+ * @callback AfterMatch
651
+ * @param {string} str
652
+ * @returns {void}
653
+ */
654
+
655
+ /**
656
+ * @callback EscapeAtOne
657
+ * @param {string} str
658
+ * @returns {void}
659
+ */
660
+
661
+ /**
662
+ * @param {RegExp} regex
663
+ * @param {string} str
664
+ * @param {{
665
+ * onMatch: (...arg0: string[]) => void,
666
+ * extra?: BetweenMatches|AfterMatch|EscapeAtOne
667
+ * betweenMatches?: BetweenMatches,
668
+ * afterMatch?: AfterMatch,
669
+ * escapeAtOne?: EscapeAtOne
670
+ * }} cfg
671
+ */
605
672
  var processRegex = function processRegex(regex, str, _ref) {
606
673
  var onMatch = _ref.onMatch,
607
674
  extra = _ref.extra,
@@ -615,6 +682,9 @@ var processRegex = function processRegex(regex, str, _ref) {
615
682
  afterMatch = extra;
616
683
  escapeAtOne = extra;
617
684
  }
685
+ if (!betweenMatches || !afterMatch) {
686
+ throw new Error('You must have `extra` or `betweenMatches` and `afterMatch` arguments.');
687
+ }
618
688
  while ((match = regex.exec(str)) !== null) {
619
689
  var _match = match,
620
690
  _match2 = _slicedToArray(_match, 2),
@@ -640,20 +710,31 @@ var processRegex = function processRegex(regex, str, _ref) {
640
710
  };
641
711
 
642
712
  /* globals fetch, document */
713
+
714
+ /**
715
+ * @typedef {(
716
+ * input: RequestInfo|URL, init?: RequestInit
717
+ * ) => Promise<Response>} Fetch
718
+ */
719
+ /**
720
+ * @type {null|Fetch}
721
+ */
643
722
  var _fetch = typeof fetch !== 'undefined' ? fetch
644
723
  /* c8 ignore next */ : null;
645
724
 
646
725
  /**
647
- * @returns {fetch}
726
+ * @returns {Fetch|null}
648
727
  */
649
728
  var getFetch = function getFetch() {
650
729
  return _fetch;
651
730
  };
731
+
732
+ /** @type {Document|null} */
652
733
  var _doc = typeof document !== 'undefined'
653
734
  /* c8 ignore next */ ? document : null;
654
735
 
655
736
  /**
656
- * @returns {document}
737
+ * @returns {Document|null}
657
738
  */
658
739
  var getDocument = function getDocument() {
659
740
  return _doc;
@@ -680,28 +761,74 @@ function generateUUID() {
680
761
  });
681
762
  }
682
763
 
764
+ /**
765
+ *
766
+ * @param {string} locale
767
+ * @param {string[]} arrayOfItems
768
+ * @param {Intl.CollatorOptions|undefined} options
769
+ * @returns {string[]}
770
+ */
683
771
  var sort = function sort(locale, arrayOfItems, options) {
684
772
  return arrayOfItems.sort(new Intl.Collator(locale, options).compare);
685
773
  };
774
+
775
+ /**
776
+ *
777
+ * @param {string} locale
778
+ * @param {string[]} arrayOfItems
779
+ * @param {Intl.ListFormatOptions|undefined} [options]
780
+ * @returns {string}
781
+ */
686
782
  var list = function list(locale, arrayOfItems, options) {
687
783
  return new Intl.ListFormat(locale, options).format(arrayOfItems);
688
784
  };
785
+
786
+ /**
787
+ *
788
+ * @param {string} locale
789
+ * @param {string[]} arrayOfItems
790
+ * @param {Intl.ListFormatOptions|undefined} [listOptions]
791
+ * @param {Intl.CollatorOptions|undefined} [collationOptions]
792
+ * @returns {string}
793
+ */
689
794
  var sortListSimple = function sortListSimple(locale, arrayOfItems, listOptions, collationOptions) {
690
795
  sort(locale, arrayOfItems, collationOptions);
691
796
  return list(locale, arrayOfItems, listOptions);
692
797
  };
798
+
799
+ /**
800
+ * @typedef {number} Integer
801
+ */
802
+
803
+ /**
804
+ *
805
+ * @param {string} locale
806
+ * @param {string[]} arrayOfItems
807
+ * @param {((str: string, idx: Integer) => any)|
808
+ * Intl.ListFormatOptions|undefined} map
809
+ * @param {Intl.ListFormatOptions|undefined} [listOptions]
810
+ * @param {Intl.CollatorOptions|undefined} [collationOptions]
811
+ * @returns {DocumentFragment|string}
812
+ */
693
813
  var sortList = function sortList(locale, arrayOfItems, map, listOptions, collationOptions) {
694
814
  if (typeof map !== 'function') {
695
- return sortListSimple(locale, arrayOfItems, map, listOptions);
815
+ return sortListSimple(locale, /** @type {string[]} */arrayOfItems, map, listOptions);
696
816
  }
697
817
  sort(locale, arrayOfItems, collationOptions);
698
818
  var randomId = generateUUID();
699
819
  var placeholderArray = _toConsumableArray(arrayOfItems).map(function (_, i) {
700
820
  return "<<".concat(randomId).concat(i, ">>");
701
821
  });
822
+
823
+ /** @type {(string|Node)[]} */
702
824
  var nodes = [];
703
- var push = function push() {
704
- nodes.push.apply(nodes, arguments);
825
+
826
+ /**
827
+ * @param {string} arg
828
+ * @returns {void}
829
+ */
830
+ var push = function push(arg) {
831
+ nodes.push(arg);
705
832
  };
706
833
  processRegex(
707
834
  // // eslint-disable-next-line prefer-named-capture-group
@@ -709,20 +836,45 @@ var sortList = function sortList(locale, arrayOfItems, map, listOptions, collati
709
836
  betweenMatches: push,
710
837
  afterMatch: push,
711
838
  onMatch: function onMatch(_, idx) {
712
- push(map(arrayOfItems[idx], idx));
839
+ push(map(arrayOfItems[Number(idx)], Number(idx)));
713
840
  }
714
841
  });
715
- var _doc = getDocument();
842
+ var _doc = /** @type {Document} */getDocument();
716
843
  var container = _doc.createDocumentFragment();
717
844
  container.append.apply(container, nodes);
718
845
  return container;
719
846
  };
720
847
 
848
+ /**
849
+ * @typedef {number} Integer
850
+ */
851
+
852
+ /**
853
+ * @param {{
854
+ * object: import('./defaultLocaleResolver.js').DateRangeValueArray|
855
+ * import('./defaultLocaleResolver.js').ListValueArray|
856
+ * import('./defaultLocaleResolver.js').RelativeValueArray|
857
+ * import('./defaultLocaleResolver.js').ValueArray
858
+ * }} cfg
859
+ * @returns {{
860
+ * value: number|string|string[]|Date,
861
+ * options?: Intl.NumberFormatOptions|Intl.PluralRulesOptions|
862
+ * string|Date|number,
863
+ * extraOpts?: object,
864
+ * callback?: (item: string, i: Integer) => Element
865
+ * }}
866
+ */
721
867
  var getFormatterInfo = function getFormatterInfo(_ref) {
722
868
  var object = _ref.object;
723
869
  if (Array.isArray(object)) {
724
870
  if (typeof object[1] === 'function') {
725
- var _object = _slicedToArray(object, 4),
871
+ var _object = _slicedToArray(
872
+ /**
873
+ * @type {[
874
+ * string[], (item: string, i: Integer) => Element, object, object
875
+ * ]}
876
+ */
877
+ object, 4),
726
878
  _value = _object[0],
727
879
  callback = _object[1],
728
880
  _options = _object[2],
@@ -749,25 +901,25 @@ var getFormatterInfo = function getFormatterInfo(_ref) {
749
901
  };
750
902
  };
751
903
 
752
- /* eslint-disable max-len */
753
904
  /**
754
905
  * Callback to give replacement text based on a substitution value.
755
- * @callback AllSubstitutionCallback
756
- * @param {PlainObject} cfg
757
- * @param {string|Node|number|Date|RelativeTimeInfo|ListInfo|NumberInfo|DateInfo} cfg.value Contains
758
- * the value returned by the individual substitution
759
- * @param {string} cfg.arg See `cfg.arg` of {@link SubstitutionCallback}.
760
- * @param {string} cfg.key The substitution key Not currently in use
761
- * @param {string} cfg.locale The locale
762
- * @returns {string|Element} The replacement text or element
906
+ *
907
+ * `value` - contains the value returned by the individual substitution.
908
+ * `arg` - See `cfg.arg` of {@link SubstitutionCallback}.
909
+ * `key` - The substitution key Not currently in use
910
+ * `locale` - The locale.
911
+ * @typedef {(info: {
912
+ * value: import('./defaultLocaleResolver.js').SubstitutionObjectValue
913
+ * arg?: string,
914
+ * key?: string,
915
+ * locale?: string
916
+ * }) => string|Node} AllSubstitutionCallback
763
917
  */
764
- /* eslint-enable max-len */
765
918
 
766
919
  /**
767
920
  * @type {AllSubstitutionCallback}
768
921
  */
769
922
  var defaultAllSubstitutions = function defaultAllSubstitutions(_ref2) {
770
- var _Intl$DateTimeFormat;
771
923
  var value = _ref2.value,
772
924
  arg = _ref2.arg;
773
925
  _ref2.key;
@@ -776,11 +928,23 @@ var defaultAllSubstitutions = function defaultAllSubstitutions(_ref2) {
776
928
  if (typeof value === 'string' || value && _typeof(value) === 'object' && 'nodeType' in value) {
777
929
  return value;
778
930
  }
931
+
932
+ /** @type {object|string|Date|number|undefined} */
779
933
  var opts;
934
+
935
+ /**
936
+ * @param {{
937
+ * type: string,
938
+ * options?: object,
939
+ * checkArgOptions?: boolean;
940
+ * }} cfg
941
+ * @returns {object|undefined}
942
+ */
780
943
  var applyArgs = function applyArgs(_ref3) {
781
944
  var type = _ref3.type,
782
945
  _ref3$options = _ref3.options,
783
- options = _ref3$options === void 0 ? opts : _ref3$options,
946
+ options = _ref3$options === void 0 ? /** @type {object|undefined} */
947
+ opts : _ref3$options,
784
948
  _ref3$checkArgOptions = _ref3.checkArgOptions,
785
949
  checkArgOptions = _ref3$checkArgOptions === void 0 ? false : _ref3$checkArgOptions;
786
950
  if (typeof arg === 'string') {
@@ -809,8 +973,29 @@ var defaultAllSubstitutions = function defaultAllSubstitutions(_ref2) {
809
973
  var singleKey = Object.keys(value)[0];
810
974
  if (['number', 'date', 'datetime', 'dateRange', 'datetimeRange', 'relative', 'region', 'language', 'script', 'currency', 'list', 'plural'].includes(singleKey)) {
811
975
  var extraOpts, callback;
976
+ /**
977
+ * @typedef {any} AnyValue
978
+ */
979
+
980
+ var obj = /** @type {unknown} */
981
+ /** @type {AnyValue} */
982
+ value[
983
+ /**
984
+ * @type {"number"|"date"|"datetime"|"dateRange"|
985
+ * "datetimeRange"|"relative"|"region"|"language"|
986
+ * "script"|"currency"|"list"|"plural"}
987
+ */
988
+ singleKey];
812
989
  var _getFormatterInfo = getFormatterInfo({
813
- object: value[singleKey]
990
+ object:
991
+ /**
992
+ * @type {import('./defaultLocaleResolver.js').DateRangeValueArray|
993
+ * import('./defaultLocaleResolver.js').ListValueArray|
994
+ * import('./defaultLocaleResolver.js').RelativeValueArray|
995
+ * import('./defaultLocaleResolver.js').ValueArray
996
+ * }
997
+ */
998
+ obj
814
999
  });
815
1000
  value = _getFormatterInfo.value;
816
1001
  opts = _getFormatterInfo.options;
@@ -823,34 +1008,44 @@ var defaultAllSubstitutions = function defaultAllSubstitutions(_ref2) {
823
1008
  break;
824
1009
  case 'dateRange':
825
1010
  case 'datetimeRange':
826
- return (_Intl$DateTimeFormat = new Intl.DateTimeFormat(locale, applyArgs({
827
- type: 'DATERANGE',
828
- options: extraOpts
829
- }))).formatRange.apply(_Intl$DateTimeFormat, _toConsumableArray([value, opts].map(function (val) {
830
- return typeof val === 'number' ? new Date(val) : val;
831
- })));
1011
+ {
1012
+ var dtf = new Intl.DateTimeFormat(locale, applyArgs({
1013
+ type: 'DATERANGE',
1014
+ options: extraOpts
1015
+ }));
1016
+ return dtf.formatRange.apply(dtf, _toConsumableArray( /** @type {[Date, Date]} */
1017
+ [/** @type {number|Date} */
1018
+ value, /** @type {Date} */
1019
+ opts].map(function (val) {
1020
+ return typeof val === 'number' ? new Date(val) : val;
1021
+ })));
1022
+ }
832
1023
  case 'region':
833
1024
  case 'language':
834
1025
  case 'script':
835
1026
  case 'currency':
836
- return new Intl.DisplayNames(locale, _objectSpread2(_objectSpread2({}, applyArgs({
837
- type: singleKey.toUpperCase()
838
- })), {}, {
839
- type: singleKey
840
- })).of(value);
1027
+ return (/** @type {string} */new Intl.DisplayNames(locale, _objectSpread2(_objectSpread2({}, applyArgs({
1028
+ type: singleKey.toUpperCase()
1029
+ })), {}, {
1030
+ type: singleKey
1031
+ })).of( /** @type {string} */value)
1032
+ );
841
1033
  case 'relative':
842
1034
  // The second argument actually contains the primary options, so swap
843
- var _ref4 = [opts, extraOpts];
1035
+ // eslint-disable-next-line max-len -- Long
1036
+ var _ref4 = /** @type {[Intl.RelativeTimeFormatUnit, object?]} */
1037
+ [opts, extraOpts];
844
1038
  extraOpts = _ref4[0];
845
1039
  opts = _ref4[1];
846
1040
  return new Intl.RelativeTimeFormat(locale, applyArgs({
847
1041
  type: 'RELATIVE'
848
- })).format(value, extraOpts);
1042
+ })).format( /** @type {number} */value, extraOpts);
849
1043
 
850
1044
  // ListFormat (with Collator)
851
1045
  case 'list':
852
1046
  if (callback) {
853
- return sortList(locale, value, callback, applyArgs({
1047
+ return sortList( /** @type {string} */locale, /** @type {string[]} */
1048
+ value, callback, applyArgs({
854
1049
  type: 'LIST'
855
1050
  }), applyArgs({
856
1051
  type: 'LIST',
@@ -858,7 +1053,8 @@ var defaultAllSubstitutions = function defaultAllSubstitutions(_ref2) {
858
1053
  checkArgOptions: true
859
1054
  }));
860
1055
  }
861
- return sortList(locale, value, applyArgs({
1056
+ return sortList( /** @type {string} */locale, /** @type {string[]} */
1057
+ value, applyArgs({
862
1058
  type: 'LIST'
863
1059
  }), applyArgs({
864
1060
  type: 'LIST',
@@ -871,10 +1067,10 @@ var defaultAllSubstitutions = function defaultAllSubstitutions(_ref2) {
871
1067
 
872
1068
  // Dates
873
1069
  if (value) {
874
- if (typeof value === 'number' && (expectsDatetime || /^DATE(?:TIME)(?:\||$)/.test(arg))) {
1070
+ if (typeof value === 'number' && (expectsDatetime || /^DATE(?:TIME)(?:\||$)/.test( /** @type {string} */arg))) {
875
1071
  value = new Date(value);
876
1072
  }
877
- if (_typeof(value) === 'object' && typeof value.getTime === 'function') {
1073
+ if (_typeof(value) === 'object' && 'getTime' in value && typeof value.getTime === 'function') {
878
1074
  return new Intl.DateTimeFormat(locale, applyArgs({
879
1075
  type: 'DATETIME'
880
1076
  })).format(value);
@@ -883,12 +1079,14 @@ var defaultAllSubstitutions = function defaultAllSubstitutions(_ref2) {
883
1079
 
884
1080
  // Date range
885
1081
  if (Array.isArray(value)) {
886
- var _Intl$DateTimeFormat2;
887
- var _extraOpts2 = value[2];
888
- return (_Intl$DateTimeFormat2 = new Intl.DateTimeFormat(locale, applyArgs({
1082
+ var _Intl$DateTimeFormat;
1083
+ var _extraOpts2 = /** @type {Intl.DateTimeFormatOptions|undefined} */
1084
+ value[2];
1085
+ return (_Intl$DateTimeFormat = new Intl.DateTimeFormat(locale, applyArgs({
889
1086
  type: 'DATERANGE',
890
1087
  options: _extraOpts2
891
- }))).formatRange.apply(_Intl$DateTimeFormat2, _toConsumableArray(value.slice(0, 2).map(function (val) {
1088
+ }))).formatRange.apply(_Intl$DateTimeFormat, _toConsumableArray( /** @type {[Date, Date]} */
1089
+ value.slice(0, 2).map(function (val) {
892
1090
  return typeof val === 'number' ? new Date(val) : val;
893
1091
  })));
894
1092
  }
@@ -912,13 +1110,14 @@ var Formatter = /*#__PURE__*/_createClass(function Formatter() {
912
1110
  });
913
1111
 
914
1112
  /**
915
- * @param {PlainObject} cfg
1113
+ * @param {object} cfg
916
1114
  * @param {string} cfg.key
917
- * @param {LocaleBody} cfg.body
1115
+ * @param {import('./getMessageForKeyByStyle.js').LocaleBody} cfg.body
918
1116
  * @param {string} cfg.type
919
1117
  * @param {"richNested"|"rich"|"plain"|
920
- * "plainNested"|MessageStyleCallback} cfg.messageStyle
921
- * @returns {string|Element}
1118
+ * "plainNested"|import('./getMessageForKeyByStyle.js').
1119
+ * MessageStyleCallback} [cfg.messageStyle="richNested"]
1120
+ * @returns {string}
922
1121
  */
923
1122
  var _getSubstitution = function getSubstitution(_ref) {
924
1123
  var key = _ref.key,
@@ -947,7 +1146,7 @@ var LocalFormatter = /*#__PURE__*/function (_Formatter) {
947
1146
  _inherits(LocalFormatter, _Formatter);
948
1147
  var _super = _createSuper(LocalFormatter);
949
1148
  /**
950
- * @param {LocalObject} locals
1149
+ * @param {import('./getMessageForKeyByStyle.js').LocalObject} locals
951
1150
  */
952
1151
  function LocalFormatter(locals) {
953
1152
  var _this;
@@ -977,12 +1176,30 @@ var LocalFormatter = /*#__PURE__*/function (_Formatter) {
977
1176
  key: "isMatch",
978
1177
  value: function isMatch(key) {
979
1178
  var components = key.slice(1).split('.');
1179
+ /** @type {import('./getMessageForKeyByStyle.js').LocaleBody} */
980
1180
  var parent = this.locals;
981
- return this.constructor.isMatchingKey(key) && components.every(function (cmpt) {
982
- var result = (cmpt in parent);
983
- parent = parent[cmpt];
984
- return result;
985
- });
1181
+ return (/** @type {typeof LocalFormatter} */this.constructor.isMatchingKey(key) && components.every(function (cmpt) {
1182
+ var result = (cmpt in parent);
1183
+ parent =
1184
+ /**
1185
+ * @type {import('./defaultLocaleResolver.js').
1186
+ * RichNestedLocaleStringBodyObject|
1187
+ * import('./defaultLocaleResolver.js').
1188
+ * PlainNestedLocaleStringBodyObject|
1189
+ * import('./defaultLocaleResolver.js').RichLocaleStringSubObject
1190
+ * }
1191
+ */
1192
+ /**
1193
+ * @type {import('./defaultLocaleResolver.js').
1194
+ * RichNestedLocaleStringBodyObject|
1195
+ * import('./defaultLocaleResolver.js').
1196
+ * PlainNestedLocaleStringBodyObject
1197
+ * }
1198
+ */
1199
+ parent[cmpt];
1200
+ return result;
1201
+ })
1202
+ );
986
1203
  }
987
1204
  /**
988
1205
  * @param {string} key
@@ -1004,7 +1221,8 @@ var RegularFormatter = /*#__PURE__*/function (_Formatter2) {
1004
1221
  _inherits(RegularFormatter, _Formatter2);
1005
1222
  var _super2 = _createSuper(RegularFormatter);
1006
1223
  /**
1007
- * @param {SubstitutionObject} substitutions
1224
+ * @param {import('./defaultLocaleResolver.js').SubstitutionObject
1225
+ * } substitutions
1008
1226
  */
1009
1227
  function RegularFormatter(substitutions) {
1010
1228
  var _this2;
@@ -1020,7 +1238,8 @@ var RegularFormatter = /*#__PURE__*/function (_Formatter2) {
1020
1238
  _createClass(RegularFormatter, [{
1021
1239
  key: "isMatch",
1022
1240
  value: function isMatch(key) {
1023
- return this.constructor.isMatchingKey(key) && key in this.substitutions;
1241
+ return (/** @type {typeof RegularFormatter} */this.constructor.isMatchingKey(key) && key in this.substitutions
1242
+ );
1024
1243
  }
1025
1244
  /**
1026
1245
  * @param {string} key
@@ -1042,8 +1261,10 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1042
1261
  _inherits(SwitchFormatter, _Formatter3);
1043
1262
  var _super3 = _createSuper(SwitchFormatter);
1044
1263
  /**
1045
- * @param {Switches} switches
1046
- * @param {SubstitutionObject} substitutions
1264
+ * @param {import('./defaultLocaleResolver.js').Switches} switches
1265
+ * @param {object} cfg
1266
+ * @param {import('./defaultLocaleResolver.js').
1267
+ * SubstitutionObject} cfg.substitutions
1047
1268
  */
1048
1269
  function SwitchFormatter(switches, _ref2) {
1049
1270
  var _this3;
@@ -1057,11 +1278,12 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1057
1278
 
1058
1279
  /**
1059
1280
  * @param {string} key
1060
- * @param {PlainObject} cfg
1281
+ * @param {object} cfg
1061
1282
  * @param {string} cfg.locale
1062
- * @param {string[]} cfg.usedKeys
1283
+ * @param {(string|undefined)[]} cfg.usedKeys
1063
1284
  * @param {string} cfg.arg
1064
- * @param {MissingSuppliedFormattersCallback} cfg.missingSuppliedFormatters
1285
+ * @param {import('./getDOMForLocaleString.js').
1286
+ * MissingSuppliedFormattersCallback} cfg.missingSuppliedFormatters
1065
1287
  * @returns {string}
1066
1288
  */
1067
1289
  _createClass(SwitchFormatter, [{
@@ -1071,7 +1293,7 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1071
1293
  usedKeys = _ref3.usedKeys,
1072
1294
  arg = _ref3.arg,
1073
1295
  missingSuppliedFormatters = _ref3.missingSuppliedFormatters;
1074
- var ky = this.constructor.getKey(key).slice(1);
1296
+ var ky = /** @type {typeof SwitchFormatter} */this.constructor.getKey(key).slice(1);
1075
1297
  // Expression might not actually use formatter, e.g., for singular,
1076
1298
  // the conditional might just write out "one"
1077
1299
 
@@ -1081,7 +1303,9 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1081
1303
  body = _this$getMatch2[1],
1082
1304
  keySegment = _this$getMatch2[2];
1083
1305
  usedKeys.push(keySegment);
1084
- var type, opts;
1306
+ var type;
1307
+ /** @type {string} */
1308
+ var opts;
1085
1309
  if (objKey && objKey.includes('|')) {
1086
1310
  var _objKey$split = objKey.split('|');
1087
1311
  var _objKey$split2 = _slicedToArray(_objKey$split, 3);
@@ -1102,15 +1326,26 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1102
1326
  }
1103
1327
  */
1104
1328
 
1329
+ /**
1330
+ * @param {number} value
1331
+ * @param {Intl.NumberFormatOptions|undefined} [defaultOptions]
1332
+ * @returns {string}
1333
+ */
1105
1334
  var getNumberFormat = function getNumberFormat(value, defaultOptions) {
1106
1335
  var numberOpts = parseJSONExtra(opts);
1107
1336
  return new Intl.NumberFormat(locale, _objectSpread2(_objectSpread2({}, defaultOptions), numberOpts)).format(value);
1108
1337
  };
1338
+
1339
+ /**
1340
+ * @param {number} value
1341
+ * @param {Intl.PluralRulesOptions|undefined} [defaultOptions]
1342
+ * @returns {Intl.LDMLPluralRule}
1343
+ */
1109
1344
  var getPluralFormat = function getPluralFormat(value, defaultOptions) {
1110
1345
  var pluralOpts = parseJSONExtra(opts);
1111
1346
  return new Intl.PluralRules(locale, _objectSpread2(_objectSpread2({}, defaultOptions), pluralOpts)).select(value);
1112
1347
  };
1113
- var formatterValue = this.substitutions[keySegment];
1348
+ var formatterValue = this.substitutions[/** @type {string} */keySegment];
1114
1349
  var match = formatterValue;
1115
1350
  if (typeof formatterValue === 'number') {
1116
1351
  switch (type) {
@@ -1128,7 +1363,13 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1128
1363
  var singleKey = Object.keys(formatterValue)[0];
1129
1364
  if (['number', 'plural'].includes(singleKey)) {
1130
1365
  var _getFormatterInfo = getFormatterInfo({
1131
- object: formatterValue[singleKey]
1366
+ object:
1367
+ /**
1368
+ * @type {import('./defaultLocaleResolver.js').NumberInfo|
1369
+ * import('./defaultLocaleResolver.js').PluralInfo}
1370
+ */
1371
+ // @ts-expect-error Ok
1372
+ formatterValue[/** @type {"number"|"plural"} */singleKey]
1132
1373
  }),
1133
1374
  value = _getFormatterInfo.value,
1134
1375
  options = _getFormatterInfo.options;
@@ -1142,10 +1383,12 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1142
1383
  // eslint-disable-next-line default-case
1143
1384
  switch (type) {
1144
1385
  case 'NUMBER':
1145
- match = getNumberFormat(value, options);
1386
+ match = getNumberFormat( /** @type {number} */value, /** @type {Intl.NumberFormatOptions} */
1387
+ options);
1146
1388
  break;
1147
1389
  case 'PLURAL':
1148
- match = getPluralFormat(value, options);
1390
+ match = getPluralFormat( /** @type {number} */value, /** @type {Intl.PluralRulesOptions} */
1391
+ options);
1149
1392
  break;
1150
1393
  }
1151
1394
  }
@@ -1154,13 +1397,18 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1154
1397
  // We do not want the default `richNested` here as that will split
1155
1398
  // up the likes of `0.0`
1156
1399
  var messageStyle = 'richNested';
1400
+
1401
+ /**
1402
+ * @param {string} s
1403
+ * @returns {string}
1404
+ */
1157
1405
  var preventNesting = function preventNesting(s) {
1158
1406
  return s.replace(/\\/g, '\\\\').replace(/\./g, '\\.');
1159
1407
  };
1160
1408
  try {
1161
1409
  return _getSubstitution({
1162
1410
  messageStyle: messageStyle,
1163
- key: match ? preventNesting(match) : arg,
1411
+ key: match ? preventNesting( /** @type {string} */match) : arg,
1164
1412
  body: body,
1165
1413
  type: 'switch'
1166
1414
  });
@@ -1168,7 +1416,7 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1168
1416
  try {
1169
1417
  return _getSubstitution({
1170
1418
  messageStyle: messageStyle,
1171
- key: '*' + preventNesting(match),
1419
+ key: '*' + preventNesting( /** @type {string} */match),
1172
1420
  body: body,
1173
1421
  type: 'switch'
1174
1422
  });
@@ -1196,16 +1444,21 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1196
1444
  }, {
1197
1445
  key: "isMatch",
1198
1446
  value: function isMatch(key) {
1199
- return key && this.constructor.isMatchingKey(key) && Boolean(this.getMatch(key.slice(1)).length);
1447
+ return Boolean(key && /** @type {typeof SwitchFormatter} */this.constructor.isMatchingKey(key) && this.getMatch(key.slice(1)).length);
1200
1448
  }
1201
1449
 
1202
1450
  /**
1203
- * @typedef {GenericArray} SwitchMatch
1204
- * @property {string} 0 objKey
1205
- * @property {LocaleBody} 1 body
1206
- * @property {string} 2 keySegment
1451
+ * @typedef {[
1452
+ * objKey?: string,
1453
+ * body?: import('./getMessageForKeyByStyle.js').LocaleBody,
1454
+ * keySegment?: string
1455
+ * ]} SwitchMatch
1207
1456
  */
1208
1457
 
1458
+ /**
1459
+ * @typedef {number} Integer
1460
+ */
1461
+
1209
1462
  /**
1210
1463
  * @param {string} ky
1211
1464
  * @returns {SwitchMatch}
@@ -1215,7 +1468,19 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1215
1468
  value: function getMatch(ky) {
1216
1469
  var _this4 = this;
1217
1470
  var ks = ky.split('.');
1218
- return ks.reduce(function (obj, k, i) {
1471
+ var returnValue = /** @type {unknown} */ks.reduce(
1472
+ /**
1473
+ * @param {import('./defaultLocaleResolver.js').SwitchArrays|
1474
+ * import('./defaultLocaleResolver.js').SwitchArray} obj
1475
+ * @param {string} k
1476
+ * @param {Integer} i
1477
+ * @throws {Error}
1478
+ * @returns {SwitchMatch|
1479
+ * import('./defaultLocaleResolver.js').SwitchCaseArray|
1480
+ * import('./defaultLocaleResolver.js').SwitchArray}
1481
+ */
1482
+ // @ts-expect-error It works
1483
+ function (obj, k, i) {
1219
1484
  if (i < ks.length - 1) {
1220
1485
  if (!(k in obj)) {
1221
1486
  throw new Error("Switch key \"".concat(k, "\" not found (from \"~").concat(ky, "\")"));
@@ -1227,10 +1492,12 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1227
1492
  var ret = Object.entries(obj).find(function (_ref4) {
1228
1493
  var _ref5 = _slicedToArray(_ref4, 1),
1229
1494
  switchKey = _ref5[0];
1230
- return k === _this4.constructor.getKey(switchKey);
1495
+ return k === /** @type {typeof SwitchFormatter} */_this4.constructor.getKey(switchKey);
1231
1496
  });
1232
1497
  return ret ? [].concat(_toConsumableArray(ret), [k]) : [];
1233
1498
  }, this.switches);
1499
+ return (/** @type {SwitchMatch} */returnValue
1500
+ );
1234
1501
  }
1235
1502
 
1236
1503
  /**
@@ -1249,18 +1516,17 @@ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1249
1516
  }, {
1250
1517
  key: "getKey",
1251
1518
  value: function getKey(key) {
1252
- var match = key.match(/^(?:(?!\|)[\s\S])*/);
1253
- return match && match[0];
1519
+ var match = key.match(/^(?:[\0-\{\}-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*/);
1520
+ return (/** @type {string} */match && match[0]
1521
+ );
1254
1522
  }
1255
1523
  }]);
1256
1524
  return SwitchFormatter;
1257
1525
  }(Formatter);
1258
1526
 
1259
1527
  /**
1260
- * @callback PromiseChainErrback
1261
- * @param {(value: any) => Promise<any>} errBack
1262
- * @returns {Promise<any>|any}
1263
- */
1528
+ * @typedef {(value: any) => Promise<any>|any} PromiseChainErrback
1529
+ */
1264
1530
 
1265
1531
  /**
1266
1532
  * The given array will have its items processed in series; if the supplied
@@ -1517,92 +1783,201 @@ var promiseChainForValues = function promiseChainForValues(values, errBack) {
1517
1783
  };
1518
1784
 
1519
1785
  /**
1520
- * @callback SubstitutionCallback
1521
- * @param {PlainObject} cfg
1522
- * @param {string} cfg.arg By default, accepts the third portion of the
1786
+ * `arg` - By default, accepts the third portion of the
1523
1787
  * `formattingRegex` within `insertNodes`, i.e., to allow the locale to
1524
1788
  * supply arguments back to the calling script.
1525
- * @param {string} cfg.key The substitution key
1789
+ * `key` - The substitution key.
1790
+ * @callback SubstitutionCallback
1791
+ * @param {{
1792
+ * arg: string,
1793
+ * key: string
1794
+ * }} cfg
1526
1795
  * @returns {string|Element} The replacement text or element
1527
1796
  */
1528
1797
 
1529
1798
  /**
1530
1799
  * May have additional properties if supplying options to an underlying
1531
1800
  * formatter.
1532
- * @typedef {GenericArray} ValueArray
1533
- * @property {string|Node|number|Date} 0 The main value
1534
- * @property {PlainObject} [1] The options related to the main value
1535
- * @property {PlainObject} [2] Any additional options
1536
- */
1801
+ * The first value is the main value.
1802
+ * The second are the options related to the main value.
1803
+ * The third are any additional options.
1804
+ * @typedef {[string|number|Date, object?, object?]} ValueArray
1805
+ */
1537
1806
 
1538
1807
  /**
1539
- * @typedef {PlainObject} RelativeTimeInfo
1540
- * @property {ValueArray} relative
1541
- */
1808
+ * @typedef {number} Integer
1809
+ */
1542
1810
 
1543
1811
  /**
1544
- * @typedef {PlainObject} ListInfo
1545
- * @property {ValueArray} list
1546
- */
1812
+ * @typedef {[
1813
+ * string[],
1814
+ * (((item: string, i: Integer) => Element)|object)?,
1815
+ * object?,
1816
+ * object?
1817
+ * ]} ListValueArray
1818
+ */
1547
1819
 
1548
1820
  /**
1549
- * @typedef {PlainObject} NumberInfo
1550
- * @property {ValueArray} number
1551
- */
1821
+ * @typedef {[
1822
+ * Date|number, Date|number, Intl.DateTimeFormatOptions|undefined
1823
+ * ]} DateRangeValueArray
1824
+ */
1552
1825
 
1553
1826
  /**
1554
- * @typedef {PlainObject} DateInfo
1555
- * @property {ValueArray} date
1556
- */
1827
+ * @typedef {[number, Intl.RelativeTimeFormatUnit, object?]} RelativeValueArray
1828
+ */
1557
1829
 
1558
1830
  /**
1559
- * @typedef {Object<string, string>} PlainLocaleStringBodyObject
1560
- */
1831
+ * @typedef {object} RelativeTimeInfo
1832
+ * @property {RelativeValueArray} relative
1833
+ */
1561
1834
 
1562
1835
  /**
1563
- * @typedef {PlainObject} SwitchCaseInfo
1564
- * @property {boolean} [default=false] Whether this conditional is the default
1565
- */
1836
+ * @typedef {object} ListInfo
1837
+ * @property {ListValueArray} list
1838
+ */
1566
1839
 
1567
1840
  /**
1568
- * @typedef {GenericArray} SwitchCase
1569
- * @property {string} 0 The type
1570
- * @property {string} 1 The message
1571
- * @property {SwitchCaseInfo} [2] Info about the switch case
1572
- */
1841
+ * @typedef {object} NumberInfo
1842
+ * @property {ValueArray|number} number
1843
+ */
1573
1844
 
1574
1845
  /**
1575
- * @typedef {PlainObject<string, SwitchCase>} Switch
1576
- */
1846
+ * @typedef {object} DateInfo
1847
+ * @property {ValueArray} date
1848
+ */
1577
1849
 
1578
1850
  /**
1579
- * @typedef {PlainObject<{string, Switch}>} Switches
1580
- */
1851
+ * @typedef {object} DateTimeInfo
1852
+ * @property {ValueArray} datetime
1853
+ */
1581
1854
 
1582
1855
  /**
1583
- * @typedef {PlainObject} LocaleStringSubObject
1584
- * @property {string} [message] The locale message with any formatting
1585
- * place-holders; defaults to use of any single conditional
1586
- * @property {string} [description] A description to add translators
1587
- * @property {Switches} [switches] Conditionals
1588
- */
1856
+ * @typedef {object} DateRangeInfo
1857
+ * @property {DateRangeValueArray} dateRange
1858
+ */
1589
1859
 
1590
1860
  /**
1591
- * @typedef {PlainObject<string, LocaleStringSubObject>} LocaleStringBodyObject
1592
- */
1861
+ * @typedef {object} DatetimeRangeInfo
1862
+ * @property {DateRangeValueArray} datetimeRange
1863
+ */
1864
+
1865
+ /**
1866
+ * @typedef {object} RegionInfo
1867
+ * @property {ValueArray} region
1868
+ */
1869
+
1870
+ /**
1871
+ * @typedef {object} LanguageInfo
1872
+ * @property {ValueArray} language
1873
+ */
1874
+
1875
+ /**
1876
+ * @typedef {object} ScriptInfo
1877
+ * @property {ValueArray} script
1878
+ */
1879
+
1880
+ /**
1881
+ * @typedef {object} CurrencyInfo
1882
+ * @property {ValueArray} currency
1883
+ */
1884
+
1885
+ /**
1886
+ * @typedef {object} PluralInfo
1887
+ * @property {ValueArray} plural
1888
+ */
1889
+
1890
+ /**
1891
+ * @typedef {{[key: string]: string}} PlainLocaleStringBodyObject
1892
+ */
1893
+
1894
+ /**
1895
+ * @typedef {{
1896
+ * [key: string]: string|PlainNestedLocaleStringBodyObject
1897
+ * }} PlainNestedLocaleStringBodyObject
1898
+ */
1899
+
1900
+ /**
1901
+ * @typedef {object} SwitchCaseInfo
1902
+ * @property {boolean} [default=false] Whether this conditional is the default
1903
+ */
1904
+
1905
+ /**
1906
+ * Contains the type, the message, and optional info about the switch case.
1907
+ * @typedef {[string, string, SwitchCaseInfo?]} SwitchCaseArray
1908
+ */
1909
+
1910
+ /**
1911
+ * @typedef {Object<string, SwitchCaseArray>} SwitchArray
1912
+ */
1913
+
1914
+ /**
1915
+ * @typedef {Object<string, SwitchArray>} SwitchArrays
1916
+ */
1917
+
1918
+ /**
1919
+ * @typedef {object} SwitchCase
1920
+ * @property {string} message The locale message with any formatting
1921
+ * place-holders; defaults to use of any single conditional
1922
+ * @property {string} [description] A description to add for translators
1923
+ */
1924
+
1925
+ /**
1926
+ * @typedef {Object<string, SwitchCase>} Switch
1927
+ */
1928
+
1929
+ /**
1930
+ * @typedef {Object<string, Switch>} Switches
1931
+ */
1932
+
1933
+ /**
1934
+ * @typedef {object} RichLocaleStringSubObject
1935
+ * @property {string} message The locale message with any formatting
1936
+ * place-holders; defaults to use of any single conditional
1937
+ * @property {string} [description] A description to add for translators
1938
+ * @property {Switches} [switches] Conditionals
1939
+ */
1940
+
1941
+ /**
1942
+ * @typedef {{
1943
+ * [key: string]: RichLocaleStringSubObject
1944
+ * }} RichLocaleStringBodyObject
1945
+ */
1946
+
1947
+ /**
1948
+ * @typedef {{
1949
+ * [key: string]: RichLocaleStringSubObject|RichNestedLocaleStringBodyObject
1950
+ * }} RichNestedLocaleStringBodyObject
1951
+ */
1593
1952
 
1594
1953
  /**
1595
1954
  * Takes a base path and locale and gives a URL.
1596
1955
  * @callback LocaleResolver
1597
1956
  * @param {string} localesBasePath (Trailing slash optional)
1598
1957
  * @param {string} locale BCP-47 language string
1599
- * @returns {string} URL of the locale file to be fetched
1600
- */
1958
+ * @returns {string|false} URL of the locale file to be fetched
1959
+ */
1601
1960
 
1602
1961
  /**
1603
- * @typedef {PlainObject<string, string|Element|
1604
- * SubstitutionCallback>} SubstitutionObject
1605
- */
1962
+ * @typedef {[
1963
+ * Date|number, Date|number, (Intl.DateTimeFormatOptions|undefined)?
1964
+ * ]} DateRange
1965
+ */
1966
+
1967
+ /**
1968
+ * @typedef {string|string[]|number|Date|DateRange|
1969
+ * Element|Node|SubstitutionCallback|
1970
+ * NumberInfo|PluralInfo|CurrencyInfo|LanguageInfo|ScriptInfo|
1971
+ * DatetimeRangeInfo|DateRangeInfo|RegionInfo|DateTimeInfo|DateInfo|
1972
+ * ListInfo|RelativeTimeInfo
1973
+ * } SubstitutionObjectValue
1974
+ */
1975
+
1976
+ /**
1977
+ * @typedef {{
1978
+ * [key: string]: SubstitutionObjectValue
1979
+ * }} SubstitutionObject
1980
+ */
1606
1981
 
1607
1982
  /**
1608
1983
  * @type {LocaleResolver}
@@ -1620,29 +1995,75 @@ var defaultLocaleResolver = function defaultLocaleResolver(localesBasePath, loca
1620
1995
  return "".concat(localesBasePath.replace(/\/$/, ''), "/_locales/").concat(locale, "/messages.json");
1621
1996
  };
1622
1997
 
1623
- /* eslint-disable max-len */
1624
1998
  /**
1625
- * Callback to return a string or array of nodes and strings based on a localized
1626
- * string, substitutions object, and other metadata.
1627
- * @callback InsertNodesCallback
1628
- * @param {PlainObject} cfg
1629
- * @param {string} cfg.string The localized string
1630
- * @param {boolean} [cfg.dom] If substitutions known to contain DOM, can be set
1631
- * to `true` to optimize
1632
- * @param {string[]} [cfg.usedKeys=[]] Array for tracking which keys have been used
1633
- * @param {SubstitutionObject} cfg.substitutions The formatting substitutions object
1634
- * @param {?(AllSubstitutionCallback|AllSubstitutionCallback[])} [cfg.allSubstitutions] The
1999
+ * @typedef {number} Integer
2000
+ */
2001
+
2002
+ /**
2003
+ * @callback Replace
2004
+ * @param {{
2005
+ * str: string,
2006
+ * substs?: import('./defaultLocaleResolver.js').SubstitutionObject,
2007
+ * formatter?: import('./Formatter.js').RegularFormatter|
2008
+ * import('./Formatter.js').LocalFormatter|
2009
+ * import('./Formatter.js').SwitchFormatter
2010
+ * }} cfg
2011
+ * @returns {string}
2012
+ */
2013
+
2014
+ /**
2015
+ * @callback ProcessSubstitutions
2016
+ * @param {{
2017
+ * str: string,
2018
+ * substs?: import('./defaultLocaleResolver.js').SubstitutionObject,
2019
+ * formatter?: import('./Formatter.js').RegularFormatter|
2020
+ * import('./Formatter.js').LocalFormatter|
2021
+ * import('./Formatter.js').SwitchFormatter
2022
+ * }} cfg
2023
+ * @returns {(string|Node)[]}
2024
+ */
2025
+
2026
+ /**
2027
+ * Callback to return a string or array of nodes and strings based on
2028
+ * a localized string, substitutions object, and other metadata.
2029
+ *
2030
+ * `string` - The localized string.
2031
+ * `dom` - If substitutions known to contain DOM, can be set
2032
+ * to `true` to optimize.
2033
+ * `usedKeys` - Array for tracking which keys have been used. Defaults
2034
+ * to empty array.
2035
+ * `substitutions` - The formatting substitutions object.
2036
+ * `allSubstitutions` - The
1635
2037
  * callback or array composed thereof for applying to each substitution.
1636
- * @param {string} locale The successfully resolved locale
1637
- * @param {Integer} [maximumLocalNestingDepth=3] Depth of local variable resolution to
1638
- * check before reporting a recursion error
1639
- * @param {MissingSuppliedFormattersCallback} [cfg.missingSuppliedFormatters] Callback
2038
+ * `locale` - The successfully resolved locale
2039
+ * `locals` - The local section.
2040
+ * `switches` - The switch section.
2041
+ * `maximumLocalNestingDepth` - Depth of local variable resolution to
2042
+ * check before reporting a recursion error. Defaults to 3.
2043
+ * `missingSuppliedFormatters` - Callback
1640
2044
  * supplied key to throw if the supplied key is present (if
1641
2045
  * `throwOnMissingSuppliedFormatters` is enabled). Defaults to no-op.
1642
- * @param {CheckExtraSuppliedFormattersCallback} [cfg.checkExtraSuppliedFormatters] No
2046
+ * `checkExtraSuppliedFormatters` - No
1643
2047
  * argument callback to check if any formatters are not present in `string`
1644
2048
  * (if `throwOnExtraSuppliedFormatters` is enabled). Defaults to no-op.
1645
- * @returns {string|Array<Node|string>}
2049
+ * @typedef {(cfg: {
2050
+ * string: string,
2051
+ * dom?: boolean,
2052
+ * usedKeys: string[],
2053
+ * substitutions: import('./defaultLocaleResolver.js').SubstitutionObject,
2054
+ * allSubstitutions?: ?(
2055
+ * import('./defaultAllSubstitutions.js').AllSubstitutionCallback|
2056
+ * import('./defaultAllSubstitutions.js').AllSubstitutionCallback[]
2057
+ * )
2058
+ * locale: string|undefined,
2059
+ * locals?: import('./getMessageForKeyByStyle.js').LocalObject|undefined,
2060
+ * switches: import('./defaultLocaleResolver.js').Switches|undefined,
2061
+ * maximumLocalNestingDepth?: Integer,
2062
+ * missingSuppliedFormatters: import('./getDOMForLocaleString.js').
2063
+ * MissingSuppliedFormattersCallback,
2064
+ * checkExtraSuppliedFormatters: import('./getDOMForLocaleString.js').
2065
+ * CheckExtraSuppliedFormattersCallback
2066
+ * }) => string|(Node|string)[]} InsertNodesCallback
1646
2067
  */
1647
2068
 
1648
2069
  /**
@@ -1675,29 +2096,49 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1675
2096
  });
1676
2097
  };
1677
2098
  addFunctionKeys();
1678
- var localFormatter = new LocalFormatter(locals);
2099
+ var localFormatter = new LocalFormatter( /** @type {import('./getMessageForKeyByStyle.js').LocalObject} */locals);
1679
2100
  var regularFormatter = new RegularFormatter(substitutions);
1680
- var switchFormatter = new SwitchFormatter(switches, {
2101
+ var switchFormatter = new SwitchFormatter( /** @type {import('./defaultLocaleResolver.js').Switches} */
2102
+ switches, {
1681
2103
  substitutions: substitutions
1682
2104
  });
1683
2105
 
1684
2106
  // eslint-disable-next-line max-len
1685
2107
  // eslint-disable-next-line prefer-named-capture-group, unicorn/no-unsafe-regex
1686
- var formattingRegex = /(\\*)\{((?:(?:(?!\})[\s\S])|\\\})*?)(?:(\|)((?:(?!\})[\s\S])*))?\}/g;
2108
+ var formattingRegex = /(\\*)\{((?:(?:[\0-\|~-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])|\\\})*?)(?:(\|)((?:[\0-\|~-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*))?\}/g;
1687
2109
  if (allSubstitutions) {
1688
2110
  allSubstitutions = Array.isArray(allSubstitutions) ? allSubstitutions : [allSubstitutions];
1689
2111
  }
2112
+
2113
+ /**
2114
+ * @param {{
2115
+ * key: string,
2116
+ * arg: string,
2117
+ * substs: import('./defaultLocaleResolver.js').SubstitutionObject
2118
+ * }} cfg
2119
+ * @returns {string|Node}
2120
+ */
1690
2121
  var getSubstitution = function getSubstitution(_ref4) {
1691
2122
  var key = _ref4.key,
1692
2123
  arg = _ref4.arg,
1693
2124
  substs = _ref4.substs;
2125
+ /** @type {import('./defaultLocaleResolver.js').SubstitutionObjectValue} */
1694
2126
  var substitution;
1695
- var isLocalKey = localFormatter.constructor.isMatchingKey(key);
2127
+ var isLocalKey =
2128
+ /**
2129
+ * @type {typeof import('./Formatter.js').LocalFormatter}
2130
+ */
2131
+ localFormatter.constructor.isMatchingKey(key);
1696
2132
  if (isLocalKey) {
1697
2133
  substitution = localFormatter.getSubstitution(key);
1698
- } else if (switchFormatter.constructor.isMatchingKey(key)) {
2134
+ } else if (
2135
+ /**
2136
+ * @type {typeof import('./Formatter.js').SwitchFormatter}
2137
+ */
2138
+ switchFormatter.constructor.isMatchingKey(key)) {
1699
2139
  substitution = switchFormatter.getSubstitution(key, {
1700
- locale: locale,
2140
+ // eslint-disable-next-line object-shorthand -- TS casting
2141
+ locale: /** @type {string} */locale,
1701
2142
  usedKeys: usedKeys,
1702
2143
  arg: arg,
1703
2144
  missingSuppliedFormatters: missingSuppliedFormatters
@@ -1716,7 +2157,20 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1716
2157
  // a mode to throw for non-string/non-DOM (non-numbers?),
1717
2158
  // or whatever is not likely intended as a target for `toString()`.
1718
2159
  if (allSubstitutions) {
1719
- substitution = allSubstitutions.reduce(function (subst, allSubst) {
2160
+ substitution = /** @type {string|Node} */
2161
+ /**
2162
+ * @type {import('./defaultAllSubstitutions.js').
2163
+ * AllSubstitutionCallback[]
2164
+ * }
2165
+ */allSubstitutions.reduce(
2166
+ /**
2167
+ * @param {import('./defaultLocaleResolver.js').
2168
+ * SubstitutionObjectValue} subst
2169
+ * @param {import('./defaultAllSubstitutions.js').
2170
+ * AllSubstitutionCallback} allSubst
2171
+ * @returns {string|Node}
2172
+ */
2173
+ function (subst, allSubst) {
1720
2174
  return allSubst({
1721
2175
  value: subst,
1722
2176
  arg: arg,
@@ -1732,26 +2186,40 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1732
2186
  locale: locale
1733
2187
  });
1734
2188
  }
1735
- return substitution;
2189
+
2190
+ // Change this and return type if other substitutions possible
2191
+ return (/** @type {string|Node} */substitution
2192
+ );
1736
2193
  };
1737
2194
  var recursiveLocalCount = 1;
2195
+ /**
2196
+ * @param {{
2197
+ * substitution: string|Node,
2198
+ * ky: string,
2199
+ * arg: string,
2200
+ * processSubsts: Replace|ProcessSubstitutions
2201
+ * }} cfg
2202
+ * @returns {number|string|Node|(string|Node)[]}
2203
+ */
1738
2204
  var checkLocalVars = function checkLocalVars(_ref5) {
1739
2205
  var substitution = _ref5.substitution,
1740
2206
  ky = _ref5.ky,
1741
2207
  arg = _ref5.arg,
1742
2208
  processSubsts = _ref5.processSubsts;
2209
+ /** @type {number|string|Node|(string|Node)[]} */
2210
+ var subst = substitution;
1743
2211
  if (typeof substitution === 'string' && substitution.includes('{')) {
1744
2212
  if (recursiveLocalCount++ > maximumLocalNestingDepth) {
1745
2213
  throw new TypeError('Too much recursion in local variables.');
1746
2214
  }
1747
- if (localFormatter.constructor.isMatchingKey(ky)) {
2215
+ if ( /** @type {typeof import('./Formatter.js').LocalFormatter} */localFormatter.constructor.isMatchingKey(ky)) {
1748
2216
  var extraSubsts = substitutions;
1749
2217
  var localFormatters;
1750
2218
  if (arg) {
1751
2219
  localFormatters = parseJSONExtra(arg);
1752
2220
  extraSubsts = _objectSpread2(_objectSpread2({}, substitutions), localFormatters);
1753
2221
  }
1754
- substitution = processSubsts({
2222
+ subst = processSubsts({
1755
2223
  str: substitution,
1756
2224
  substs: extraSubsts,
1757
2225
  formatter: localFormatter
@@ -1761,26 +2229,38 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1761
2229
  substitutions: localFormatters
1762
2230
  });
1763
2231
  }
1764
- } else if (switchFormatter.constructor.isMatchingKey(ky)) {
1765
- substitution = processSubsts({
2232
+ } else if ( /** @type {typeof import('./Formatter.js').SwitchFormatter} */
2233
+ switchFormatter.constructor.isMatchingKey(ky)) {
2234
+ subst = processSubsts({
1766
2235
  str: substitution
1767
2236
  });
1768
2237
  }
1769
2238
  }
1770
- return substitution;
2239
+ return subst;
1771
2240
  };
1772
2241
 
1773
2242
  // Give chance to avoid this block when known to contain DOM
1774
2243
  if (!dom) {
1775
2244
  // Run this block to optimize non-DOM substitutions
1776
2245
  var returnsDOM = false;
2246
+
2247
+ /** @type {Replace} */
1777
2248
  var replace = function replace(_ref6) {
1778
2249
  var str = _ref6.str,
1779
2250
  _ref6$substs = _ref6.substs,
1780
2251
  substs = _ref6$substs === void 0 ? substitutions : _ref6$substs,
1781
2252
  _ref6$formatter = _ref6.formatter,
1782
2253
  formatter = _ref6$formatter === void 0 ? regularFormatter : _ref6$formatter;
1783
- return str.replace(formattingRegex, function (_, esc, ky, pipe, arg) {
2254
+ return str.replace(formattingRegex,
2255
+ /**
2256
+ * @param {string} _
2257
+ * @param {string} esc
2258
+ * @param {string} ky
2259
+ * @param {string} pipe
2260
+ * @param {string} arg
2261
+ * @returns {string}
2262
+ */
2263
+ function (_, esc, ky, pipe, arg) {
1784
2264
  if (esc.length % 2) {
1785
2265
  return _;
1786
2266
  }
@@ -1790,6 +2270,7 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1790
2270
  })) {
1791
2271
  return _;
1792
2272
  }
2273
+ /** @type {string|number|Node|(string|Node)[]} */
1793
2274
  var substitution = getSubstitution({
1794
2275
  key: ky,
1795
2276
  arg: arg,
@@ -1801,7 +2282,7 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1801
2282
  arg: arg,
1802
2283
  processSubsts: replace
1803
2284
  });
1804
- returnsDOM = returnsDOM || substitution && _typeof(substitution) === 'object' && 'nodeType' in substitution;
2285
+ returnsDOM = returnsDOM || substitution !== null && _typeof(substitution) === 'object' && 'nodeType' in substitution;
1805
2286
  usedKeys.push(ky);
1806
2287
  return esc + substitution;
1807
2288
  });
@@ -1821,18 +2302,25 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1821
2302
  addFunctionKeys();
1822
2303
  }
1823
2304
  recursiveLocalCount = 1;
2305
+
2306
+ /** @type {ProcessSubstitutions} */
1824
2307
  var processSubstitutions = function processSubstitutions(_ref7) {
1825
2308
  var str = _ref7.str,
1826
2309
  _ref7$substs = _ref7.substs,
1827
2310
  substs = _ref7$substs === void 0 ? substitutions : _ref7$substs,
1828
2311
  _ref7$formatter = _ref7.formatter,
1829
2312
  formatter = _ref7$formatter === void 0 ? regularFormatter : _ref7$formatter;
2313
+ /** @type {(string|Node)[]} */
1830
2314
  var nodes = [];
1831
2315
 
1832
2316
  // Copy to ensure we are resetting index on each instance (manually
1833
2317
  // resetting on `formattingRegex` is problematic with recursion that
1834
2318
  // uses the same regex copy)
1835
2319
  var regex = new RegExp(formattingRegex, 'gu');
2320
+
2321
+ /**
2322
+ * @param {...(string|Node)} args
2323
+ */
1836
2324
  var push = function push() {
1837
2325
  nodes.push.apply(nodes, arguments);
1838
2326
  };
@@ -1848,6 +2336,8 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1848
2336
  if (esc.length) {
1849
2337
  push(esc);
1850
2338
  }
2339
+
2340
+ /** @type {string|number|Node|(string|Node)[]} */
1851
2341
  var substitution = getSubstitution({
1852
2342
  key: ky,
1853
2343
  arg: arg,
@@ -1867,7 +2357,8 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1867
2357
  substitution && _typeof(substitution) === 'object' && 'nodeType' in substitution) {
1868
2358
  push(substitution.cloneNode(true));
1869
2359
  } else {
1870
- push(substitution);
2360
+ // Why no number here?
2361
+ push( /** @type {string} */substitution);
1871
2362
  }
1872
2363
  }
1873
2364
  usedKeys.push(ky);
@@ -1895,7 +2386,9 @@ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1895
2386
  * @param {string|string[]} key By default may be an array (if the type ends
1896
2387
  * with "Nested") or a string, but a non-default validator may do otherwise.
1897
2388
  * @param {"plain"|"plainNested"|"rich"|
1898
- * "richNested"|MessageStyleCallback} messageStyle
2389
+ * "richNested"|
2390
+ * import('./getMessageForKeyByStyle.js').MessageStyleCallback
2391
+ * } messageStyle
1899
2392
  * @throws {TypeError}
1900
2393
  * @returns {string} The converted (or unconverted) key
1901
2394
  */
@@ -1926,26 +2419,34 @@ function defaultKeyCheckerConverter(key, messageStyle) {
1926
2419
  /**
1927
2420
  * May also contain language code and direction, translator name and
1928
2421
  * contact, etc., but no defaults currently apply besides reserving `locals`
1929
- * @typedef {PlainObject} LocaleHead
1930
- * @property {LocalObject} locals
2422
+ * @typedef {object} LocaleHead
2423
+ * @property {LocalObject} [locals]
2424
+ * @property {import('./defaultLocaleResolver.js').Switches} [switches]
1931
2425
  */
1932
2426
 
1933
2427
  /**
1934
- * @typedef {LocaleStringBodyObject|
1935
- * PlainLocaleStringBodyObject|PlainObject} LocaleBody
1936
- */
2428
+ * @typedef {import('./defaultLocaleResolver.js').
2429
+ * RichNestedLocaleStringBodyObject|
2430
+ * import('./defaultLocaleResolver.js').RichLocaleStringBodyObject|
2431
+ * import('./defaultLocaleResolver.js').PlainLocaleStringBodyObject|
2432
+ * import('./defaultLocaleResolver.js').PlainNestedLocaleStringBodyObject|
2433
+ * object
2434
+ * } LocaleBody
2435
+ */
1937
2436
 
1938
2437
  /**
1939
- * @typedef {PlainObject} LocaleObject
2438
+ * @typedef {object} LocaleObject
1940
2439
  * @property {LocaleHead} [head]
1941
2440
  * @property {LocaleBody} body
1942
2441
  */
1943
2442
 
1944
2443
  /**
1945
- * @typedef {PlainObject} MessageStyleCallbackResult
1946
- * @property {string} value Regardless of message style, will contain the
1947
- * string result
1948
- * @property {LocaleStringSubObject} [info] Full info on the localized item
2444
+ * @typedef {object} MessageStyleCallbackResult
2445
+ * @property {string} value Regardless of message style, will contain
2446
+ * the string result
2447
+ * @property {import(
2448
+ * './defaultLocaleResolver.js'
2449
+ * ).RichLocaleStringSubObject} [info] Full info on the localized item
1949
2450
  * (for rich message styles only)
1950
2451
  */
1951
2452
 
@@ -1959,7 +2460,7 @@ function defaultKeyCheckerConverter(key, messageStyle) {
1959
2460
 
1960
2461
  /* eslint-disable max-len */
1961
2462
  /**
1962
- * @param {PlainObject} [cfg]
2463
+ * @param {object} [cfg]
1963
2464
  * @param {"richNested"|"rich"|"plain"|"plainNested"|MessageStyleCallback} [cfg.messageStyle="richNested"]
1964
2465
  * @returns {MessageStyleCallback}
1965
2466
  */
@@ -1968,10 +2469,25 @@ var getMessageForKeyByStyle = function getMessageForKeyByStyle() {
1968
2469
  _ref$messageStyle = _ref.messageStyle,
1969
2470
  messageStyle = _ref$messageStyle === void 0 ? 'richNested' : _ref$messageStyle;
1970
2471
  return typeof messageStyle === 'function' ? messageStyle : messageStyle === 'richNested' ? function (mainObj, key) {
1971
- var obj = mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2472
+ var obj =
2473
+ /**
2474
+ * @type {import('./defaultLocaleResolver.js').
2475
+ * RichNestedLocaleStringBodyObject
2476
+ * }
2477
+ */
2478
+ mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2479
+
2480
+ /**
2481
+ * @type {string[]}
2482
+ */
1972
2483
  var keys = [];
1973
2484
  // eslint-disable-next-line prefer-named-capture-group
1974
2485
  var possiblyEscapedCharPattern = /(\\*)\./g;
2486
+
2487
+ /**
2488
+ * @param {string} val
2489
+ * @returns {void}
2490
+ */
1975
2491
  var mergeWithPreviousOrStart = function mergeWithPreviousOrStart(val) {
1976
2492
  if (!keys.length) {
1977
2493
  keys[0] = '';
@@ -1993,6 +2509,14 @@ var getMessageForKeyByStyle = function getMessageForKeyByStyle() {
1993
2509
  var keysUnescaped = keys.map(function (ky) {
1994
2510
  return unescapeBackslashes(ky);
1995
2511
  });
2512
+
2513
+ /**
2514
+ * @type {false|{
2515
+ * value: string|undefined,
2516
+ * info: import('./defaultLocaleResolver.js').
2517
+ * RichLocaleStringSubObject
2518
+ * }}
2519
+ */
1996
2520
  var ret = false;
1997
2521
  var currObj = obj;
1998
2522
  keysUnescaped.some(function (ky, i, kys) {
@@ -2005,16 +2529,33 @@ var getMessageForKeyByStyle = function getMessageForKeyByStyle() {
2005
2529
  // NECESSARY FOR SECURITY ON UNTRUSTED LOCALES
2006
2530
  typeof currObj[ky].message === 'string') {
2007
2531
  ret = {
2008
- value: currObj[ky].message,
2009
- info: currObj[ky]
2532
+ value: /** @type {string} */currObj[ky].message,
2533
+ info:
2534
+ /**
2535
+ * @type {import('./defaultLocaleResolver.js').
2536
+ * RichLocaleStringSubObject}
2537
+ */
2538
+ currObj[ky]
2010
2539
  };
2011
2540
  }
2012
- currObj = currObj[ky];
2541
+ currObj =
2542
+ /**
2543
+ * @type {import('./defaultLocaleResolver.js').
2544
+ * RichNestedLocaleStringBodyObject
2545
+ * }
2546
+ */
2547
+ currObj[ky];
2013
2548
  return false;
2014
2549
  });
2015
2550
  return ret;
2016
2551
  } : messageStyle === 'rich' ? function (mainObj, key) {
2017
- var obj = mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2552
+ var obj =
2553
+ /**
2554
+ * @type {import('./defaultLocaleResolver.js').
2555
+ * RichLocaleStringBodyObject
2556
+ * }
2557
+ */
2558
+ mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2018
2559
  if (obj && _typeof(obj) === 'object' && key in obj && obj[key] && _typeof(obj[key]) === 'object' && 'message' in obj[key] &&
2019
2560
  // NECESSARY FOR SECURITY ON UNTRUSTED LOCALES
2020
2561
  typeof obj[key].message === 'string') {
@@ -2025,7 +2566,13 @@ var getMessageForKeyByStyle = function getMessageForKeyByStyle() {
2025
2566
  }
2026
2567
  return false;
2027
2568
  } : messageStyle === 'plain' ? function (mainObj, key) {
2028
- var obj = mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2569
+ var obj =
2570
+ /**
2571
+ * @type {import('./defaultLocaleResolver.js').
2572
+ * PlainLocaleStringBodyObject
2573
+ * }
2574
+ */
2575
+ mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2029
2576
  if (obj && _typeof(obj) === 'object' && key in obj && obj[key] && typeof obj[key] === 'string') {
2030
2577
  return {
2031
2578
  value: obj[key]
@@ -2033,13 +2580,27 @@ var getMessageForKeyByStyle = function getMessageForKeyByStyle() {
2033
2580
  }
2034
2581
  return false;
2035
2582
  } : messageStyle === 'plainNested' ? function (mainObj, key) {
2036
- var obj = mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2583
+ var obj =
2584
+ /**
2585
+ * @type {import('./defaultLocaleResolver.js').
2586
+ * PlainNestedLocaleStringBodyObject
2587
+ * }
2588
+ */
2589
+ mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2037
2590
  if (obj && _typeof(obj) === 'object') {
2038
2591
  // Should really be counting that it is an odd number
2039
2592
  // of backslashes only
2040
2593
  var keys = key.split(/(?<!\\)\./);
2041
- var value = keys.reduce(function (o, k) {
2042
- if (o && o[k]) {
2594
+ var value = keys.reduce(
2595
+ /**
2596
+ * @param {null|string|import('./defaultLocaleResolver.js').
2597
+ * PlainNestedLocaleStringBodyObject} o
2598
+ * @param {string} k
2599
+ * @returns {null|string|import('./defaultLocaleResolver.js').
2600
+ * PlainNestedLocaleStringBodyObject}
2601
+ */
2602
+ function (o, k) {
2603
+ if (o && _typeof(o) === 'object' && o[k]) {
2043
2604
  return o[k];
2044
2605
  }
2045
2606
  return null;
@@ -2056,19 +2617,26 @@ var getMessageForKeyByStyle = function getMessageForKeyByStyle() {
2056
2617
  }();
2057
2618
  };
2058
2619
 
2059
- /* eslint-disable max-len */
2060
2620
  /**
2061
- * @param {PlainObject} cfg
2062
- * @param {string} [cfg.message] If present, this string will be the return value.
2063
- * @param {false|null|undefined|LocaleObject} [cfg.defaults]
2064
- * @param {"richNested"|"rich"|"plain"|"plainNested"|MessageStyleCallback} [cfg.messageStyle="richNested"]
2065
- * @param {MessageStyleCallback} [cfg.messageForKey] Defaults to getting `MessageStyleCallback` based on `messageStyle`
2066
- * @param {string} cfg.key Key to check against object of strings; used to find a default if no string `message` is provided.
2621
+ * @param {object} cfg
2622
+ * @param {string|false} [cfg.message] If present, this string will be
2623
+ * the return value.
2624
+ * @param {false|null|undefined|
2625
+ * import('./getMessageForKeyByStyle.js').LocaleObject
2626
+ * } [cfg.defaults]
2627
+ * @param {"richNested"|"rich"|"plain"|"plainNested"|
2628
+ * import('./getMessageForKeyByStyle.js').MessageStyleCallback
2629
+ * } [cfg.messageStyle="richNested"]
2630
+ * @param {import('./getMessageForKeyByStyle.js').
2631
+ * MessageStyleCallback
2632
+ * } [cfg.messageForKey] Defaults to getting `MessageStyleCallback` based
2633
+ * on `messageStyle`
2634
+ * @param {string} cfg.key Key to check against object of strings;
2635
+ * used to find a default if no string `message` is provided.
2067
2636
  * @returns {string}
2068
2637
  */
2069
- var getStringFromMessageAndDefaults = function getStringFromMessageAndDefaults() {
2070
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2071
- message = _ref.message,
2638
+ var getStringFromMessageAndDefaults = function getStringFromMessageAndDefaults(_ref) {
2639
+ var message = _ref.message,
2072
2640
  defaults = _ref.defaults,
2073
2641
  messageStyle = _ref.messageStyle,
2074
2642
  _ref$messageForKey = _ref.messageForKey,
@@ -2077,16 +2645,15 @@ var getStringFromMessageAndDefaults = function getStringFromMessageAndDefaults()
2077
2645
  }) : _ref$messageForKey,
2078
2646
  key = _ref.key;
2079
2647
  // NECESSARY CHECK FOR SECURITY ON UNTRUSTED LOCALES
2648
+ /** @type {string|false} */
2080
2649
  var str;
2081
2650
  if (typeof message === 'string') {
2082
2651
  str = message;
2083
2652
  } else if (defaults === false || defaults === undefined || defaults === null) {
2084
2653
  str = false;
2085
2654
  } else if (defaults && _typeof(defaults) === 'object') {
2086
- str = messageForKey(defaults, key);
2087
- if (str) {
2088
- str = str.value;
2089
- }
2655
+ var msg = messageForKey(defaults, key);
2656
+ str = msg ? msg.value : msg;
2090
2657
  } else {
2091
2658
  throw new TypeError("Default locale strings must resolve to `false`, " + "nullish, or an object!");
2092
2659
  }
@@ -2096,28 +2663,54 @@ var getStringFromMessageAndDefaults = function getStringFromMessageAndDefaults()
2096
2663
  return str;
2097
2664
  };
2098
2665
 
2099
- /* eslint-disable max-len */
2666
+ /**
2667
+ * @typedef {number} Integer
2668
+ */
2669
+
2670
+ /**
2671
+ * @callback CheckExtraSuppliedFormattersCallback
2672
+ * @param {import('./defaultLocaleResolver.js').SubstitutionObject|{
2673
+ * substitutions: import('./defaultLocaleResolver.js').SubstitutionObject
2674
+ * }} substs (Why is an arg. of `substitutions` being passed in?)
2675
+ * @throws {Error} Upon an extra formatting key being found
2676
+ * @returns {void}
2677
+ */
2678
+
2679
+ /**
2680
+ * @typedef {(
2681
+ * cfg: {
2682
+ * key: string,
2683
+ * formatter: import('./Formatter.js').LocalFormatter|
2684
+ * import('./Formatter.js').RegularFormatter|
2685
+ * import('./Formatter.js').SwitchFormatter
2686
+ * }
2687
+ * ) => boolean} MissingSuppliedFormattersCallback
2688
+ */
2689
+
2100
2690
  /**
2101
2691
  *
2102
- * @param {PlainObject} cfg
2692
+ * @param {object} cfg
2103
2693
  * @param {string} cfg.string
2104
- * @param {string} cfg.locale The (possibly already resolved) locale for use by
2105
- * configuring formatters
2106
- * @param {LocalObject} [cfg.locals]
2107
- * @param {LocalObject} [cfg.switches]
2694
+ * @param {string} [cfg.locale] The (possibly already resolved) locale
2695
+ * for use by configuring formatters
2696
+ * @param {import('./getMessageForKeyByStyle.js').LocalObject} [cfg.locals]
2697
+ * @param {import('./defaultLocaleResolver.js').Switches} [cfg.switches]
2108
2698
  * @param {Integer} [cfg.maximumLocalNestingDepth=3]
2109
- * @param {?(AllSubstitutionCallback|AllSubstitutionCallback[])} [cfg.allSubstitutions=[defaultAllSubstitutions]]
2110
- * @param {InsertNodesCallback} [cfg.insertNodes=defaultInsertNodes]
2111
- * @param {false|SubstitutionObject} [cfg.substitutions=false]
2699
+ * @param {?(import('./defaultAllSubstitutions.js').AllSubstitutionCallback|
2700
+ * import('./defaultAllSubstitutions.js').AllSubstitutionCallback[])
2701
+ * } [cfg.allSubstitutions=[defaultAllSubstitutions]]
2702
+ * @param {import('./defaultInsertNodes.js').InsertNodesCallback
2703
+ * } [cfg.insertNodes=defaultInsertNodes]
2704
+ * @param {false|import('./defaultLocaleResolver.js').SubstitutionObject
2705
+ * } [cfg.substitutions=false]
2112
2706
  * @param {boolean} [cfg.dom=false]
2113
2707
  * @param {boolean} [cfg.forceNodeReturn=false]
2114
2708
  * @param {boolean} [cfg.throwOnMissingSuppliedFormatters=true]
2115
2709
  * @param {boolean} [cfg.throwOnExtraSuppliedFormatters=true]
2116
- * @returns {string|DocumentFragment}
2710
+ * @returns {string|Text|DocumentFragment}
2117
2711
  */
2118
- var getDOMForLocaleString = function getDOMForLocaleString() {
2119
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2120
- string = _ref.string,
2712
+ var getDOMForLocaleString = function getDOMForLocaleString(_ref) {
2713
+ var string = _ref.string,
2121
2714
  locale = _ref.locale,
2122
2715
  locals = _ref.locals,
2123
2716
  switches = _ref.switches;
@@ -2139,18 +2732,18 @@ var getDOMForLocaleString = function getDOMForLocaleString() {
2139
2732
  if (typeof string !== 'string') {
2140
2733
  throw new TypeError('An options object with a `string` property set to a string must ' + 'be provided for `getDOMForLocaleString`.');
2141
2734
  }
2735
+
2736
+ /**
2737
+ * @param {string} str
2738
+ * @returns {Text|string}
2739
+ */
2142
2740
  var stringOrTextNode = function stringOrTextNode(str) {
2143
2741
  var _doc = getDocument();
2144
- return forceNodeReturn ? _doc.createTextNode(str) : str;
2742
+ return forceNodeReturn ? /** @type {Document} */_doc.createTextNode(str) : str;
2145
2743
  };
2146
- var usedKeys = [];
2147
2744
 
2148
- /**
2149
- * @callback CheckExtraSuppliedFormattersCallback
2150
- * @param {SubstitutionObject} substs
2151
- * @throws {Error} Upon an extra formatting key being found
2152
- * @returns {void}
2153
- */
2745
+ /** @type {string[]} */
2746
+ var usedKeys = [];
2154
2747
 
2155
2748
  /**
2156
2749
  * @type {CheckExtraSuppliedFormattersCallback}
@@ -2166,13 +2759,6 @@ var getDOMForLocaleString = function getDOMForLocaleString() {
2166
2759
  }
2167
2760
  };
2168
2761
 
2169
- /**
2170
- * @callback MissingSuppliedFormattersCallback
2171
- * @param {string} key
2172
- * @param {SubstitutionObject} substs
2173
- * @throws {Error} If missing formatting key
2174
- * @returns {boolean}
2175
- */
2176
2762
  /**
2177
2763
  * @type {MissingSuppliedFormattersCallback}
2178
2764
  */
@@ -2180,7 +2766,13 @@ var getDOMForLocaleString = function getDOMForLocaleString() {
2180
2766
  var key = _ref3.key,
2181
2767
  formatter = _ref3.formatter;
2182
2768
  var matching = formatter.isMatch(key);
2183
- if (formatter.constructor.isMatchingKey(key) && !matching) {
2769
+ if (
2770
+ /**
2771
+ * @type {typeof import('./Formatter.js').LocalFormatter|
2772
+ * typeof import('./Formatter.js').RegularFormatter|
2773
+ * typeof import('./Formatter.js').SwitchFormatter}
2774
+ */
2775
+ formatter.constructor.isMatchingKey(key) && !matching) {
2184
2776
  if (throwOnMissingSuppliedFormatters) {
2185
2777
  throw new Error("Missing formatting key: ".concat(key));
2186
2778
  }
@@ -2210,7 +2802,7 @@ var getDOMForLocaleString = function getDOMForLocaleString() {
2210
2802
  return stringOrTextNode(nodes);
2211
2803
  }
2212
2804
  var _doc = getDocument();
2213
- var container = _doc.createDocumentFragment();
2805
+ var container = /** @type {Document} */_doc.createDocumentFragment();
2214
2806
  container.append.apply(container, _toConsumableArray(nodes));
2215
2807
  return container;
2216
2808
  };
@@ -2265,24 +2857,34 @@ var defaultLocaleMatcher = function defaultLocaleMatcher(locale) {
2265
2857
  // Try without hyphen, i.e., the "lookup" algorithm:
2266
2858
  // See https://tools.ietf.org/html/rfc4647#section-3.4 and
2267
2859
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
2268
- return locale.replace(/\x2D(?:(?!\x2D)[\s\S])*$/, '');
2860
+ return locale.replace(/\x2D(?:[\0-,\.-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*$/, '');
2269
2861
  };
2270
2862
 
2271
2863
  /**
2272
- * @typedef {PlainObject} LocaleObjectInfo
2273
- * @property {LocaleObject} strings The successfully retrieved locale strings
2274
- * @property {string} locale The successfully resolved locale
2275
- */
2864
+ * @typedef {object} LocaleObjectInfo
2865
+ * @property {import('./getMessageForKeyByStyle.js').
2866
+ * LocaleObject} strings The successfully retrieved locale strings
2867
+ * @property {string} locale The successfully resolved locale
2868
+ */
2276
2869
 
2277
2870
  /**
2278
- * @callback LocaleStringFinder
2279
- * @param {PlainObject} [cfg={}]
2280
- * @param {string[]} [cfg.locales=navigator.languages] BCP-47 language strings
2281
- * @param {string[]} [cfg.defaultLocales=["en-US"]]
2282
- * @param {string} [cfg.localesBasePath="."]
2283
- * @param {LocaleResolver} [cfg.localeResolver=defaultLocaleResolver]
2284
- * @param {"lookup"|LocaleMatcher} [cfg.localeMatcher]
2285
- * @returns {Promise<LocaleObjectInfo>}
2871
+ * @typedef {{
2872
+ * locales?: string[],
2873
+ * defaultLocales?: string[],
2874
+ * localesBasePath?: string,
2875
+ * localeResolver?: import('./defaultLocaleResolver.js').LocaleResolver,
2876
+ * localeMatcher?: "lookup"|LocaleMatcher
2877
+ * }} LocaleStringArgs
2878
+ */
2879
+
2880
+ /**
2881
+ * `locales` - BCP-47 language strings. Defaults to `navigator.languages`.
2882
+ * `defaultLocales` - Defaults to ["en-US"].
2883
+ * `localesBasePath` - Defaults to `.`.
2884
+ * `localeResolver` - Defaults to `defaultLocaleResolver`.
2885
+ * @typedef {(
2886
+ * cfg?: LocaleStringArgs
2887
+ * ) => Promise<LocaleObjectInfo>} LocaleStringFinder
2286
2888
  */
2287
2889
 
2288
2890
  /**
@@ -2296,17 +2898,22 @@ var findLocaleStrings = function findLocaleStrings() {
2296
2898
  localeResolver = _ref2.localeResolver,
2297
2899
  localesBasePath = _ref2.localesBasePath,
2298
2900
  localeMatcher = _ref2.localeMatcher;
2299
- return _findLocale({
2300
- locales: locales,
2301
- defaultLocales: defaultLocales,
2302
- localeResolver: localeResolver,
2303
- localesBasePath: localesBasePath,
2304
- localeMatcher: localeMatcher
2305
- });
2901
+ return (/** @type {Promise<LocaleObjectInfo>} */_findLocale({
2902
+ locales: locales,
2903
+ defaultLocales: defaultLocales,
2904
+ localeResolver: localeResolver,
2905
+ localesBasePath: localesBasePath,
2906
+ localeMatcher: localeMatcher
2907
+ })
2908
+ );
2306
2909
  };
2307
2910
 
2308
2911
  /**
2309
- * @type {LocaleStringFinder|LocaleFinder} Also has a `headOnly` boolean
2912
+ * @type {(
2913
+ * cfg: LocaleStringArgs & {
2914
+ * headOnly?: boolean
2915
+ * }
2916
+ * ) => Promise<string|LocaleObjectInfo>} Also has a `headOnly` boolean
2310
2917
  * property to determine whether to make a simple HEAD and resolve to
2311
2918
  * the locale rather than locale and contents
2312
2919
  */
@@ -2315,7 +2922,7 @@ var _findLocale = _async(function (_ref4) {
2315
2922
  * @callback getLocale
2316
2923
  * @throws {SyntaxError|TypeError|Error}
2317
2924
  * @param {string} locale
2318
- * @returns {Promise<LocaleObjectInfo>}
2925
+ * @returns {Promise<LocaleObjectInfo|string>}
2319
2926
  */
2320
2927
  var getLocale = _async(function (locale) {
2321
2928
  if (typeof locale !== 'string') {
@@ -2326,7 +2933,7 @@ var _findLocale = _async(function (_ref4) {
2326
2933
  throw new TypeError('`localeResolver` expected to resolve to (URL) string.');
2327
2934
  }
2328
2935
  return _catch(function () {
2329
- var _fetch = getFetch();
2936
+ var _fetch = /** @type {import('./shared.js').Fetch} */getFetch();
2330
2937
  return _await$1(headOnly ? _fetch(url, {
2331
2938
  method: 'HEAD'
2332
2939
  }) : _fetch(url), function (resp) {
@@ -2344,10 +2951,10 @@ var _findLocale = _async(function (_ref4) {
2344
2951
  });
2345
2952
  });
2346
2953
  }, function (err) {
2347
- if (err.name === 'SyntaxError') {
2954
+ if ( /** @type {Error} */err.name === 'SyntaxError') {
2348
2955
  throw err;
2349
2956
  }
2350
- return _await$1(localeMatcher(locale), getLocale);
2957
+ return _await$1( /** @type {LocaleMatcher} */localeMatcher(locale), getLocale);
2351
2958
  });
2352
2959
  });
2353
2960
  var _ref4$locales = _ref4.locales,
@@ -2371,39 +2978,43 @@ var _findLocale = _async(function (_ref4) {
2371
2978
  });
2372
2979
 
2373
2980
  /**
2374
- * Checks a key (against an object of strings). Optionally
2375
- * accepts an object of substitutions which are used when finding text
2376
- * within curly brackets (pipe symbol not allowed in its keys); the
2377
- * substitutions may be DOM elements as well as strings and may be
2378
- * functions which return the same (being provided the text after the
2379
- * pipe within brackets as the single argument).) Optionally accepts a
2380
- * config object, with the optional key "dom" which if set to `true`
2381
- * optimizes when DOM elements are (known to be) present.
2382
- * @callback I18NCallback
2383
- * @param {string} key Key to check against object of strings
2384
- * @param {false|SubstitutionObject} [substitutions=false]
2385
- * @param {PlainObject} [cfg={}]
2386
- * @param {boolean} [cfg.dom=false]
2387
- * @returns {string|DocumentFragment}
2388
- */
2981
+ * @typedef {import('./index.js').Sort} Sort
2982
+ */
2983
+ /**
2984
+ * @typedef {import('./index.js').SortList} SortList
2985
+ */
2986
+ /**
2987
+ * @typedef {import('./index.js').List} List
2988
+ */
2389
2989
 
2390
- /* eslint-disable max-len */
2391
2990
  /**
2392
- * @param {PlainObject} cfg
2393
- * @param {LocaleObject} cfg.strings
2991
+ * @typedef {import('./index.js').I18NCallback} I18NCallback
2992
+ */
2993
+
2994
+ /**
2995
+ * @param {object} cfg
2996
+ * @param {import('./getMessageForKeyByStyle.js').LocaleObject} cfg.strings
2394
2997
  * @param {string} cfg.resolvedLocale
2395
- * @param {"richNested"|"rich"|"plain"|"plainNested"|MessageStyleCallback} [cfg.messageStyle="richNested"]
2396
- * @param {?AllSubstitutionCallback|AllSubstitutionCallback[]} [cfg.allSubstitutions]
2397
- * @param {InsertNodesCallback} [cfg.insertNodes=defaultInsertNodes]
2398
- * @param {KeyCheckerConverterCallback} [cfg.keyCheckerConverter]
2399
- * @param {false|null|undefined|LocaleObject} [cfg.defaults]
2400
- * @param {false|SubstitutionObject} [cfg.substitutions={}]
2998
+ * @param {"richNested"|"rich"|"plain"|"plainNested"|
2999
+ * import('./getMessageForKeyByStyle.js').
3000
+ * MessageStyleCallback} [cfg.messageStyle="richNested"]
3001
+ * @param {?import('./defaultAllSubstitutions.js').AllSubstitutionCallback|
3002
+ * import('./defaultAllSubstitutions.js').
3003
+ * AllSubstitutionCallback[]} [cfg.allSubstitutions]
3004
+ * @param {import('./defaultInsertNodes.js').
3005
+ * InsertNodesCallback} [cfg.insertNodes=defaultInsertNodes]
3006
+ * @param {import('./defaultKeyCheckerConverter.js').
3007
+ * KeyCheckerConverterCallback} [cfg.keyCheckerConverter]
3008
+ * @param {false|null|undefined|
3009
+ * import('./getMessageForKeyByStyle.js').LocaleObject} [cfg.defaults]
3010
+ * @param {false|import('./defaultLocaleResolver.js').
3011
+ * SubstitutionObject} [cfg.substitutions={}]
2401
3012
  * @param {Integer} [cfg.maximumLocalNestingDepth=3]
2402
3013
  * @param {boolean} [cfg.dom=false]
2403
3014
  * @param {boolean} [cfg.forceNodeReturn=false]
2404
3015
  * @param {boolean} [cfg.throwOnMissingSuppliedFormatters=true]
2405
3016
  * @param {boolean} [cfg.throwOnExtraSuppliedFormatters=true]
2406
- * @returns {Promise<I18NCallback>} Rejects if no suitable locale is found.
3017
+ * @returns {I18NCallback} Rejects if no suitable locale is found.
2407
3018
  */
2408
3019
 
2409
3020
  function _await(value, then, direct) {
@@ -2416,21 +3027,36 @@ function _await(value, then, direct) {
2416
3027
  return then ? value.then(then) : value;
2417
3028
  }
2418
3029
 
2419
- /* eslint-disable max-len */
2420
3030
  /**
2421
- * @param {PlainObject} [cfg={}]
3031
+ * @typedef {number} Integer
3032
+ */
3033
+
3034
+ /**
3035
+ * @param {object} [cfg={}]
2422
3036
  * @param {string[]} [cfg.locales=navigator.languages] BCP-47 language strings
2423
3037
  * @param {string[]} [cfg.defaultLocales=["en-US"]]
2424
- * @param {LocaleStringFinder} [cfg.localeStringFinder=findLocaleStrings]
3038
+ * @param {import('./findLocaleStrings.js').
3039
+ * LocaleStringFinder} [cfg.localeStringFinder=findLocaleStrings]
2425
3040
  * @param {string} [cfg.localesBasePath="."]
2426
- * @param {LocaleResolver} [cfg.localeResolver=defaultLocaleResolver]
2427
- * @param {"lookup"|LocaleMatcher} [cfg.localeMatcher="lookup"]
2428
- * @param {"richNested"|"rich"|"plain"|"plainNested"|MessageStyleCallback} [cfg.messageStyle="richNested"]
2429
- * @param {?AllSubstitutionCallback|AllSubstitutionCallback[]} [cfg.allSubstitutions]
2430
- * @param {InsertNodesCallback} [cfg.insertNodes=defaultInsertNodes]
2431
- * @param {KeyCheckerConverterCallback} [cfg.keyCheckerConverter]
2432
- * @param {false|null|undefined|LocaleObject} [cfg.defaults]
2433
- * @param {false|SubstitutionObject} [cfg.substitutions={}]
3041
+ * @param {import('./defaultLocaleResolver.js').
3042
+ * LocaleResolver} [cfg.localeResolver=defaultLocaleResolver]
3043
+ * @param {"lookup"|import('./findLocaleStrings.js').
3044
+ * LocaleMatcher} [cfg.localeMatcher="lookup"]
3045
+ * @param {"richNested"|"rich"|"plain"|"plainNested"|
3046
+ * import('./getMessageForKeyByStyle.js').
3047
+ * MessageStyleCallback} [cfg.messageStyle="richNested"]
3048
+ * @param {?(import('./defaultAllSubstitutions.js').AllSubstitutionCallback|
3049
+ * import('./defaultAllSubstitutions.js').
3050
+ * AllSubstitutionCallback[])} [cfg.allSubstitutions]
3051
+ * @param {import('./defaultInsertNodes.js').
3052
+ * InsertNodesCallback} [cfg.insertNodes=defaultInsertNodes]
3053
+ * @param {import('./defaultKeyCheckerConverter.js').
3054
+ * KeyCheckerConverterCallback} [cfg.keyCheckerConverter]
3055
+ * @param {false|null|undefined|
3056
+ * import('./getMessageForKeyByStyle.js').LocaleObject} [cfg.defaults]
3057
+ * @param {false|
3058
+ * import('./defaultLocaleResolver.js').
3059
+ * SubstitutionObject} [cfg.substitutions={}]
2434
3060
  * @param {Integer} [cfg.maximumLocalNestingDepth=3]
2435
3061
  * @param {boolean} [cfg.dom=false]
2436
3062
  * @param {boolean} [cfg.forceNodeReturn=false]
@@ -2472,6 +3098,10 @@ var i18nServer = function i18nServer(_ref) {
2472
3098
  var messageForKey = getMessageForKeyByStyle({
2473
3099
  messageStyle: messageStyle
2474
3100
  });
3101
+
3102
+ /**
3103
+ * @type {I18NCallback}
3104
+ */
2475
3105
  var formatter = function formatter(key, substitutions) {
2476
3106
  var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
2477
3107
  _ref2$allSubstitution = _ref2.allSubstitutions,
@@ -2486,7 +3116,7 @@ var i18nServer = function i18nServer(_ref) {
2486
3116
  throwOnMissingSuppliedFormatters = _ref2$throwOnMissingS === void 0 ? throwOnMissingSuppliedFormattersDefault : _ref2$throwOnMissingS,
2487
3117
  _ref2$throwOnExtraSup = _ref2.throwOnExtraSuppliedFormatters,
2488
3118
  throwOnExtraSuppliedFormatters = _ref2$throwOnExtraSup === void 0 ? throwOnExtraSuppliedFormattersDefault : _ref2$throwOnExtraSup;
2489
- key = keyCheckerConverter(key, messageStyle);
3119
+ key = /** @type {string} */keyCheckerConverter(key, messageStyle);
2490
3120
  var message = messageForKey(strings, key);
2491
3121
  var string = getStringFromMessageAndDefaults({
2492
3122
  message: message && typeof message.value === 'string' ? message.value : false,
@@ -2511,23 +3141,20 @@ var i18nServer = function i18nServer(_ref) {
2511
3141
  };
2512
3142
  formatter.resolvedLocale = resolvedLocale;
2513
3143
  formatter.strings = strings;
2514
- formatter.sort = function () {
2515
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2516
- args[_key] = arguments[_key];
2517
- }
2518
- return sort.apply(void 0, [resolvedLocale].concat(args));
3144
+
3145
+ /** @type {Sort} */
3146
+ formatter.sort = function (arrayOfItems, options) {
3147
+ return sort(resolvedLocale, arrayOfItems, options);
2519
3148
  };
2520
- formatter.sortList = function () {
2521
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2522
- args[_key2] = arguments[_key2];
2523
- }
2524
- return sortList.apply(void 0, [resolvedLocale].concat(args));
3149
+
3150
+ /** @type {SortList} */
3151
+ formatter.sortList = function (arrayOfItems, map, listOptions, collationOptions) {
3152
+ return sortList(resolvedLocale, arrayOfItems, map, listOptions, collationOptions);
2525
3153
  };
2526
- formatter.list = function () {
2527
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
2528
- args[_key3] = arguments[_key3];
2529
- }
2530
- return list.apply(void 0, [resolvedLocale].concat(args));
3154
+
3155
+ /** @type {List} */
3156
+ formatter.list = function (arrayOfItems, options) {
3157
+ return list(resolvedLocale, arrayOfItems, options);
2531
3158
  };
2532
3159
  return formatter;
2533
3160
  };
@@ -2640,8 +3267,9 @@ var JsonRefs=function(t){var n={};function r(e){if(n[e])return n[e].exports;var
2640
3267
 
2641
3268
  /* eslint-env browser */
2642
3269
 
2643
- const getCurrDir = () =>
2644
- window.location.href.replace(/(index\.html)?#.*$/, '');
3270
+ const getCurrDir = () => {
3271
+ return window.location.href.replace(/(index\.html)?#.*$/, '');
3272
+ };
2645
3273
 
2646
3274
  const getMetaProp = function getMetaProp (lang, metadataObj, properties, allowObjects) {
2647
3275
  let prop;
@@ -2675,8 +3303,8 @@ const getMetadata = async (file, property, basePath) => {
2675
3303
  url.pathname = file;
2676
3304
  url.hash = property ? '#/' + property : '';
2677
3305
 
2678
- return (await JsonRefs
2679
- .resolveRefsAt(
3306
+ return (await JsonRefs.
3307
+ resolveRefsAt(
2680
3308
  url.toString(),
2681
3309
  {
2682
3310
  loaderOptions: {
@@ -2729,7 +3357,7 @@ class Metadata {
2729
3357
  // If this is a localized field (e.g., enum), we don't want
2730
3358
  // to avoid as may be translated (should check though)
2731
3359
  const hasFieldValue = localeStrings &&
2732
- Object.keys(localeStrings).some(lng => {
3360
+ Object.keys(localeStrings).some((lng) => {
2733
3361
  const fv = localeStrings[lng] &&
2734
3362
  localeStrings[lng].fieldvalue;
2735
3363
  return fv && fv[field];
@@ -2737,30 +3365,30 @@ class Metadata {
2737
3365
 
2738
3366
  return hasFieldValue ||
2739
3367
  (metaLang && preferredLanguages.includes(metaLang)) ||
2740
- schemaItems.some(item =>
2741
- item.title === field && item.type !== 'string'
2742
- );
3368
+ schemaItems.some((item) => {
3369
+ return item.title === field && item.type !== 'string';
3370
+ });
2743
3371
  };
2744
3372
  }
2745
3373
  }
2746
3374
 
2747
3375
  const escapePluginComponent = (pluginName) => {
2748
- return pluginName.replace(/\^/g, '^^') // Escape our escape
2749
- .replace(/-/g, '^0');
3376
+ return pluginName.replaceAll('^', '^^'). // Escape our escape
3377
+ replaceAll('-', '^0');
2750
3378
  };
2751
3379
 
2752
3380
  const unescapePluginComponent = (pluginName) => {
2753
3381
  if (!pluginName) {
2754
3382
  return pluginName;
2755
3383
  }
2756
- return pluginName.replace(
3384
+ return pluginName.replaceAll(
2757
3385
  /(\^+)0/g,
2758
3386
  (n0, esc) => {
2759
3387
  return esc.length % 2
2760
3388
  ? esc.slice(1) + '-'
2761
3389
  : n0;
2762
3390
  }
2763
- ).replace(/\^\^/g, '^');
3391
+ ).replaceAll('^^', '^');
2764
3392
  };
2765
3393
 
2766
3394
  const escapePlugin = ({pluginName, applicableField, targetLanguage}) => {
@@ -2905,9 +3533,9 @@ const getWorkData = async function ({
2905
3533
 
2906
3534
  let fileData;
2907
3535
  const fileGroup = filesObj.groups.find((fg) => {
2908
- fileData = fg.files.find((file) =>
2909
- work === workI18n(['workNames', fg.id, file.name])
2910
- );
3536
+ fileData = fg.files.find((file) => {
3537
+ return work === workI18n(['workNames', fg.id, file.name]);
3538
+ });
2911
3539
  return Boolean(fileData);
2912
3540
  });
2913
3541
  // This is not specific to the work, but we export it anyways
@@ -3016,7 +3644,7 @@ const getWorkData = async function ({
3016
3644
  console.log('pluginsForWork', pluginsForWork);
3017
3645
  const {lang, namespace} = this; // array with first item as preferred
3018
3646
  pluginsForWork.iterateMappings(({
3019
- plugin,
3647
+ // plugin,
3020
3648
  pluginName, pluginLang,
3021
3649
  onByDefaultDefault,
3022
3650
  placement, applicableFields, meta