react-intl 3.12.0 → 4.1.1

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 (66) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/components/message.d.ts +1 -1
  3. package/dist/components/message.js +2 -2
  4. package/dist/components/plural.d.ts +1 -1
  5. package/dist/components/provider.js +13 -8
  6. package/dist/error.d.ts +11 -0
  7. package/dist/error.js +28 -0
  8. package/dist/formatters/dateTime.js +5 -4
  9. package/dist/formatters/displayName.js +4 -2
  10. package/dist/formatters/list.js +4 -2
  11. package/dist/formatters/message.d.ts +1 -2
  12. package/dist/formatters/message.js +17 -34
  13. package/dist/formatters/number.js +3 -2
  14. package/dist/formatters/plural.js +4 -2
  15. package/dist/formatters/relativeTime.js +4 -2
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +6 -4
  18. package/dist/react-intl.api.md +29 -22
  19. package/dist/react-intl.d.ts +77 -36
  20. package/dist/react-intl.js +6267 -5860
  21. package/dist/react-intl.js.map +1 -1
  22. package/dist/react-intl.min.js +1 -1
  23. package/dist/react-intl.min.js.map +1 -1
  24. package/dist/types.d.ts +5 -5
  25. package/dist/utils.d.ts +3 -4
  26. package/dist/utils.js +2 -18
  27. package/lib/components/message.d.ts +1 -1
  28. package/lib/components/message.js +2 -2
  29. package/lib/components/plural.d.ts +1 -1
  30. package/lib/components/provider.js +15 -10
  31. package/lib/error.d.ts +11 -0
  32. package/lib/error.js +9 -0
  33. package/lib/formatters/dateTime.js +6 -5
  34. package/lib/formatters/displayName.js +6 -4
  35. package/lib/formatters/list.js +6 -4
  36. package/lib/formatters/message.d.ts +1 -2
  37. package/lib/formatters/message.js +17 -31
  38. package/lib/formatters/number.js +4 -3
  39. package/lib/formatters/plural.js +6 -4
  40. package/lib/formatters/relativeTime.js +6 -4
  41. package/lib/index.d.ts +2 -2
  42. package/lib/index.js +4 -2
  43. package/lib/react-intl.d.ts +21 -17
  44. package/lib/tsdoc-metadata.json +1 -1
  45. package/lib/types.d.ts +5 -5
  46. package/lib/utils.d.ts +3 -4
  47. package/lib/utils.js +2 -16
  48. package/package.json +45 -47
  49. package/src/components/message.tsx +6 -5
  50. package/src/components/provider.tsx +25 -14
  51. package/src/error.ts +18 -0
  52. package/src/formatters/dateTime.ts +30 -5
  53. package/src/formatters/displayName.ts +15 -4
  54. package/src/formatters/list.ts +15 -4
  55. package/src/formatters/message.ts +49 -66
  56. package/src/formatters/number.ts +16 -3
  57. package/src/formatters/plural.ts +15 -4
  58. package/src/formatters/relativeTime.ts +15 -4
  59. package/src/index.ts +4 -2
  60. package/src/types.ts +5 -7
  61. package/src/utils.ts +4 -25
  62. package/dist/components/html-message.d.ts +0 -11
  63. package/dist/components/html-message.js +0 -75
  64. package/lib/components/html-message.d.ts +0 -11
  65. package/lib/components/html-message.js +0 -43
  66. package/src/components/html-message.tsx +0 -68
@@ -5,11 +5,6 @@ import * as React from 'react';
5
5
 
6
6
  declare type ArgumentElement = BaseElement<TYPE.argument>;
7
7
 
