react-intl 4.4.0 → 4.5.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [4.5.0](https://github.com/formatjs/react-intl/compare/v4.4.0...v4.5.0) (2020-04-20)
6
+
7
+
8
+ ### Features
9
+
10
+ * upgrade intl-messageformat & parser ([cbbd6cf](https://github.com/formatjs/react-intl/commit/cbbd6cf93ee6294bdfbc28af3e33227df0e621e4))
11
+
5
12
  ## [4.4.0](https://github.com/formatjs/react-intl/compare/v4.3.1...v4.4.0) (2020-04-14)
6
13
 
7
14
 
@@ -54,7 +54,9 @@ exports.createFormattedDateTimePartsComponent = createFormattedDateTimePartsComp
54
54
  function createFormattedComponent(name) {
55
55
  var Component = function (props) { return (React.createElement(injectIntl_1.Context.Consumer, null, function (intl) {
56
56
  utils_1.invariantIntlContext(intl);
57
- var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]);
57
+ var value = props.value, children = props.children, formatProps = __rest(props
58
+ // TODO: fix TS type definition for localeMatcher upstream
59
+ , ["value", "children"]);
58
60
  // TODO: fix TS type definition for localeMatcher upstream
59
61
  var formattedValue = intl[name](value, formatProps);
60
62
  if (typeof children === 'function') {
package/dist/error.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MessageDescriptor } from "./types";
1
+ import { MessageDescriptor } from './types';
2
2
  export declare const enum ReactIntlErrorCode {
3
3
  FORMAT_ERROR = "FORMAT_ERROR",
4
4
  UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var utils_1 = require("../utils");
4
4
  var intl_messageformat_1 = require("intl-messageformat");
5
5
  var error_1 = require("../error");
6
- var RELATIVE_TIME_FORMAT_OPTIONS = [
7
- 'numeric',
8
- 'style',
9
- ];
6
+ var RELATIVE_TIME_FORMAT_OPTIONS = ['numeric', 'style'];
10
7
  function getFormatter(_a, getRelativeTimeFormat, options) {
11
8
  var locale = _a.locale, formats = _a.formats, onError = _a.onError;
12
9
  if (options === void 0) { options = {}; }
@@ -345,7 +345,8 @@ declare class IntlMessageFormat {
345
345
  locale: string;
346
346
  };
347
347
  getAst: () => MessageFormatElement[];
348
- static defaultLocale: string;
348
+ private static memoizedDefaultLocale;
349
+ static get defaultLocale(): string;
349
350
  static __parse: typeof parse | undefined;
350
351
  static formats: {
351
352
  number: {
@@ -3998,7 +3998,7 @@
3998
3998
  return unit.replace(/^(.*?)-/, '');
3999
3999
  }
4000
4000
 
4001
- var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\+|#+)?)?$/g;
4001
+ var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
4002
4002
  var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g;
4003
4003
 
4004
4004
  function parseSignificantPrecision(str) {
@@ -4102,6 +4102,7 @@
4102
4102
  continue;
4103
4103
 
4104
4104
  case 'precision-integer':
4105
+ case '.':
4105
4106
  result.maximumFractionDigits = 0;
4106
4107
  continue;
4107
4108
 
@@ -4161,6 +4162,7 @@
4161
4162
  continue;
4162
4163
  } // Precision
4163
4164
  // https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#fraction-precision
4165
+ // precision-integer case
4164
4166
 
4165
4167
 
4166
4168
  if (FRACTION_PRECISION_REGEX.test(token.stem)) {
@@ -4168,21 +4170,21 @@
4168
4170
  throw new RangeError('Fraction-precision stems only accept a single optional option');
4169
4171
  }
4170
4172
 
4171
- token.stem.replace(FRACTION_PRECISION_REGEX, function (match, g1, g2) {
4172
- // precision-integer case
4173
- if (match === '.') {
4174
- result.maximumFractionDigits = 0;
4175
- } // .000+ case
4176
- else if (g2 === '+') {
4177
- result.minimumFractionDigits = g2.length;
4178
- } // .### case
4179
- else if (g1[0] === '#') {
4173
+ token.stem.replace(FRACTION_PRECISION_REGEX, function (match, g1, g2, g3, g4, g5) {
4174
+ // .000* case (before ICU67 it was .000+)
4175
+ if (g2 === '*') {
4176
+ result.minimumFractionDigits = g1.length;
4177
+ } // .### case
4178
+ else if (g3 && g3[0] === '#') {
4179
+ result.maximumFractionDigits = g3.length;
4180
+ } // .00## case
4181
+ else if (g4 && g5) {
4182
+ result.minimumFractionDigits = g4.length;
4183
+ result.maximumFractionDigits = g4.length + g5.length;
4184
+ } else {
4185
+ result.minimumFractionDigits = g1.length;
4180
4186
  result.maximumFractionDigits = g1.length;
4181
- } // .00## or .000 case
4182
- else {
4183
- result.minimumFractionDigits = g1.length;
4184
- result.maximumFractionDigits = g1.length + (typeof g2 === 'string' ? g2.length : 0);
4185
- }
4187
+ }
4186
4188
 
4187
4189
  return '';
4188
4190
  });
@@ -4729,7 +4731,18 @@
4729
4731
  this.formatters = opts && opts.formatters || createDefaultFormatters(this.formatterCache);
4730
4732
  }
4731
4733
 
4732
- IntlMessageFormat.defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
4734
+ Object.defineProperty(IntlMessageFormat, "defaultLocale", {
4735
+ get: function get() {
4736
+ if (!IntlMessageFormat.memoizedDefaultLocale) {
4737
+ IntlMessageFormat.memoizedDefaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
4738
+ }
4739
+
4740
+ return IntlMessageFormat.memoizedDefaultLocale;
4741
+ },
4742
+ enumerable: true,
4743
+ configurable: true
4744
+ });
4745
+ IntlMessageFormat.memoizedDefaultLocale = null;
4733
4746
  IntlMessageFormat.__parse = parse; // Default format options used as the prototype of the `formats` provided to the
4734
4747
  // constructor. These are used when constructing the internal Intl.NumberFormat
4735
4748
  // and Intl.DateTimeFormat instances.
@@ -5437,7 +5450,8 @@
5437
5450
 
5438
5451
  var value = props.value,
5439
5452
  children = props.children,
5440
- formatProps = __rest(props, ["value", "children"]); // TODO: fix TS type definition for localeMatcher upstream
5453
+ formatProps = __rest(props // TODO: fix TS type definition for localeMatcher upstream
5454
+ , ["value", "children"]); // TODO: fix TS type definition for localeMatcher upstream
5441
5455
 
5442
5456
 
5443
5457
  var formattedValue = intl[name](value, formatProps);