intl-messageformat 9.9.1 → 9.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -7,7 +7,7 @@ See the accompanying LICENSE file for terms.
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  var tslib_1 = require("tslib");
9
9
  var core_1 = require("./src/core");
10
- tslib_1.__exportStar(require("./src/formatters"), exports);
11
- tslib_1.__exportStar(require("./src/core"), exports);
12
- tslib_1.__exportStar(require("./src/error"), exports);
10
+ (0, tslib_1.__exportStar)(require("./src/formatters"), exports);
11
+ (0, tslib_1.__exportStar)(require("./src/core"), exports);
12
+ (0, tslib_1.__exportStar)(require("./src/error"), exports);
13
13
  exports.default = core_1.IntlMessageFormat;
@@ -1,5 +1,5 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
@@ -231,7 +231,7 @@ function parseNumberSkeletonFromString(skeleton) {
231
231
  throw new Error("Invalid number skeleton");
232
232
  }
233
233
  }
234
- tokens.push({stem, options});
234
+ tokens.push({ stem, options });
235
235
  }
236
236
  return tokens;
237
237
  }
@@ -239,11 +239,16 @@ function icuUnitToEcma(unit) {
239
239
  return unit.replace(/^(.*?)-/, "");
240
240
  }
241
241
  var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
242
- var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g;
242
+ var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
243
243
  var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
244
244
  var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
