react-intl 4.2.2 → 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.
Files changed (52) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +1 -1
  3. package/dist/components/createFormattedComponent.js +3 -1
  4. package/dist/components/injectIntl.js +2 -3
  5. package/dist/components/message.d.ts +1 -1
  6. package/dist/error.d.ts +4 -2
  7. package/dist/error.js +2 -1
  8. package/dist/formatters/message.js +4 -4
  9. package/dist/formatters/relativeTime.js +1 -4
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js +4 -0
  12. package/dist/react-intl.api.md +42 -35
  13. package/dist/react-intl.d.ts +72 -59
  14. package/dist/react-intl.js +74 -31
  15. package/dist/react-intl.js.map +1 -1
  16. package/dist/react-intl.min.js +1 -1
  17. package/dist/react-intl.min.js.map +1 -1
  18. package/dist/types.d.ts +2 -2
  19. package/lib/components/createFormattedComponent.js +3 -1
  20. package/lib/components/injectIntl.js +2 -3
  21. package/lib/components/message.d.ts +1 -1
  22. package/lib/error.d.ts +4 -2
  23. package/lib/error.js +2 -1
  24. package/lib/formatters/message.js +4 -4
  25. package/lib/formatters/relativeTime.js +1 -4
  26. package/lib/index.d.ts +1 -0
  27. package/lib/index.js +3 -0
  28. package/lib/react-intl.d.ts +51 -47
  29. package/lib/tsdoc-metadata.json +1 -1
  30. package/lib/types.d.ts +2 -2
  31. package/package.json +32 -39
  32. package/src/components/createFormattedComponent.tsx +50 -48
  33. package/src/components/injectIntl.tsx +33 -34
  34. package/src/components/message.tsx +33 -32
  35. package/src/components/plural.tsx +22 -22
  36. package/src/components/provider.tsx +36 -36
  37. package/src/components/relative.tsx +70 -70
  38. package/src/components/useIntl.ts +7 -7
  39. package/src/error.ts +26 -13
  40. package/src/formatters/dateTime.ts +25 -33
  41. package/src/formatters/displayName.ts +11 -11
  42. package/src/formatters/list.ts +29 -29
  43. package/src/formatters/message.ts +47 -50
  44. package/src/formatters/number.ts +15 -15
  45. package/src/formatters/plural.ts +10 -10
  46. package/src/formatters/relativeTime.ts +18 -19
  47. package/src/index.ts +49 -36
  48. package/src/tsconfig.cjs.json +8 -8
  49. package/src/tsconfig.json +7 -7
  50. package/src/types.ts +59 -59
  51. package/src/utils.ts +29 -24
  52. package/src/vendor.d.ts +1 -1
@@ -1,11 +1,11 @@
1
- import * as React from 'react';
1
+ import * as React_2 from 'react';
2
2
 
3
3
  declare type ArgumentElement = BaseElement<TYPE.argument>;
4
4
 
5
5
  declare interface BaseElement<T extends TYPE> {
6
6
  type: T;
7
7
  value: string;
8
- location?: Location;
8
+ location?: Location_2;
9
9
  }
10
10
 
11
11
  /**
@@ -32,11 +32,13 @@ declare type DateElement = SimpleFormatElement<TYPE.date, DateTimeSkeleton>;
32
32
  declare interface DateTimeSkeleton {
33
33
  type: SKELETON_TYPE.dateTime;
34
34
  pattern: string;
35
- location?: Location;
35
+ location?: Location_2;
36
36
  }
37
37
 
38
38
  declare const DEFAULT_INTL_CONFIG: Pick<IntlConfig, 'formats' | 'messages' | 'timeZone' | 'textComponent' | 'defaultLocale' | 'defaultFormats' | 'onError'>;
39
39
 
40
+ export declare function defineMessage<T>(msg: T): T;
41
+
40
42
  export declare function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
41
43
 
42
44
  declare class DisplayNames {
@@ -137,7 +139,15 @@ export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'loc
137
139
 
138
140
  declare class FormatError extends Error {
139
141
  readonly code: ErrorCode;
140
- constructor(msg: string, code: ErrorCode);
142
+ /**
143
+ * Original message we're trying to format
144
+ * `undefined` if we're only dealing w/ AST
145
+ *
146
+ * @type {(string | undefined)}
147
+ * @memberof FormatError
148
+ */
149
+ readonly originalMessage: string | undefined;
150
+ constructor(msg: string, code: ErrorCode, originalMessage?: string);
141
151
  toString(): string;