8
- declare interface ArgumentPart {
9
- type: PART_TYPE.argument;
10
- value: any;
11
- }
12
-
13
8
  declare interface BaseElement<T extends TYPE> {
14
9
  type: T;
15
10
  value: string;
@@ -50,6 +45,12 @@ declare interface ElementPart {
50
45
  value: string;
51
46
  }
52
47
 
48
+ declare const enum ErrorCode {
49
+ MISSING_VALUE = 0,
50
+ INVALID_VALUE = 1,
51
+ MISSING_INTL_API = 2
52
+ }
53
+
53
54
  declare interface FieldData {
54
55
  '0'?: string;
55
56
  '1'?: string;
@@ -66,6 +67,12 @@ export declare type FormatDateOptions = Exclude<Intl.DateTimeFormatOptions, 'loc
66
67
 
67
68
  export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
68
69
 
70
+ declare class FormatError extends Error {
71
+ readonly code: ErrorCode;
72
+ constructor(msg: string, code: ErrorCode);
73
+ toString(): string;
74
+ }
75
+
69
76
  export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;
70
77
 
71
78
  export declare type FormatNumberOptions = Exclude<UnifiedNumberFormatOptions, 'localeMatcher'> & CustomFormatConfig;
@@ -95,20 +102,11 @@ export declare const FormattedDisplayName: React.FC<DisplayNamesOptions_2 & {
95
102
  value: string | number | object;
96
103
  }>;
97
104
 
98
- export declare class FormattedHTMLMessage extends FormattedMessage<Record<string, PrimitiveType>> {
99
- static displayName: string;
100
- static defaultProps: {
101
- tagName: "span";
102
- values: {};
103
- };
104
- render(): JSX.Element;
105
- }
106
-
107
105
  export declare const FormattedList: React.FC<IntlListFormatOptions & {
108
106
  value: React.ReactNode[];
109
107
  }>;
110
108
 
111
- export declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn>> extends React.Component<Props_3<V>> {
109
+ 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>> {
112
110
  static displayName: string;
113
111
  static defaultProps: {
114
112
  values: {};
@@ -126,7 +124,7 @@ export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] &
126
124
  children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
127
125
  }>;
128
126
 
129
- export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
127
+ export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
130
128
  forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
131
129
  } & React.RefAttributes<any>> & {
132
130
  WrappedComponent: React.ComponentType<Props_2>;
@@ -179,7 +177,7 @@ declare interface Formatters_2 {
179
177
  getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
180
178
  }
181
179
 
182
- declare type FormatXMLElementFn = (...args: any[]) => string | object;
180
+ declare type FormatXMLElementFn<T> = (...args: Array<string | T>) => string | Array<string | T>;
183
181
 
184
182
  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>> & {
185
183
  WrappedComponent: React.ComponentType<P>;
@@ -207,12 +205,12 @@ export declare interface IntlConfig {
207
205
  messages: Record<string, string> | Record<string, MessageFormatElement[]>;
208
206
  defaultLocale: string;
209
207
  defaultFormats: CustomFormats;
210
- onError(err: string): void;
208
+ onError(err: ReactIntlError | FormatError): void;
211
209
  }
212
210
 
213
211
  export declare const IntlContext: React.Context<IntlShape>;
214
212
 
215
- export declare interface IntlFormatters {
213
+ export declare interface IntlFormatters<T = React.ReactNode> {
216
214
  formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
217
215
  formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
218
216
  formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
@@ -222,8 +220,7 @@ export declare interface IntlFormatters {
222
220
  formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
223
221
  formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
224
222
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
225
- formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn>): string | React.ReactNodeArray;
226
- formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
223
+ formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
227
224
  formatList(values: Array<string>, opts?: FormatListOptions): string;
228
225
  formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
229
226
  formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
@@ -263,9 +260,8 @@ declare class IntlMessageFormat {
263
260
  private readonly message;
264
261
  private readonly formatterCache;
265
262
  constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
266
- format: (values?: Record<string, PrimitiveType> | undefined) => string;
267
- formatToParts: (values?: Record<string, any> | undefined) => MessageFormatPart[];
268
- formatHTMLMessage: (values?: Record<string, string | number | boolean | object | Date | FormatXMLElementFn | null | undefined> | undefined) => (string | object)[];
263
+ format: <T = void>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => string | T | (string | T)[];
264
+ formatToParts: <T>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => MessageFormatPart<T>[];
269
265
  resolvedOptions: () => {
270
266
  locale: string;
271
267
  };
@@ -459,9 +455,9 @@ export declare interface MessageDescriptor {
459
455
  defaultMessage?: string;
460
456
  }
461
457
 
462
- declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement | PoundElement;
458
+ declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement | TagElement | PoundElement;
463
459
 
464
- declare type MessageFormatPart = LiteralPart_2 | ArgumentPart;
460
+ declare type MessageFormatPart<T> = LiteralPart_2 | ObjectPart<T>;
465
461
 
466
462
  declare type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;
467
463
 
@@ -484,6 +480,11 @@ declare interface NumberSkeletonToken {
484
480
  options: string[];
485
481
  }
486
482
 
483
+ declare interface ObjectPart<T = any> {
484
+ type: PART_TYPE.object;
485
+ value: T;
486
+ }
487
+
487
488
  export declare type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
488
489
 
489
490
  declare type OptionalIntlConfig = Omit<IntlConfig, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
@@ -522,7 +523,7 @@ declare type Part_2 = LiteralPart | ElementPart;
522
523
 
523
524
  declare const enum PART_TYPE {
524
525
  literal = 0,
525
- argument = 1
526
+ object = 1
526
527
  }
527
528
 
528
529
  declare interface PluralElement extends BaseElement<TYPE.plural> {
@@ -570,6 +571,19 @@ declare interface Props_3<V extends Record<string, any> = Record<string, React.R
570
571
 
571
572
  export declare const RawIntlProvider: React.Provider<IntlShape>;
572
573
 
574
+ export declare class ReactIntlError extends Error {
575
+ code: ReactIntlErrorCode;
576
+ constructor(code: ReactIntlErrorCode, message: string, exception?: Error);
577
+ }
578
+
579
+ export declare const enum ReactIntlErrorCode {
580
+ FORMAT_ERROR = "FORMAT_ERROR",
581
+ UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
582
+ INVALID_CONFIG = "INVALID_CONFIG",
583
+ MISSING_DATA = "MISSING_DATA",
584
+ MISSING_TRANSLATION = "MISSING_TRANSLATION"
585
+ }
586
+
573
587
  declare type RelativeTimeData = {
574
588
  [u in LDMLPluralRule]?: string;
575
589
  };
@@ -679,6 +693,13 @@ declare interface State_2 {
679
693
  currentValueInSeconds: number;
680
694
  }
681
695
 
696
+ declare interface TagElement {
697
+ type: TYPE.tag;
698
+ value: string;
699
+ children: MessageFormatElement[];
700
+ location?: Location;
701
+ }
702
+
682
703
  declare type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>;
683
704
 
684
705
  declare enum TYPE {
@@ -714,21 +735,41 @@ declare enum TYPE {
714
735
  * Only possible within plural argument.
715
736
  * This is the `#` symbol that will be substituted with the count.
716
737
  */
717
- pound = 7
738
+ pound = 7,
739
+ /**
740
+ * XML-like tag
741
+ */
742
+ tag = 8
718
743
  }
719
744
 
720
745
  declare type UnifiedNumberFormatOptions = Intl.NumberFormatOptions & NumberFormatDigitOptions & {
721
- localeMatcher?: 'lookup' | 'best fit';
722
- style?: 'decimal' | 'percent' | 'currency' | 'unit';
723
- compactDisplay?: 'short' | 'long';
724
- currencyDisplay?: 'symbol' | 'code' | 'name' | 'narrowSymbol';
725
- currencySign?: 'standard' | 'accounting';
726
- notation?: 'standard' | 'scientific' | 'engineering' | 'compact';
727
- signDisplay?: 'auto' | 'always' | 'never' | 'exceptZero';
746
+ localeMatcher?: UnifiedNumberFormatOptionsLocaleMatcher;
747
+ style?: UnifiedNumberFormatOptionsStyle;
748
+ compactDisplay?: UnifiedNumberFormatOptionsCompactDisplay;
749
+ currencyDisplay?: UnifiedNumberFormatOptionsCurrencyDisplay;
750
+ currencySign?: UnifiedNumberFormatOptionsCurrencySign;
751
+ notation?: UnifiedNumberFormatOptionsNotation;
752
+ signDisplay?: UnifiedNumberFormatOptionsSignDisplay;
728
753
  unit?: Unit_2;
729
- unitDisplay?: 'long' | 'short' | 'narrow';
754
+ unitDisplay?: UnifiedNumberFormatOptionsUnitDisplay;
730
755
  };
731
756
 
757
+ declare type UnifiedNumberFormatOptionsCompactDisplay = 'short' | 'long';
758
+
759
+ declare type UnifiedNumberFormatOptionsCurrencyDisplay = 'symbol' | 'code' | 'name' | 'narrowSymbol';
760
+
761
+ declare type UnifiedNumberFormatOptionsCurrencySign = 'standard' | 'accounting';
762
+
763
+ declare type UnifiedNumberFormatOptionsLocaleMatcher = 'lookup' | 'best fit';
764
+
765
+ declare type UnifiedNumberFormatOptionsNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
766
+
767
+ declare type UnifiedNumberFormatOptionsSignDisplay = 'auto' | 'always' | 'never' | 'exceptZero';
768
+
769
+ declare type UnifiedNumberFormatOptionsStyle = 'decimal' | 'percent' | 'currency' | 'unit';
770
+
771
+ declare type UnifiedNumberFormatOptionsUnitDisplay = 'long' | 'short' | 'narrow';
772
+
732
773
  declare type Unit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
733
774
 
734
775
  declare type Unit_2 = 'degree' | 'acre' | 'hectare' | 'percent' | 'bit' | 'byte' | 'gigabit' | 'gigabyte' | 'kilobit' | 'kilobyte' | 'megabit' | 'megabyte' | 'petabyte' | 'terabit' | 'terabyte' | 'day' | 'hour' | 'millisecond' | 'minute' | 'month' | 'second' | 'week' | 'year' | 'centimeter' | 'foot' | 'inch' | 'kilometer' | 'meter' | 'mile-scandinavian' | 'mile' | 'millimeter' | 'yard' | 'gram' | 'kilogram' | 'ounce' | 'pound' | 'stone' | 'celsius' | 'fahrenheit' | 'fluid-ounce' | 'gallon' | 'liter' | 'milliliter';