245
245
  function parseSignificantPrecision(str) {
246
246
  var result = {};
247
+ if (str[str.length - 1] === "r") {
248
+ result.roundingPriority = "morePrecision";
249
+ } else if (str[str.length - 1] === "s") {
250
+ result.roundingPriority = "lessPrecision";
251
+ }
247
252
  str.replace(SIGNIFICANT_PRECISION_REGEX, function(_, g1, g2) {
248
253
  if (typeof g2 !== "string") {
249
254
  result.minimumSignificantDigits = g1.length;
@@ -378,13 +383,13 @@ function parseNumberSkeleton(tokens) {
378
383
  result.compactDisplay = "long";
379
384
  continue;
380
385
  case "scientific":
381
- result = __assign(__assign(__assign({}, result), {notation: "scientific"}), token.options.reduce(function(all, opt) {
382
- return __assign(__assign({}, all), parseNotationOptions(opt));
386
+ result = __assign(__assign(__assign({}, result), { notation: "scientific" }), token.options.reduce(function(all, opt2) {
387
+ return __assign(__assign({}, all), parseNotationOptions(opt2));
383
388
  }, {}));
384
389
  continue;
385
390
  case "engineering":
386
- result = __assign(__assign(__assign({}, result), {notation: "engineering"}), token.options.reduce(function(all, opt) {
387
- return __assign(__assign({}, all), parseNotationOptions(opt));
391
+ result = __assign(__assign(__assign({}, result), { notation: "engineering" }), token.options.reduce(function(all, opt2) {
392
+ return __assign(__assign({}, all), parseNotationOptions(opt2));
388
393
  }, {}));
389
394
  continue;
390
395
  case "notation-simple":
@@ -446,8 +451,11 @@ function parseNumberSkeleton(tokens) {
446
451
  }
447
452
  return "";
448
453
  });
449
- if (token.options.length) {
450
- result = __assign(__assign({}, result), parseSignificantPrecision(token.options[0]));
454
+ var opt = token.options[0];
455
+ if (opt === "w") {
456
+ result = __assign(__assign({}, result), { trailingZeroDisplay: "stripIfInteger" });
457
+ } else if (opt) {
458
+ result = __assign(__assign({}, result), parseSignificantPrecision(opt));
451
459
  }
452
460
  continue;
453
461
  }
@@ -472,7 +480,7 @@ var _a;
472
480
  var SPACE_SEPARATOR_START_REGEX = new RegExp("^" + SPACE_SEPARATOR_REGEX.source + "*");
473
481
  var SPACE_SEPARATOR_END_REGEX = new RegExp(SPACE_SEPARATOR_REGEX.source + "*$");
474
482
  function createLocation(start, end) {
475
- return {start, end};
483
+ return { start, end };
476
484
  }
477
485
  var hasNativeStartsWith = !!String.prototype.startsWith;
478
486
  var hasNativeFromCodePoint = !!String.fromCodePoint;
@@ -576,7 +584,7 @@ var Parser = function() {
576
584
  options = {};
577
585
  }
578
586
  this.message = message;
579
- this.position = {offset: 0, line: 1, column: 1};
587
+ this.position = { offset: 0, line: 1, column: 1 };
580
588
  this.ignoreTag = !!options.ignoreTag;
581
589
  this.requiresOtherClause = !!options.requiresOtherClause;
582
590
  this.shouldParseSkeletons = !!options.shouldParseSkeletons;
@@ -626,7 +634,7 @@ var Parser = function() {
626
634
  elements.push(result.val);
627
635
  }
628
636
  }
629
- return {val: elements, err: null};
637
+ return { val: elements, err: null };
630
638
  };
631
639
  Parser2.prototype.parseTag = function(nestingLevel, parentArgType) {
632
640
  var startPosition = this.clonePosition();
@@ -709,7 +717,7 @@ var Parser = function() {
709
717
  }
710
718
  var location = createLocation(start, this.clonePosition());
711
719
  return {
712
- val: {type: TYPE.literal, value, location},
720
+ val: { type: TYPE.literal, value, location },
713
721
  err: null
714
722
  };
715
723
  };
@@ -825,7 +833,7 @@ var Parser = function() {
825
833
  this.bumpTo(endOffset);
826
834
  var endPosition = this.clonePosition();
827
835
  var location = createLocation(startingPosition, endPosition);
828
- return {value, location};
836
+ return { value, location };
829
837
  };
830
838
  Parser2.prototype.parseArgumentOptions = function(nestingLevel, expectingCloseTag, value, openingBracePosition) {
831
839
  var _a2;
@@ -852,7 +860,7 @@ var Parser = function() {
852
860
  return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition()));
853
861
  }
854
862
  var styleLocation = createLocation(styleStartPosition, this.clonePosition());
855
- styleAndLocation = {style, styleLocation};
863
+ styleAndLocation = { style, styleLocation };
856
864
  }
857
865
  var argCloseResult = this.tryParseArgumentClose(openingBracePosition);
858
866
  if (argCloseResult.err) {
@@ -867,7 +875,7 @@ var Parser = function() {
867
875
  return result;
868
876
  }
869
877
  return {
870
- val: {type: TYPE.number, value, location: location_1, style: result.val},
878
+ val: { type: TYPE.number, value, location: location_1, style: result.val },
871
879
  err: null
872
880
  };
873
881
  } else {
@@ -882,7 +890,7 @@ var Parser = function() {
882
890
  };
883
891
  var type = argType === "date" ? TYPE.date : TYPE.time;
884
892
  return {
885
- val: {type, value, location: location_1, style},
893
+ val: { type, value, location: location_1, style },
886
894
  err: null
887
895
  };
888
896
  }
@@ -963,7 +971,7 @@ var Parser = function() {
963
971
  return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
964
972
  }
965
973
  this.bump();
966
- return {val: true, err: null};
974
+ return { val: true, err: null };
967
975
  };
968
976
  Parser2.prototype.parseSimpleArgStyleIfPossible = function() {
969
977
  var nestedBraces = 0;
@@ -1079,7 +1087,7 @@ var Parser = function() {
1079
1087
  if (this.requiresOtherClause && !hasOtherClause) {
1080
1088
  return this.error(ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition()));
1081
1089
  }
1082
- return {val: options, err: null};
1090
+ return { val: options, err: null };
1083
1091
  };
1084
1092
  Parser2.prototype.tryParseDecimalInteger = function(expectNumberError, invalidNumberError) {
1085
1093
  var sign = 1;
@@ -1108,7 +1116,7 @@ var Parser = function() {
1108
1116
  if (!isSafeInteger(decimal)) {
1109
1117
  return this.error(invalidNumberError, location);
1110
1118
  }
1111
- return {val: decimal, err: null};
1119
+ return { val: decimal, err: null };
1112
1120
  };
1113
1121
  Parser2.prototype.offset = function() {
1114
1122
  return this.position.offset;
@@ -1251,7 +1259,7 @@ function parse(message, opts) {
1251
1259
  if (opts === void 0) {
1252
1260
  opts = {};
1253
1261
  }
1254
- opts = __assign({shouldParseSkeletons: true, requiresOtherClause: true}, opts);
1262
+ opts = __assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts);
1255
1263
  var result = new Parser(message, opts).parse();
1256
1264
  if (result.err) {
1257
1265
  var error = SyntaxError(ErrorKind[result.err.kind]);
@@ -1417,8 +1425,8 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
1417
1425
  }
1418
1426
  continue;
1419
1427
  }
1420
- const {value: varName} = el;
1421
- if (!(values && varName in values)) {
1428
+ const { value: varName } = el;
1429
+ if (!(values && values[varName] != null)) {
1422
1430
  throw new MissingValueError(varName, originalMessage);
1423
1431
  }
1424
1432
  let value = values[varName];
@@ -1460,7 +1468,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
1460
1468
  continue;
1461
1469
  }
1462
1470
  if (isTagElement(el)) {
1463
- const {children, value: value2} = el;
1471
+ const { children, value: value2 } = el;
1464
1472
  const formatFn = values[value2];
1465
1473
  if (!isFormatXMLElementFn(formatFn)) {
1466
1474
  throw new InvalidValueTypeError(value2, "function", originalMessage);
@@ -1493,7 +1501,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
1493
1501
  Try polyfilling it using "@formatjs/intl-pluralrules"
1494
1502
  `, ErrorCode.MISSING_INTL_API, originalMessage);
1495
1503
  }
1496
- const rule = formatters.getPluralRules(locales, {type: el.pluralType}).select(value - (el.offset || 0));
1504
+ const rule = formatters.getPluralRules(locales, { type: el.pluralType }).select(value - (el.offset || 0));
1497
1505
  opt = el.options[rule] || el.options.other;
1498
1506
  }
1499
1507
  if (!opt) {
@@ -1530,7 +1538,7 @@ function mergeConfigs(defaultConfig, configs) {
1530
1538
  return Object.keys(defaultConfig).reduce((all, k) => {
1531
1539
  all[k] = mergeConfig(defaultConfig[k], configs[k]);
1532
1540
  return all;
1533
- }, {...defaultConfig});
1541
+ }, { ...defaultConfig });
1534
1542
  }
1535
1543
  function createFastMemoizeCache(store) {
1536
1544
  return {
@@ -1,8 +1,12 @@
1
1
  var IntlMessageFormat = (function() {
2
2
  var __defProp = Object.defineProperty;
3
+ var __markAsModule = function(target) {
4
+ return __defProp(target, "__esModule", { value: true });
5
+ };
3
6
  var __export = function(target, all) {
7
+ __markAsModule(target);
4
8
  for (var name in all)
5
- __defProp(target, name, {get: all[name], enumerable: true});
9
+ __defProp(target, name, { get: all[name], enumerable: true });
6
10
  };
7
11
 
8
12
  // bazel-out/darwin-fastbuild/bin/packages/intl-messageformat/lib/index.js
@@ -42,7 +46,7 @@ var IntlMessageFormat = (function() {
42
46
 
43
47
  // node_modules/tslib/tslib.es6.js
44
48
  var extendStatics = function(d, b) {
45
- extendStatics = Object.setPrototypeOf || {__proto__: []} instanceof Array && function(d2, b2) {
49
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
46
50
  d2.__proto__ = b2;
47
51
  } || function(d2, b2) {
48
52
  for (var p in b2)
@@ -296,7 +300,7 @@ var IntlMessageFormat = (function() {
296
300
  throw new Error("Invalid number skeleton");
297
301
  }
298
302
  }
299
- tokens.push({stem: stem, options: options});
303
+ tokens.push({ stem: stem, options: options });
300
304
  }
301
305
  return tokens;
302
306
  }
@@ -304,11 +308,16 @@ var IntlMessageFormat = (function() {
304
308
  return unit.replace(/^(.*?)-/, "");
305
309
  }
306
310
  var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
307
- var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g;
311
+ var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
308
312
  var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
309
313
  var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
310
314
  function parseSignificantPrecision(str) {
311
315
  var result = {};
316
+ if (str[str.length - 1] === "r") {
317
+ result.roundingPriority = "morePrecision";
318
+ } else if (str[str.length - 1] === "s") {
319
+ result.roundingPriority = "lessPrecision";
320
+ }
312
321
  str.replace(SIGNIFICANT_PRECISION_REGEX, function(_, g1, g2) {
313
322
  if (typeof g2 !== "string") {
314
323
  result.minimumSignificantDigits = g1.length;
@@ -443,13 +452,13 @@ var IntlMessageFormat = (function() {
443
452
  result.compactDisplay = "long";
444
453
  continue;
445
454
  case "scientific":
446
- result = __assign(__assign(__assign({}, result), {notation: "scientific"}), token.options.reduce(function(all, opt) {
447
- return __assign(__assign({}, all), parseNotationOptions(opt));
455
+ result = __assign(__assign(__assign({}, result), { notation: "scientific" }), token.options.reduce(function(all, opt2) {
456
+ return __assign(__assign({}, all), parseNotationOptions(opt2));
448
457
  }, {}));
449
458
  continue;
450
459
  case "engineering":
451
- result = __assign(__assign(__assign({}, result), {notation: "engineering"}), token.options.reduce(function(all, opt) {
452
- return __assign(__assign({}, all), parseNotationOptions(opt));
460
+ result = __assign(__assign(__assign({}, result), { notation: "engineering" }), token.options.reduce(function(all, opt2) {
461
+ return __assign(__assign({}, all), parseNotationOptions(opt2));
453
462
  }, {}));
454
463
  continue;
455
464
  case "notation-simple":
@@ -511,8 +520,11 @@ var IntlMessageFormat = (function() {
511
520
  }
512
521
  return "";
513
522
  });
514
- if (token.options.length) {
515
- result = __assign(__assign({}, result), parseSignificantPrecision(token.options[0]));
523
+ var opt = token.options[0];
524
+ if (opt === "w") {
525
+ result = __assign(__assign({}, result), { trailingZeroDisplay: "stripIfInteger" });
526
+ } else if (opt) {
527
+ result = __assign(__assign({}, result), parseSignificantPrecision(opt));
516
528
  }
517
529
  continue;
518
530
  }
@@ -537,7 +549,7 @@ var IntlMessageFormat = (function() {
537
549
  var SPACE_SEPARATOR_START_REGEX = new RegExp("^" + SPACE_SEPARATOR_REGEX.source + "*");
538
550
  var SPACE_SEPARATOR_END_REGEX = new RegExp(SPACE_SEPARATOR_REGEX.source + "*$");
539
551
  function createLocation(start, end) {
540
- return {start: start, end: end};
552
+ return { start: start, end: end };
541
553
  }
542
554
  var hasNativeStartsWith = !!String.prototype.startsWith;
543
555
  var hasNativeFromCodePoint = !!String.fromCodePoint;
@@ -641,7 +653,7 @@ var IntlMessageFormat = (function() {
641
653
  options = {};
642
654
  }
643
655
  this.message = message;
644
- this.position = {offset: 0, line: 1, column: 1};
656
+ this.position = { offset: 0, line: 1, column: 1 };
645
657
  this.ignoreTag = !!options.ignoreTag;
646
658
  this.requiresOtherClause = !!options.requiresOtherClause;
647
659
  this.shouldParseSkeletons = !!options.shouldParseSkeletons;
@@ -691,7 +703,7 @@ var IntlMessageFormat = (function() {
691
703
  elements.push(result.val);
692
704
  }
693
705
  }
694
- return {val: elements, err: null};
706
+ return { val: elements, err: null };
695
707
  };
696
708
  Parser2.prototype.parseTag = function(nestingLevel, parentArgType) {
697
709
  var startPosition = this.clonePosition();
@@ -774,7 +786,7 @@ var IntlMessageFormat = (function() {
774
786
  }
775
787
  var location = createLocation(start, this.clonePosition());
776
788
  return {
777
- val: {type: TYPE.literal, value: value, location: location},
789
+ val: { type: TYPE.literal, value: value, location: location },
778
790
  err: null
779
791
  };
780
792
  };
@@ -890,7 +902,7 @@ var IntlMessageFormat = (function() {
890
902
  this.bumpTo(endOffset);
891
903
  var endPosition = this.clonePosition();
892
904
  var location = createLocation(startingPosition, endPosition);
893
- return {value: value, location: location};
905
+ return { value: value, location: location };
894
906
  };
895
907
  Parser2.prototype.parseArgumentOptions = function(nestingLevel, expectingCloseTag, value, openingBracePosition) {
896
908
  var _a2;
@@ -917,7 +929,7 @@ var IntlMessageFormat = (function() {
917
929
  return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition()));
918
930
  }
919
931
  var styleLocation = createLocation(styleStartPosition, this.clonePosition());
920
- styleAndLocation = {style: style, styleLocation: styleLocation};
932
+ styleAndLocation = { style: style, styleLocation: styleLocation };
921
933
  }
922
934
  var argCloseResult = this.tryParseArgumentClose(openingBracePosition);
923
935
  if (argCloseResult.err) {
@@ -932,7 +944,7 @@ var IntlMessageFormat = (function() {
932
944
  return result;
933
945
  }
934
946
  return {
935
- val: {type: TYPE.number, value: value, location: location_1, style: result.val},
947
+ val: { type: TYPE.number, value: value, location: location_1, style: result.val },
936
948
  err: null
937
949
  };
938
950
  } else {
@@ -947,7 +959,7 @@ var IntlMessageFormat = (function() {
947
959
  };
948
960
  var type = argType === "date" ? TYPE.date : TYPE.time;
949
961
  return {
950
- val: {type: type, value: value, location: location_1, style: style},
962
+ val: { type: type, value: value, location: location_1, style: style },
951
963
  err: null
952
964
  };
953
965
  }
@@ -1028,7 +1040,7 @@ var IntlMessageFormat = (function() {
1028
1040
  return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
1029
1041
  }
1030
1042
  this.bump();
1031
- return {val: true, err: null};
1043
+ return { val: true, err: null };
1032
1044
  };
1033
1045
  Parser2.prototype.parseSimpleArgStyleIfPossible = function() {
1034
1046
  var nestedBraces = 0;
@@ -1144,7 +1156,7 @@ var IntlMessageFormat = (function() {
1144
1156
  if (this.requiresOtherClause && !hasOtherClause) {
1145
1157
  return this.error(ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition()));
1146
1158
  }
1147
- return {val: options, err: null};
1159
+ return { val: options, err: null };
1148
1160
  };
1149
1161
  Parser2.prototype.tryParseDecimalInteger = function(expectNumberError, invalidNumberError) {
1150
1162
  var sign = 1;
@@ -1173,7 +1185,7 @@ var IntlMessageFormat = (function() {
1173
1185
  if (!isSafeInteger(decimal)) {
1174
1186
  return this.error(invalidNumberError, location);
1175
1187
  }
1176
- return {val: decimal, err: null};
1188
+ return { val: decimal, err: null };
1177
1189
  };
1178
1190
  Parser2.prototype.offset = function() {
1179
1191
  return this.position.offset;
@@ -1316,7 +1328,7 @@ var IntlMessageFormat = (function() {
1316
1328
  if (opts === void 0) {
1317
1329
  opts = {};
1318
1330
  }
1319
- opts = __assign({shouldParseSkeletons: true, requiresOtherClause: true}, opts);
1331
+ opts = __assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts);
1320
1332
  var result = new Parser(message, opts).parse();
1321
1333
  if (result.err) {
1322
1334
  var error = SyntaxError(ErrorKind[result.err.kind]);
@@ -1491,7 +1503,7 @@ var IntlMessageFormat = (function() {
1491
1503
  continue;
1492
1504
  }
1493
1505
  var varName = el.value;
1494
- if (!(values && varName in values)) {
1506
+ if (!(values && values[varName] != null)) {
1495
1507
  throw new MissingValueError(varName, originalMessage);
1496
1508
  }
1497
1509
  var value = values[varName];
@@ -1566,7 +1578,7 @@ var IntlMessageFormat = (function() {
1566
1578
  if (!Intl.PluralRules) {
1567
1579
  throw new FormatError('Intl.PluralRules is not available in this environment.\nTry polyfilling it using "@formatjs/intl-pluralrules"\n', ErrorCode.MISSING_INTL_API, originalMessage);
1568
1580
  }
1569
- var rule = formatters.getPluralRules(locales, {type: el.pluralType}).select(value - (el.offset || 0));
1581
+ var rule = formatters.getPluralRules(locales, { type: el.pluralType }).select(value - (el.offset || 0));
1570
1582
  opt = el.options[rule] || el.options.other;
1571
1583
  }
1572
1584
  if (!opt) {
@@ -1627,7 +1639,7 @@ var IntlMessageFormat = (function() {
1627
1639
  for (var _i = 0; _i < arguments.length; _i++) {
1628
1640
  args[_i] = arguments[_i];
1629
1641
  }
1630
- return new ((_a2 = Intl.NumberFormat).bind.apply(_a2, __spreadArray([void 0], args)))();
1642
+ return new ((_a2 = Intl.NumberFormat).bind.apply(_a2, __spreadArray([void 0], args, false)))();
1631
1643
  }, {
1632
1644
  cache: createFastMemoizeCache(cache.number),
1633
1645
  strategy: strategies.variadic
@@ -1638,7 +1650,7 @@ var IntlMessageFormat = (function() {
1638
1650
  for (var _i = 0; _i < arguments.length; _i++) {
1639
1651
  args[_i] = arguments[_i];
1640
1652
  }
1641
- return new ((_a2 = Intl.DateTimeFormat).bind.apply(_a2, __spreadArray([void 0], args)))();
1653
+ return new ((_a2 = Intl.DateTimeFormat).bind.apply(_a2, __spreadArray([void 0], args, false)))();
1642
1654
  }, {
1643
1655
  cache: createFastMemoizeCache(cache.dateTime),
1644
1656
  strategy: strategies.variadic
@@ -1649,7 +1661,7 @@ var IntlMessageFormat = (function() {
1649
1661
  for (var _i = 0; _i < arguments.length; _i++) {
1650
1662
  args[_i] = arguments[_i];
1651
1663
  }
1652
- return new ((_a2 = Intl.PluralRules).bind.apply(_a2, __spreadArray([void 0], args)))();
1664
+ return new ((_a2 = Intl.PluralRules).bind.apply(_a2, __spreadArray([void 0], args, false)))();
1653
1665
  }, {
1654
1666
  cache: createFastMemoizeCache(cache.pluralRules),
1655
1667
  strategy: strategies.variadic
package/lib/src/core.js CHANGED
@@ -53,7 +53,7 @@ function createDefaultFormatters(cache) {
53
53
  for (var _i = 0; _i < arguments.length; _i++) {
54
54
  args[_i] = arguments[_i];
55
55
  }
56
- return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args)))();
56
+ return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
57
57
  }, {
58
58
  cache: createFastMemoizeCache(cache.number),
59
59
  strategy: strategies.variadic,
@@ -64,7 +64,7 @@ function createDefaultFormatters(cache) {
64
64
  for (var _i = 0; _i < arguments.length; _i++) {
65
65
  args[_i] = arguments[_i];
66
66
  }
67
- return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args)))();
67
+ return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
68
68
  }, {
69
69
  cache: createFastMemoizeCache(cache.dateTime),
70
70
  strategy: strategies.variadic,
@@ -75,7 +75,7 @@ function createDefaultFormatters(cache) {
75
75
  for (var _i = 0; _i < arguments.length; _i++) {
76
76
  args[_i] = arguments[_i];
77
77
  }
78
- return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args)))();
78
+ return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
79
79
  }, {
80
80
  cache: createFastMemoizeCache(cache.pluralRules),
81
81
  strategy: strategies.variadic,
@@ -62,7 +62,7 @@ originalMessage) {
62
62
  }
63
63
  var varName = el.value;
64
64
  // Enforce that all required values are provided by the caller.
65
- if (!(values && varName in values)) {
65
+ if (!(values && values[varName] != null)) {
66
66
  throw new MissingValueError(varName, originalMessage);
67
67
  }
68
68
  var value = values[varName];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-messageformat",
3
- "version": "9.9.1",
3
+ "version": "9.9.5",
4
4
  "description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -32,7 +32,7 @@
32
32
  "types": "index.d.ts",
33
33
  "dependencies": {
34
34
  "@formatjs/fast-memoize": "1.2.0",
35
- "@formatjs/icu-messageformat-parser": "2.0.11",
35
+ "@formatjs/icu-messageformat-parser": "2.0.14",
36
36
  "tslib": "^2.1.0"
37
37
  },
38
38
  "sideEffects": false,
package/src/core.js CHANGED
@@ -8,15 +8,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.IntlMessageFormat = void 0;
9
9
  var tslib_1 = require("tslib");
10
10
  var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
11
- var fast_memoize_1 = tslib_1.__importStar(require("@formatjs/fast-memoize"));
11
+ var fast_memoize_1 = (0, tslib_1.__importStar)(require("@formatjs/fast-memoize"));
12
12
  var formatters_1 = require("./formatters");
13
13
  // -- MessageFormat --------------------------------------------------------
14
14
  function mergeConfig(c1, c2) {
15
15
  if (!c2) {
16
16
  return c1;
17
17
  }
18
- return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, (c1 || {})), (c2 || {})), Object.keys(c1).reduce(function (all, k) {
19
- all[k] = tslib_1.__assign(tslib_1.__assign({}, c1[k]), (c2[k] || {}));
18
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, (c1 || {})), (c2 || {})), Object.keys(c1).reduce(function (all, k) {
19
+ all[k] = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, c1[k]), (c2[k] || {}));
20
20
  return all;
21
21
  }, {}));
22
22
  }
@@ -27,7 +27,7 @@ function mergeConfigs(defaultConfig, configs) {
27
27
  return Object.keys(defaultConfig).reduce(function (all, k) {
28
28
  all[k] = mergeConfig(defaultConfig[k], configs[k]);
29
29
  return all;
30
- }, tslib_1.__assign({}, defaultConfig));
30
+ }, (0, tslib_1.__assign)({}, defaultConfig));
31
31
  }
32
32
  function createFastMemoizeCache(store) {
33
33
  return {
@@ -50,35 +50,35 @@ function createDefaultFormatters(cache) {
50
50
  pluralRules: {},
51
51
  }; }
52
52
  return {
53
- getNumberFormat: fast_memoize_1.default(function () {
53
+ getNumberFormat: (0, fast_memoize_1.default)(function () {
54
54
  var _a;
55
55
  var args = [];
56
56
  for (var _i = 0; _i < arguments.length; _i++) {
57
57
  args[_i] = arguments[_i];
58
58
  }
59
- return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
59
+ return new ((_a = Intl.NumberFormat).bind.apply(_a, (0, tslib_1.__spreadArray)([void 0], args, false)))();
60
60
  }, {
61
61
  cache: createFastMemoizeCache(cache.number),
62
62
  strategy: fast_memoize_1.strategies.variadic,
63
63
  }),
64
- getDateTimeFormat: fast_memoize_1.default(function () {
64
+ getDateTimeFormat: (0, fast_memoize_1.default)(function () {
65
65
  var _a;
66
66
  var args = [];
67
67
  for (var _i = 0; _i < arguments.length; _i++) {
68
68
  args[_i] = arguments[_i];
69
69
  }
70
- return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
70
+ return new ((_a = Intl.DateTimeFormat).bind.apply(_a, (0, tslib_1.__spreadArray)([void 0], args, false)))();
71
71
  }, {
72
72
  cache: createFastMemoizeCache(cache.dateTime),
73
73
  strategy: fast_memoize_1.strategies.variadic,
74
74
  }),
75
- getPluralRules: fast_memoize_1.default(function () {
75
+ getPluralRules: (0, fast_memoize_1.default)(function () {
76
76
  var _a;
77
77
  var args = [];
78
78
  for (var _i = 0; _i < arguments.length; _i++) {
79
79
  args[_i] = arguments[_i];
80
80
  }
81
- return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
81
+ return new ((_a = Intl.PluralRules).bind.apply(_a, (0, tslib_1.__spreadArray)([void 0], args, false)))();
82
82
  }, {
83
83
  cache: createFastMemoizeCache(cache.pluralRules),
84
84
  strategy: fast_memoize_1.strategies.variadic,
@@ -117,7 +117,7 @@ var IntlMessageFormat = /** @class */ (function () {
117
117
  return result;
118
118
  };
119
119
  this.formatToParts = function (values) {
120
- return formatters_1.formatToParts(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
120
+ return (0, formatters_1.formatToParts)(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
121
121
  };
122
122
  this.resolvedOptions = function () { return ({
123
123
  locale: Intl.NumberFormat.supportedLocalesOf(_this.locales)[0],
package/src/error.js CHANGED
@@ -12,7 +12,7 @@ var ErrorCode;
12
12
  ErrorCode["MISSING_INTL_API"] = "MISSING_INTL_API";
13
13
  })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
14
14
  var FormatError = /** @class */ (function (_super) {
15
- tslib_1.__extends(FormatError, _super);
15
+ (0, tslib_1.__extends)(FormatError, _super);
16
16
  function FormatError(msg, code, originalMessage) {
17
17
  var _this = _super.call(this, msg) || this;
18
18
  _this.code = code;
@@ -26,7 +26,7 @@ var FormatError = /** @class */ (function (_super) {
26
26
  }(Error));
27
27
  exports.FormatError = FormatError;
28
28
  var InvalidValueError = /** @class */ (function (_super) {
29
- tslib_1.__extends(InvalidValueError, _super);
29
+ (0, tslib_1.__extends)(InvalidValueError, _super);
30
30
  function InvalidValueError(variableId, value, options, originalMessage) {
31
31
  return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", ErrorCode.INVALID_VALUE, originalMessage) || this;
32
32
  }
@@ -34,7 +34,7 @@ var InvalidValueError = /** @class */ (function (_super) {
34
34
  }(FormatError));
35
35
  exports.InvalidValueError = InvalidValueError;
36
36
  var InvalidValueTypeError = /** @class */ (function (_super) {
37
- tslib_1.__extends(InvalidValueTypeError, _super);
37
+ (0, tslib_1.__extends)(InvalidValueTypeError, _super);
38
38
  function InvalidValueTypeError(value, type, originalMessage) {
39
39
  return _super.call(this, "Value for \"" + value + "\" must be of type " + type, ErrorCode.INVALID_VALUE, originalMessage) || this;
40
40
  }
@@ -42,7 +42,7 @@ var InvalidValueTypeError = /** @class */ (function (_super) {
42
42
  }(FormatError));
43
43
  exports.InvalidValueTypeError = InvalidValueTypeError;
44
44
  var MissingValueError = /** @class */ (function (_super) {
45
- tslib_1.__extends(MissingValueError, _super);
45
+ (0, tslib_1.__extends)(MissingValueError, _super);
46
46
  function MissingValueError(variableId, originalMessage) {
47
47
  return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"", ErrorCode.MISSING_VALUE, originalMessage) || this;
48
48
  }
package/src/formatters.js CHANGED
@@ -34,7 +34,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
34
34
  // For debugging
35
35
  originalMessage) {
36
36
  // Hot path for straight simple msg translations
37
- if (els.length === 1 && icu_messageformat_parser_1.isLiteralElement(els[0])) {
37
+ if (els.length === 1 && (0, icu_messageformat_parser_1.isLiteralElement)(els[0])) {
38
38
  return [
39
39
  {
40
40
  type: PART_TYPE.literal,
@@ -46,7 +46,7 @@ originalMessage) {
46
46
  for (var _i = 0, els_1 = els; _i < els_1.length; _i++) {
47
47
  var el = els_1[_i];
48
48
  // Exit early for string parts.
49
- if (icu_messageformat_parser_1.isLiteralElement(el)) {
49
+ if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
50
50
  result.push({
51
51
  type: PART_TYPE.literal,
52
52
  value: el.value,
@@ -55,7 +55,7 @@ originalMessage) {
55
55
  }
56
56
  // TODO: should this part be literal type?
57
57
  // Replace `#` in plural rules with the actual numeric value.
58
- if (icu_messageformat_parser_1.isPoundElement(el)) {
58
+ if ((0, icu_messageformat_parser_1.isPoundElement)(el)) {
59
59
  if (typeof currentPluralValue === 'number') {
60
60
  result.push({
61
61
  type: PART_TYPE.literal,
@@ -66,11 +66,11 @@ originalMessage) {
66
66
  }
67
67
  var varName = el.value;
68
68
  // Enforce that all required values are provided by the caller.
69
- if (!(values && varName in values)) {
69
+ if (!(values && values[varName] != null)) {
70
70
  throw new error_1.MissingValueError(varName, originalMessage);
71
71
  }
72
72
  var value = values[varName];
73
- if (icu_messageformat_parser_1.isArgumentElement(el)) {
73
+ if ((0, icu_messageformat_parser_1.isArgumentElement)(el)) {
74
74
  if (!value || typeof value === 'string' || typeof value === 'number') {
75
75
  value =
76
76
  typeof value === 'string' || typeof value === 'number'
@@ -86,10 +86,10 @@ originalMessage) {
86
86
  // Recursively format plural and select parts' option — which can be a
87
87
  // nested pattern structure. The choosing of the option to use is
88
88
  // abstracted-by and delegated-to the part helper object.
89
- if (icu_messageformat_parser_1.isDateElement(el)) {
89
+ if ((0, icu_messageformat_parser_1.isDateElement)(el)) {
90
90
  var style = typeof el.style === 'string'
91
91
  ? formats.date[el.style]
92
- : icu_messageformat_parser_1.isDateTimeSkeleton(el.style)
92
+ : (0, icu_messageformat_parser_1.isDateTimeSkeleton)(el.style)
93
93
  ? el.style.parsedOptions
94
94
  : undefined;
95
95
  result.push({
@@ -100,10 +100,10 @@ originalMessage) {
100
100
  });
101
101
  continue;
102
102
  }
103
- if (icu_messageformat_parser_1.isTimeElement(el)) {
103
+ if ((0, icu_messageformat_parser_1.isTimeElement)(el)) {
104
104
  var style = typeof el.style === 'string'
105
105
  ? formats.time[el.style]
106
- : icu_messageformat_parser_1.isDateTimeSkeleton(el.style)
106
+ : (0, icu_messageformat_parser_1.isDateTimeSkeleton)(el.style)
107
107
  ? el.style.parsedOptions
108
108
  : undefined;
109
109
  result.push({
@@ -114,10 +114,10 @@ originalMessage) {
114
114
  });
115
115
  continue;
116
116
  }
117
- if (icu_messageformat_parser_1.isNumberElement(el)) {
117
+ if ((0, icu_messageformat_parser_1.isNumberElement)(el)) {
118
118
  var style = typeof el.style === 'string'
119
119
  ? formats.number[el.style]
120
- : icu_messageformat_parser_1.isNumberSkeleton(el.style)
120
+ : (0, icu_messageformat_parser_1.isNumberSkeleton)(el.style)
121
121
  ? el.style.parsedOptions
122
122
  : undefined;
123
123
  if (style && style.scale) {
@@ -133,7 +133,7 @@ originalMessage) {
133
133
  });
134
134
  continue;
135
135
  }
136
- if (icu_messageformat_parser_1.isTagElement(el)) {
136
+ if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
137
137
  var children = el.children, value_1 = el.value;
138
138
  var formatFn = values[value_1];
139
139
  if (!isFormatXMLElementFn(formatFn)) {
@@ -151,7 +151,7 @@ originalMessage) {
151
151
  };
152
152
  }));
153
153
  }
154
- if (icu_messageformat_parser_1.isSelectElement(el)) {
154
+ if ((0, icu_messageformat_parser_1.isSelectElement)(el)) {
155
155
  var opt = el.options[value] || el.options.other;
156
156
  if (!opt) {
157
157
  throw new error_1.InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
@@ -159,7 +159,7 @@ originalMessage) {
159
159
  result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
160
160
  continue;
161
161
  }
162
- if (icu_messageformat_parser_1.isPluralElement(el)) {
162
+ if ((0, icu_messageformat_parser_1.isPluralElement)(el)) {
163
163
  var opt = el.options["=" + value];
164
164
  if (!opt) {
165
165
  if (!Intl.PluralRules) {