142
152
  }
143
153
 
@@ -157,24 +167,24 @@ declare interface Formats {
157
167
 
158
168
  declare type FormattableUnit = Unit | Units;
159
169
 
160
- export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
170
+ export declare const FormattedDate: React_2.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
161
171
  value: string | number | Date | undefined;
162
172
  }>;
163
173
 
164
- export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
174
+ export declare const FormattedDateParts: React_2.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
165
175
  value: string | number | Date | undefined;
166
- children(val: Intl.DateTimeFormatPart[]): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | null;
176
+ children(val: Intl.DateTimeFormatPart[]): React_2.ReactElement<any, string | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, any>)> | null;
167
177
  }>;
168
178
 
169
- export declare const FormattedDisplayName: React.FC<DisplayNamesOptions & {
179
+ export declare const FormattedDisplayName: React_2.FC<DisplayNamesOptions & {
170
180
  value: string | number | object;
171
181
  }>;
172
182
 
173
- export declare const FormattedList: React.FC<IntlListFormatOptions & {
174
- value: React.ReactNode[];
183
+ export declare const FormattedList: React_2.FC<IntlListFormatOptions & {
184
+ value: React_2.ReactNode[];
175
185
  }>;
176
186
 
177
- export declare class FormattedMessage<T = React.ReactNode, V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>> extends React.Component<Props_3<V>> {
187
+ export declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React_2.ReactElement | FormatXMLElementFn<React_2.ReactNode, React_2.ReactNode>>> extends React_2.Component<Props_3<V>> {
178
188
  static displayName: string;
179
189
  static defaultProps: {
180
190
  values: {};
@@ -183,22 +193,22 @@ export declare class FormattedMessage<T = React.ReactNode, V extends Record<stri
183
193
  render(): JSX.Element;
184
194
  }
185
195
 
186
- export declare const FormattedNumber: React.FC<UnifiedNumberFormatOptions & CustomFormatConfig & {
196
+ export declare const FormattedNumber: React_2.FC<UnifiedNumberFormatOptions & CustomFormatConfig & {
187
197
  value: number;
188
198
  }>;
189
199
 
190
- export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] & {
200
+ export declare const FormattedNumberParts: React_2.FC<Formatter['formatNumber'] & {
191
201
  value: Parameters<IntlShape['formatNumber']>[0];
192
- children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
202
+ children(val: Intl.NumberFormatPart[]): React_2.ReactElement | null;
193
203
  }>;
194
204
 
195
- export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
196
- forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
197
- } & React.RefAttributes<any>> & {
198
- WrappedComponent: React.ComponentType<Props_2>;
205
+ export declare const FormattedPlural: React_2.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
206
+ forwardedRef?: ((instance: any) => void) | React_2.RefObject<any> | null | undefined;
207
+ } & React_2.RefAttributes<any>> & {
208
+ WrappedComponent: React_2.ComponentType<Props_2>;
199
209
  };
200
210
 
201
- export declare class FormattedRelativeTime extends React.PureComponent<Props, State_2> {
211
+ export declare class FormattedRelativeTime extends React_2.PureComponent<Props, State_2> {
202
212
  _updateTimer: any;
203
213
  static displayName: string;
204
214
  static defaultProps: Pick<Props, 'unit' | 'value'>;
@@ -212,13 +222,13 @@ export declare class FormattedRelativeTime extends React.PureComponent<Props, St
212
222
  render(): JSX.Element;
213
223
  }
214
224
 
215
- export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
225
+ export declare const FormattedTime: React_2.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
216
226
  value: string | number | Date | undefined;
217
227
  }>;
218
228
 
219
- export declare const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
229
+ export declare const FormattedTimeParts: React_2.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
220
230
  value: string | number | Date | undefined;
221
- children(val: Intl.DateTimeFormatPart[]): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | null;
231
+ children(val: Intl.DateTimeFormatPart[]): React_2.ReactElement<any, string | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, any>)> | null;
222
232
  }>;
223
233
 
224
234
  declare type Formatter = {
@@ -245,14 +255,14 @@ declare interface Formatters_2 {
245
255
  getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
246
256
  }
247
257
 
248
- declare type FormatXMLElementFn<T> = (...args: Array<string | T>) => string | Array<string | T>;
258
+ declare type FormatXMLElementFn<T, R = string | Array<string | T>> = (...args: Array<string | T>) => R;
249
259
 
250
- export declare function injectIntl<IntlPropName extends string, P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, false>): React.FC<WithIntlProps<P>> & {
251
- WrappedComponent: React.ComponentType<P>;
260
+ export declare function injectIntl<IntlPropName extends string, P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>>(WrappedComponent: React_2.ComponentType<P>, options?: Opts<IntlPropName, false>): React_2.FC<WithIntlProps<P>> & {
261
+ WrappedComponent: React_2.ComponentType<P>;
252
262
  };
253
263
 
254
- export declare function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>, T extends React.ComponentType<P> = any>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, true>): React.ForwardRefExoticComponent<React.PropsWithoutRef<WithIntlProps<P>> & React.RefAttributes<T>> & {
255
- WrappedComponent: React.ComponentType<P>;
264
+ export declare function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>, T extends React_2.ComponentType<P> = any>(WrappedComponent: React_2.ComponentType<P>, options?: Opts<IntlPropName, true>): React_2.ForwardRefExoticComponent<React_2.PropsWithoutRef<WithIntlProps<P>> & React_2.RefAttributes<T>> & {
265
+ WrappedComponent: React_2.ComponentType<P>;
256
266
  };
257
267
 
258
268
  export declare interface IntlCache {
@@ -269,7 +279,7 @@ export declare interface IntlConfig {
269
279
  locale: string;
270
280
  timeZone?: string;
271
281
  formats: CustomFormats;
272
- textComponent?: React.ComponentType | keyof React.ReactHTML;
282
+ textComponent?: React_2.ComponentType | keyof React_2.ReactHTML;
273
283
  messages: Record<string, string> | Record<string, MessageFormatElement[]>;
274
284
  defaultLocale: string;
275
285
  defaultFormats: CustomFormats;
@@ -277,9 +287,9 @@ export declare interface IntlConfig {
277
287
  onError(err: ReactIntlError | FormatError): void;
278
288
  }
279
289
 
280
- export declare const IntlContext: React.Context<IntlShape>;
290
+ export declare const IntlContext: React_2.Context<IntlShape>;
281
291
 
282
- export declare interface IntlFormatters<T = React.ReactNode> {
292
+ export declare interface IntlFormatters<T = React_2.ReactNode, R = T> {
283
293
  formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
284
294
  formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
285
295
  formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
@@ -289,9 +299,9 @@ export declare interface IntlFormatters<T = React.ReactNode> {
289
299
  formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
290
300
  formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
291
301
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
292
- formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
302
+ formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React_2.ReactElement | FormatXMLElementFn<T, R>>): string | React_2.ReactNodeArray;
293
303
  formatList(values: Array<string>, opts?: FormatListOptions): string;
294
- formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
304
+ formatList(values: Array<string | React_2.ReactNode>, opts?: FormatListOptions): React_2.ReactNode;
295
305
  formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
296
306
  }
297
307
 
@@ -329,13 +339,14 @@ declare class IntlMessageFormat {
329
339
  private readonly message;
330
340
  private readonly formatterCache;
331
341
  constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
332
- format: <T = void>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => string | T | (string | T)[];
333
- formatToParts: <T>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => MessageFormatPart<T>[];
342
+ format: <T = void>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T, string | (string | T)[]> | null | undefined> | undefined) => string | T | (string | T)[];
343
+ formatToParts: <T>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T, string | (string | T)[]> | null | undefined> | undefined) => MessageFormatPart<T>[];
334
344
  resolvedOptions: () => {
335
345
  locale: string;
336
346
  };
337
347
  getAst: () => MessageFormatElement[];
338
- static defaultLocale: string;
348
+ private static memoizedDefaultLocale;
349
+ static get defaultLocale(): string;
339
350
  static __parse: typeof parse | undefined;
340
351
  static formats: {
341
352
  number: {
@@ -395,7 +406,7 @@ declare class IntlMessageFormat {
395
406
  };
396
407
  }
397
408
 
398
- export declare class IntlProvider extends React.PureComponent<OptionalIntlConfig, State> {
409
+ export declare class IntlProvider extends React_2.PureComponent<OptionalIntlConfig, State> {
399
410
  static displayName: string;
400
411
  static defaultProps: Pick<IntlConfig, "formats" | "messages" | "timeZone" | "textComponent" | "defaultLocale" | "defaultFormats" | "onError">;
401
412
  private cache;
@@ -509,7 +520,7 @@ declare type LocaleFieldsData = {
509
520
  nu?: Array<string | null>;
510
521
  };
511
522
 
512
- declare interface Location {
523
+ declare interface Location_2 {
513
524
  start: LocationDetails;
514
525
  end: LocationDetails;
515
526
  }
@@ -543,7 +554,7 @@ declare interface NumberFormatDigitOptions {
543
554
  declare interface NumberSkeleton {
544
555
  type: SKELETON_TYPE.number;
545
556
  tokens: NumberSkeletonToken[];
546
- location?: Location;
557
+ location?: Location_2;
547
558
  }
548
559
 
549
560
  declare interface NumberSkeletonToken {
@@ -556,9 +567,10 @@ declare interface ObjectPart<T = any> {
556
567
  value: T;
557
568
  }
558
569
 
559
- export declare type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
570
+ declare type Omit_2<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
571
+ export { Omit_2 as Omit }
560
572
 
561
- declare type OptionalIntlConfig = Omit<IntlConfig, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
573
+ declare type OptionalIntlConfig = Omit_2<IntlConfig, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
562
574
 
563
575
  declare interface Options {
564
576
  formatters?: Formatters_2;
@@ -605,12 +617,12 @@ declare interface PluralElement extends BaseElement<TYPE.plural> {
605
617
 
606
618
  declare interface PluralOrSelectOption {
607
619
  value: MessageFormatElement[];
608
- location?: Location;
620
+ location?: Location_2;
609
621
  }
610
622
 
611
623
  declare interface PoundElement {
612
624
  type: TYPE.pound;
613
- location?: Location;
625
+ location?: Location_2;
614
626
  }
615
627
 
616
628
  declare type PrimitiveType = string | number | boolean | null | undefined | Date;
@@ -619,32 +631,33 @@ declare interface Props extends FormatRelativeTimeOptions {
619
631
  value?: number;
620
632
  unit?: Unit;
621
633
  updateIntervalInSeconds?: number;
622
- children?(value: string): React.ReactChild;
634
+ children?(value: string): React_2.ReactChild;
623
635
  }
624
636
 
625
637
  declare interface Props_2 extends FormatPluralOptions {
626
638
  value: number;
627
639
  intl: IntlShape;
628
- other: React.ReactNode;
629
- zero?: React.ReactNode;
630
- one?: React.ReactNode;
631
- two?: React.ReactNode;
632
- few?: React.ReactNode;
633
- many?: React.ReactNode;
634
- children?(value: React.ReactNode): React.ReactElement | null;
640
+ other: React_2.ReactNode;
641
+ zero?: React_2.ReactNode;
642
+ one?: React_2.ReactNode;
643
+ two?: React_2.ReactNode;
644
+ few?: React_2.ReactNode;
645
+ many?: React_2.ReactNode;
646
+ children?(value: React_2.ReactNode): React_2.ReactElement | null;
635
647
  }
636
648
 
637
- declare interface Props_3<V extends Record<string, any> = Record<string, React.ReactNode>> extends MessageDescriptor {
649
+ declare interface Props_3<V extends Record<string, any> = Record<string, React_2.ReactNode>> extends MessageDescriptor {
638
650
  values?: V;
639
- tagName?: React.ElementType<any>;
640
- children?(...nodes: React.ReactNodeArray): React.ReactNode;
651
+ tagName?: React_2.ElementType<any>;
652
+ children?(...nodes: React_2.ReactNodeArray): React_2.ReactNode;
641
653
  }
642
654
 
643
- export declare const RawIntlProvider: React.Provider<IntlShape>;
655
+ export declare const RawIntlProvider: React_2.Provider<IntlShape>;
644
656
 
645
657
  export declare class ReactIntlError extends Error {
646
- code: ReactIntlErrorCode;
647
- constructor(code: ReactIntlErrorCode, message: string, exception?: Error);
658
+ readonly code: ReactIntlErrorCode;
659
+ readonly descriptor?: MessageDescriptor;
660
+ constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error);
648
661
  }
649
662
 
650
663
  export declare const enum ReactIntlErrorCode {
@@ -772,7 +785,7 @@ declare interface TagElement {
772
785
  type: TYPE.tag;
773
786
  value: string;
774
787
  children: MessageFormatElement[];
775
- location?: Location;
788
+ location?: Location_2;
776
789
  }
777
790
 
778
791
  declare type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>;
@@ -861,8 +874,8 @@ export declare function useIntl(): IntlShape;
861
874
 
862
875
  declare type ValidPluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other' | string;
863
876
 
864
- export declare type WithIntlProps<P> = Omit<P, keyof WrappedComponentProps> & {
865
- forwardedRef?: React.Ref<any>;
877
+ export declare type WithIntlProps<P> = Omit_2<P, keyof WrappedComponentProps> & {
878
+ forwardedRef?: React_2.Ref<any>;
866
879
  };
867
880
 
868
881
  export declare type WrappedComponentProps<IntlPropName extends string = 'intl'> = {
@@ -277,6 +277,13 @@
277
277
 
278
278
  TYPE[TYPE["tag"] = 8] = "tag";
279
279
  })(TYPE || (TYPE = {}));
280
+
281
+ var SKELETON_TYPE;
282
+
283
+ (function (SKELETON_TYPE) {
284
+ SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
285
+ SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
286
+ })(SKELETON_TYPE || (SKELETON_TYPE = {}));
280
287
  /**
281
288
  * Type Guards
282
289
  */
@@ -3991,7 +3998,7 @@
3991
3998
  return unit.replace(/^(.*?)-/, '');
3992
3999
  }
3993
4000
 
3994
- var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\+|#+)?)?$/g;
4001
+ var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
3995
4002
  var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g;
3996
4003
 
3997
4004
  function parseSignificantPrecision(str) {
@@ -4095,6 +4102,7 @@
4095
4102
  continue;
4096
4103
 
4097
4104
  case 'precision-integer':
4105
+ case '.':
4098
4106
  result.maximumFractionDigits = 0;
4099
4107
  continue;
4100
4108
 
@@ -4154,6 +4162,7 @@
4154
4162
  continue;
4155
4163
  } // Precision
4156
4164
  // https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#fraction-precision
4165
+ // precision-integer case
4157
4166
 
4158
4167
 
4159
4168
  if (FRACTION_PRECISION_REGEX.test(token.stem)) {
@@ -4161,21 +4170,21 @@
4161
4170
  throw new RangeError('Fraction-precision stems only accept a single optional option');
4162
4171
  }
4163
4172
 
4164
- token.stem.replace(FRACTION_PRECISION_REGEX, function (match, g1, g2) {
4165
- // precision-integer case
4166
- if (match === '.') {
4167
- result.maximumFractionDigits = 0;
4168
- } // .000+ case
4169
- else if (g2 === '+') {
4170
- result.minimumFractionDigits = g2.length;
4171
- } // .### case
4172
- 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;
4173
4186
  result.maximumFractionDigits = g1.length;
4174
- } // .00## or .000 case
4175
- else {
4176
- result.minimumFractionDigits = g1.length;
4177
- result.maximumFractionDigits = g1.length + (typeof g2 === 'string' ? g2.length : 0);
4178
- }
4187
+ }
4179
4188
 
4180
4189
  return '';
4181
4190
  });
@@ -4317,10 +4326,11 @@
4317
4326
  function (_super) {
4318
4327
  __extends$1(FormatError, _super);
4319
4328
 
4320
- function FormatError(msg, code) {
4329
+ function FormatError(msg, code, originalMessage) {
4321
4330
  var _this = _super.call(this, msg) || this;
4322
4331
 
4323
4332
  _this.code = code;
4333
+ _this.originalMessage = originalMessage;
4324
4334
  return _this;
4325
4335
  }
4326
4336
 
@@ -4336,15 +4346,29 @@
4336
4346
  function (_super) {
4337
4347
  __extends$1(InvalidValueError, _super);
4338
4348
 
4339
- function InvalidValueError(variableId, value, options) {
4349
+ function InvalidValueError(variableId, value, options, originalMessage) {
4340
4350
  return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", "INVALID_VALUE"
4341
4351
  /* INVALID_VALUE */
4342
- ) || this;
4352
+ , originalMessage) || this;
4343
4353
  }
4344
4354
 
4345
4355
  return InvalidValueError;
4346
4356
  }(FormatError);
4347
4357
 
4358
+ var InvalidValueTypeError =
4359
+ /** @class */
4360
+ function (_super) {
4361
+ __extends$1(InvalidValueTypeError, _super);
4362
+
4363
+ function InvalidValueTypeError(value, type, originalMessage) {
4364
+ return _super.call(this, "Value for \"" + value + "\" must be of type " + type, "INVALID_VALUE"
4365
+ /* INVALID_VALUE */
4366
+ , originalMessage) || this;
4367
+ }
4368
+
4369
+ return InvalidValueTypeError;
4370
+ }(FormatError);
4371
+
4348
4372
  var MissingValueError =
4349
4373
  /** @class */
4350
4374
  function (_super) {
@@ -4353,7 +4377,7 @@
4353
4377
  function MissingValueError(variableId, originalMessage) {
4354
4378
  return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"", "MISSING_VALUE"
4355
4379
  /* MISSING_VALUE */
4356
- ) || this;
4380
+ , originalMessage) || this;
4357
4381
  }
4358
4382
 
4359
4383
  return MissingValueError;
@@ -4501,7 +4525,7 @@
4501
4525
  var formatFn = values[value_1];
4502
4526
 
4503
4527
  if (!isFormatXMLElementFn(formatFn)) {
4504
- throw new TypeError("Value for \"" + value_1 + "\" must be a function");
4528
+ throw new InvalidValueTypeError(value_1, 'function', originalMessage);
4505
4529
  }
4506
4530
 
4507
4531
  var parts = formatToParts(children, locales, formatters, formats, values);
@@ -4529,7 +4553,7 @@
4529
4553
  var opt = el.options[value] || el.options.other;
4530
4554
 
4531
4555
  if (!opt) {
4532
- throw new InvalidValueError(el.value, value, Object.keys(el.options));
4556
+ throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
4533
4557
  }
4534
4558
 
4535
4559
  result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
@@ -4543,7 +4567,7 @@
4543
4567
  if (!Intl.PluralRules) {
4544
4568
  throw new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", "MISSING_INTL_API"
4545
4569
  /* MISSING_INTL_API */
4546
- );
4570
+ , originalMessage);
4547
4571
  }
4548
4572
 
4549
4573
  var rule = formatters.getPluralRules(locales, {
@@ -4553,7 +4577,7 @@
4553
4577
  }
4554
4578
 
4555
4579
  if (!opt) {
4556
- throw new InvalidValueError(el.value, value, Object.keys(el.options));
4580
+ throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
4557
4581
  }
4558
4582
 
4559
4583
  result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values, value - (el.offset || 0)));
@@ -4707,7 +4731,18 @@
4707
4731
  this.formatters = opts && opts.formatters || createDefaultFormatters(this.formatterCache);
4708
4732
  }
4709
4733
 
4710
- 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;
4711
4746
  IntlMessageFormat.__parse = parse; // Default format options used as the prototype of the `formats` provided to the
4712
4747
  // constructor. These are used when constructing the internal Intl.NumberFormat
4713
4748
  // and Intl.DateTimeFormat instances.
@@ -4800,13 +4835,14 @@
4800
4835
 
4801
4836
  var _super = _createSuper(ReactIntlError);
4802
4837
 
4803
- function ReactIntlError(code, message, exception) {
4838
+ function ReactIntlError(code, message, descriptor, exception) {
4804
4839
  var _this;
4805
4840
 
4806
4841
  _classCallCheck(this, ReactIntlError);
4807
4842
 
4808
4843
  _this = _super.call(this, "[React Intl Error ".concat(code, "] ").concat(message, " ").concat(exception ? "\n".concat(exception.stack) : ''));
4809
4844
  _this.code = code;
4845
+ _this.descriptor = descriptor;
4810
4846
 
4811
4847
  if (typeof Error.captureStackTrace === 'function') {
4812
4848
  Error.captureStackTrace(_assertThisInitialized(_this), ReactIntlError);
@@ -5322,7 +5358,9 @@
5322
5358
  invariantIntlContext(intl);
5323
5359
  }
5324
5360
 
5325
- return React.createElement(WrappedComponent, Object.assign({}, props, _defineProperty({}, intlPropName, intl), {
5361
+ var intlProp = _defineProperty({}, intlPropName, intl);
5362
+
5363
+ return React.createElement(WrappedComponent, Object.assign({}, props, intlProp, {
5326
5364
  ref: forwardRef ? props.forwardedRef : null
5327
5365
  }));
5328
5366
  });
@@ -5412,7 +5450,8 @@
5412
5450
 
5413
5451
  var value = props.value,
5414
5452
  children = props.children,
5415
- 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
5416
5455
 
5417
5456
 
5418
5457
  var formattedValue = intl[name](value, formatProps);
@@ -5688,7 +5727,7 @@
5688
5727
  } catch (e) {
5689
5728
  onError(new ReactIntlError("FORMAT_ERROR"
5690
5729
  /* FORMAT_ERROR */
5691
- , "Error formatting message: \"".concat(id, "\" for locale: \"").concat(locale, "\"") + (defaultMessage ? ', using default message as fallback.' : ''), e));
5730
+ , "Error formatting message: \"".concat(id, "\" for locale: \"").concat(locale, "\"") + (defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor, e));
5692
5731
  }
5693
5732
  } else if (!defaultMessage || locale && locale.toLowerCase() !== defaultLocale.toLowerCase()) {
5694
5733
  // This prevents warnings from littering the console in development
@@ -5696,7 +5735,7 @@
5696
5735
  // default locale.
5697
5736
  onError(new ReactIntlError("MISSING_TRANSLATION"
5698
5737
  /* MISSING_TRANSLATION */
5699
- , "Missing message: \"".concat(id, "\" for locale: \"").concat(locale, "\"") + (defaultMessage ? ', using default message as fallback.' : '')));
5738
+ , "Missing message: \"".concat(id, "\" for locale: \"").concat(locale, "\"") + (defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor));
5700
5739
  }
5701
5740
 
5702
5741
  if (!formattedMessageParts && defaultMessage) {
@@ -5707,14 +5746,14 @@
5707
5746
  } catch (e) {
5708
5747
  onError(new ReactIntlError("FORMAT_ERROR"
5709
5748
  /* FORMAT_ERROR */
5710
- , "Error formatting the default message for: \"".concat(id, "\""), e));
5749
+ , "Error formatting the default message for: \"".concat(id, "\""), messageDescriptor, e));
5711
5750
  }
5712
5751
  }
5713
5752
 
5714
5753
  if (!formattedMessageParts) {
5715
5754
  onError(new ReactIntlError("FORMAT_ERROR"
5716
5755
  /* FORMAT_ERROR */
5717
- , "Cannot format message: \"".concat(id, "\", ") + "using message ".concat(message || defaultMessage ? 'source' : 'id', " as fallback.")));
5756
+ , "Cannot format message: \"".concat(id, "\", ") + "using message ".concat(message || defaultMessage ? 'source' : 'id', " as fallback."), messageDescriptor));
5718
5757
 
5719
5758
  if (typeof message === 'string') {
5720
5759
  return message || defaultMessage || String(id);
@@ -6313,6 +6352,9 @@
6313
6352
  function defineMessages(msgs) {
6314
6353
  return msgs;
6315
6354
  }
6355
+ function defineMessage(msg) {
6356
+ return msg;
6357
+ }
6316
6358
 
6317
6359
  var FormattedDate = createFormattedComponent('formatDate');
6318
6360
  var FormattedTime = createFormattedComponent('formatTime');
@@ -6339,6 +6381,7 @@
6339
6381
  exports.ReactIntlError = ReactIntlError;
6340
6382
  exports.createIntl = createIntl;
6341
6383
  exports.createIntlCache = createIntlCache;
6384
+ exports.defineMessage = defineMessage;
6342
6385
  exports.defineMessages = defineMessages;
6343
6386
  exports.injectIntl = injectIntl;
6344
6387
  exports.useIntl = useIntl;