react-intl 3.9.1 → 3.11.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 (46) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/components/createFormattedComponent.js +4 -2
  3. package/dist/components/html-message.js +1 -1
  4. package/dist/components/injectIntl.d.ts +1 -1
  5. package/dist/components/message.js +13 -4
  6. package/dist/components/plural.d.ts +1 -1
  7. package/dist/components/provider.js +2 -2
  8. package/dist/components/relative.js +3 -10
  9. package/dist/formatters/dateTime.js +2 -2
  10. package/dist/formatters/list.d.ts +1 -2
  11. package/dist/formatters/message.d.ts +1 -0
  12. package/dist/formatters/message.js +19 -18
  13. package/dist/index.d.ts +2 -2
  14. package/dist/react-intl.api.md +7 -5
  15. package/dist/react-intl.d.ts +30 -9
  16. package/dist/react-intl.js +563 -386
  17. package/dist/react-intl.js.map +1 -1
  18. package/dist/react-intl.min.js +1 -1
  19. package/dist/react-intl.min.js.map +1 -1
  20. package/dist/types.d.ts +2 -1
  21. package/dist/utils.d.ts +1 -1
  22. package/dist/utils.js +2 -7
  23. package/lib/components/createFormattedComponent.js +4 -2
  24. package/lib/components/html-message.js +1 -1
  25. package/lib/components/injectIntl.d.ts +1 -1
  26. package/lib/components/message.js +5 -3
  27. package/lib/components/plural.d.ts +1 -1
  28. package/lib/components/provider.js +2 -2
  29. package/lib/components/relative.js +3 -10
  30. package/lib/formatters/dateTime.js +2 -2
  31. package/lib/formatters/list.d.ts +1 -2
  32. package/lib/formatters/message.d.ts +1 -0
  33. package/lib/formatters/message.js +12 -18
  34. package/lib/index.d.ts +2 -2
  35. package/lib/react-intl.d.ts +6 -5
  36. package/lib/tsdoc-metadata.json +1 -1
  37. package/lib/types.d.ts +2 -1
  38. package/lib/utils.d.ts +1 -1
  39. package/lib/utils.js +1 -6
  40. package/package.json +31 -31
  41. package/src/components/provider.tsx +1 -1
  42. package/src/components/relative.tsx +6 -15
  43. package/src/formatters/list.ts +7 -1
  44. package/src/formatters/message.ts +13 -18
  45. package/src/types.ts +5 -1
  46. package/src/utils.ts +2 -7
package/dist/types.d.ts CHANGED
@@ -37,6 +37,7 @@ export interface IntlFormatters {
37
37
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
38
38
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn>): string | React.ReactNodeArray;
39
39
  formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
40
+ formatList(values: Array<string>, opts?: FormatListOptions): string;
40
41
  formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
41
42
  }
42
43
  export interface Formatters {
@@ -59,7 +60,7 @@ export interface IntlCache {
59
60
  list: Record<string, IntlListFormat>;
60
61
  }
61
62
  export interface MessageDescriptor {
62
- id?: string;
63
+ id?: string | number;
63
64
  description?: string | object;
64
65
  defaultMessage?: string;
65
66
  }
package/dist/utils.d.ts CHANGED
@@ -2,7 +2,7 @@ import { IntlConfig, IntlCache, CustomFormats, Formatters } from './types';
2
2
  import { IntlRelativeTimeFormatOptions } from '@formatjs/intl-relativetimeformat';
3
3
  export declare function escape(str: string): string;
4
4
  export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, whitelist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
5
- export declare function invariantIntlContext(intl?: any): void;
5
+ export declare function invariantIntlContext(intl?: any): asserts intl;
6
6
  export declare function createError(message: string, exception?: Error): string;
7
7
  export declare function defaultErrorHandler(error: string): void;
8
8
  export declare const DEFAULT_INTL_CONFIG: Pick<IntlConfig, 'formats' | 'messages' | 'timeZone' | 'textComponent' | 'defaultLocale' | 'defaultFormats' | 'onError'>;
package/dist/utils.js CHANGED
@@ -13,12 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  var React = require("react");
14
14
  var intl_messageformat_1 = require("intl-messageformat");
15
15
  var intl_format_cache_1 = require("intl-format-cache");
16
- // Since rollup cannot deal with namespace being a function,
17
- // this is to interop with TypeScript since `invariant`
18
- // does not export a default
19
- // https://github.com/rollup/rollup/issues/1267
20
- var invariant_ = require("invariant");
21
- var invariant = invariant_.default || invariant_;
16
+ var intl_utils_1 = require("@formatjs/intl-utils");
22
17
  var ESCAPED_CHARS = {
23
18
  38: '&amp;',
24
19
  62: '&gt;',
@@ -45,7 +40,7 @@ function filterProps(props, whitelist, defaults) {
45
40
  }
46
41
  exports.filterProps = filterProps;
47
42
  function invariantIntlContext(intl) {
48
- invariant(intl, '[React Intl] Could not find required `intl` object. ' +
43
+ intl_utils_1.invariant(intl, '[React Intl] Could not find required `intl` object. ' +
49
44
  '<IntlProvider> needs to exist in the component ancestry.');
50
45
  }
51
46
  exports.invariantIntlContext = invariantIntlContext;
@@ -3,8 +3,10 @@ var __rest = (this && this.__rest) || function (s, e) {
3
3
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
4
  t[p] = s[p];
5
5
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
7
- t[p[i]] = s[p[i]];
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
8
10
  return t;
9
11
  };
10
12
  import * as React from 'react';
@@ -39,5 +39,5 @@ class FormattedHTMLMessage extends FormattedMessage {
39
39
  }
40
40
  }
41
41
  FormattedHTMLMessage.displayName = 'FormattedHTMLMessage';
42
- FormattedHTMLMessage.defaultProps = Object.assign({}, FormattedMessage.defaultProps, { tagName: 'span' });
42
+ FormattedHTMLMessage.defaultProps = Object.assign(Object.assign({}, FormattedMessage.defaultProps), { tagName: 'span' });
43
43
  export default FormattedHTMLMessage;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { IntlShape, Omit } from '../types';
3
- export declare const Provider: React.ProviderExoticComponent<React.ProviderProps<IntlShape>>;
3
+ export declare const Provider: React.Provider<IntlShape>;
4
4
  export declare const Context: React.Context<IntlShape>;
5
5
  export interface Opts<IntlPropName extends string = 'intl', ForwardRef extends boolean = false> {
6
6
  intlPropName?: IntlPropName;
@@ -8,8 +8,10 @@ var __rest = (this && this.__rest) || function (s, e) {
8
8
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
9
9
  t[p] = s[p];
10
10
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
11
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
12
- t[p[i]] = s[p[i]];
11
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
12
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
13
+ t[p[i]] = s[p[i]];
14
+ }
13
15
  return t;
14
16
  };
15
17
  import * as React from 'react';
@@ -22,7 +24,7 @@ const defaultFormatMessage = (descriptor, values) => {
22
24
  if (process.env.NODE_ENV !== 'production') {
23
25
  console.error('[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry. Using default message as fallback.');
24
26
  }
25
- return formatMessage(Object.assign({}, DEFAULT_INTL_CONFIG, { locale: 'en' }), createFormatters(), descriptor, values);
27
+ return formatMessage(Object.assign(Object.assign({}, DEFAULT_INTL_CONFIG), { locale: 'en' }), createFormatters(), descriptor, values);
26
28
  };
27
29
  class FormattedMessage extends React.Component {
28
30
  shouldComponentUpdate(nextProps) {
@@ -11,7 +11,7 @@ interface Props extends FormatPluralOptions {
11
11
  many?: React.ReactNode;
12
12
  children?(value: React.ReactNode): React.ReactElement | null;
13
13
  }
14
- declare const _default: React.ForwardRefExoticComponent<Pick<Props, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "type" | "format" | "value"> & {
14
+ declare const _default: React.ForwardRefExoticComponent<Pick<Props, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
15
15
  forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
16
16
  } & React.RefAttributes<any>> & {
17
17
  WrappedComponent: React.ComponentType<Props>;
@@ -34,7 +34,7 @@ function processIntlConfig(config) {
34
34
  */
35
35
  export function createIntl(config, cache) {
36
36
  const formatters = createFormatters(cache);
37
- const resolvedConfig = Object.assign({}, DEFAULT_INTL_CONFIG, config);
37
+ const resolvedConfig = Object.assign(Object.assign({}, DEFAULT_INTL_CONFIG), config);
38
38
  if (!resolvedConfig.locale ||
39
39
  !areIntlLocalesSupported(resolvedConfig.locale)) {
40
40
  const { locale, defaultLocale, onError } = resolvedConfig;
@@ -49,7 +49,7 @@ export function createIntl(config, cache) {
49
49
  // each <FormattedMessage> contains a `defaultMessage` prop.
50
50
  resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
51
51
  }
52
- return Object.assign({}, resolvedConfig, { formatters, formatNumber: formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: formatMessage.bind(null, resolvedConfig, formatters), formatHTMLMessage: formatHTMLMessage.bind(null, resolvedConfig, formatters), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat) });
52
+ return Object.assign(Object.assign({}, resolvedConfig), { formatters, formatNumber: formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: formatMessage.bind(null, resolvedConfig, formatters), formatHTMLMessage: formatHTMLMessage.bind(null, resolvedConfig, formatters), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat) });
53
53
  }
54
54
  export default class IntlProvider extends React.PureComponent {
55
55
  constructor() {
@@ -6,12 +6,7 @@
6
6
  import * as React from 'react';
7
7
  import { Context } from './injectIntl';
8
8
  import { invariantIntlContext } from '../utils';
9
- // Since rollup cannot deal with namespace being a function,
10
- // this is to interop with TypeScript since `invariant`
11
- // does not export a default
12
- // https://github.com/rollup/rollup/issues/1267
13
- import * as invariant_ from 'invariant';
14
- const invariant = invariant_.default || invariant_;
9
+ import { invariant } from '@formatjs/intl-utils';
15
10
  const MINUTE = 60;
16
11
  const HOUR = 60 * 60;
17
12
  const DAY = 60 * 60 * 24;
@@ -57,9 +52,6 @@ const INCREMENTABLE_UNITS = ['second', 'minute', 'hour'];
57
52
  function canIncrement(unit = 'second') {
58
53
  return INCREMENTABLE_UNITS.includes(unit);
59
54
  }
60
- function verifyProps(updateIntervalInSeconds, unit) {
61
- invariant(!updateIntervalInSeconds || (updateIntervalInSeconds && canIncrement(unit)), 'Cannot schedule update with unit longer than hour');
62
- }
63
55
  export class FormattedRelativeTime extends React.PureComponent {
64
56
  constructor(props) {
65
57
  super(props);
@@ -72,7 +64,8 @@ export class FormattedRelativeTime extends React.PureComponent {
72
64
  ? valueToSeconds(this.props.value, this.props.unit)
73
65
  : 0,
74
66
  };
75
- verifyProps(props.updateIntervalInSeconds, props.unit);
67
+ invariant(!props.updateIntervalInSeconds ||
68
+ !!(props.updateIntervalInSeconds && canIncrement(props.unit)), 'Cannot schedule update with unit longer than hour');
76
69
  }
77
70
  scheduleNextUpdate({ updateIntervalInSeconds, unit }, { currentValueInSeconds }) {
78
71
  clearTimeout(this._updateTimer);
@@ -21,14 +21,14 @@ const DATE_TIME_FORMAT_OPTIONS = [
21
21
  ];
22
22
  export function getFormatter({ locale, formats, onError, timeZone, }, type, getDateTimeFormat, options = {}) {
23
23
  const { format } = options;
24
- const defaults = Object.assign({}, (timeZone && { timeZone }), (format && getNamedFormat(formats, type, format, onError)));
24
+ const defaults = Object.assign(Object.assign({}, (timeZone && { timeZone })), (format && getNamedFormat(formats, type, format, onError)));
25
25
  let filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults);
26
26
  if (type === 'time' &&
27
27
  !filteredOptions.hour &&
28
28
  !filteredOptions.minute &&
29
29
  !filteredOptions.second) {
30
30
  // Add default formatting options if hour, minute, or second isn't defined.
31
- filteredOptions = Object.assign({}, filteredOptions, { hour: 'numeric', minute: 'numeric' });
31
+ filteredOptions = Object.assign(Object.assign({}, filteredOptions), { hour: 'numeric', minute: 'numeric' });
32
32
  }
33
33
  return getDateTimeFormat(locale, filteredOptions);
34
34
  }
@@ -1,3 +1,2 @@
1
- import * as React from 'react';
2
1
  import { IntlConfig, Formatters, IntlFormatters } from '../types';
3
- export declare function formatList({ locale, onError }: Pick<IntlConfig, 'locale' | 'onError'>, getListFormat: Formatters['getListFormat'], values: Parameters<IntlFormatters['formatList']>[0], options?: Parameters<IntlFormatters['formatList']>[1]): string | React.ReactNode;
2
+ export declare function formatList({ locale, onError }: Pick<IntlConfig, 'locale' | 'onError'>, getListFormat: Formatters['getListFormat'], values: Array<string>, options: Parameters<IntlFormatters['formatList']>[1]): string;
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Formatters, IntlConfig, MessageDescriptor } from '../types';
3
3
  import { PrimitiveType } from 'intl-messageformat';
4
+ export declare const prepareIntlMessageFormatHtmlOutput: (chunks: (string | object)[]) => 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>)>;
4
5
  export declare function formatMessage({ locale, formats, messages, defaultLocale, defaultFormats, onError, }: Pick<IntlConfig, 'locale' | 'formats' | 'messages' | 'defaultLocale' | 'defaultFormats' | 'onError'>, state: Formatters, messageDescriptor?: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
5
6
  export declare function formatHTMLMessage(config: Pick<IntlConfig, 'locale' | 'formats' | 'messages' | 'defaultLocale' | 'defaultFormats' | 'onError'>, state: Formatters, messageDescriptor?: MessageDescriptor, rawValues?: Record<string, PrimitiveType>): React.ReactNode;
@@ -3,12 +3,8 @@
3
3
  * Copyrights licensed under the New BSD License.
4
4
  * See the accompanying LICENSE file for terms.
5
5
  */
6
- // Since rollup cannot deal with namespace being a function,
7
- // this is to interop with TypeScript since `invariant`
8
- // does not export a default
9
- // https://github.com/rollup/rollup/issues/1267
10
- import * as invariant_ from 'invariant';
11
- const invariant = invariant_.default || invariant_;
6
+ import * as React from 'react';
7
+ import { invariant } from '@formatjs/intl-utils';
12
8
  import { createError, escape } from '../utils';
13
9
  import IntlMessageFormat from 'intl-messageformat';
14
10
  function setTimeZoneInOptions(opts, timeZone) {
@@ -18,9 +14,9 @@ function setTimeZoneInOptions(opts, timeZone) {
18
14
  }, {});
19
15
  }
20
16
  function deepMergeOptions(opts1, opts2) {
21
- const keys = Object.keys(Object.assign({}, opts1, opts2));
17
+ const keys = Object.keys(Object.assign(Object.assign({}, opts1), opts2));
22
18
  return keys.reduce((all, k) => {
23
- all[k] = Object.assign({}, (opts1[k] || {}), (opts2[k] || {}));
19
+ all[k] = Object.assign(Object.assign({}, (opts1[k] || {})), (opts2[k] || {}));
24
20
  return all;
25
21
  }, {});
26
22
  }
@@ -29,16 +25,14 @@ function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
29
25
  return f1;
30
26
  }
31
27
  const mfFormats = IntlMessageFormat.formats;
32
- return Object.assign({}, mfFormats, f1, { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
28
+ return Object.assign(Object.assign(Object.assign({}, mfFormats), f1), { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
33
29
  }
30
+ export const prepareIntlMessageFormatHtmlOutput = (chunks) => React.createElement(React.Fragment, null, ...chunks);
34
31
  export function formatMessage({ locale, formats, messages, defaultLocale, defaultFormats, onError, timeZone, }, state, messageDescriptor = { id: '' }, values = {}) {
35
32
  const { id, defaultMessage } = messageDescriptor;
36
33
  // `id` is a required field of a Message Descriptor.
37
- invariant(id, '[React Intl] An `id` must be provided to format a message.');
38
- if (!id) {
39
- throw new Error('[React Intl] An `id` must be provided to format a message.');
40
- }
41
- const message = messages && messages[id];
34
+ invariant(!!id, '[React Intl] An `id` must be provided to format a message.');
35
+ const message = messages && messages[String(id)];
42
36
  formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
43
37
  defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
44
38
  let formattedMessageParts = [];
@@ -77,15 +71,15 @@ export function formatMessage({ locale, formats, messages, defaultLocale, defaul
77
71
  onError(createError(`Cannot format message: "${id}", ` +
78
72
  `using message ${message || defaultMessage ? 'source' : 'id'} as fallback.`));
79
73
  if (typeof message === 'string') {
80
- return message || defaultMessage || id;
74
+ return message || defaultMessage || String(id);
81
75
  }
82
- return defaultMessage || id;
76
+ return defaultMessage || String(id);
83
77
  }
84
78
  if (formattedMessageParts.length === 1 &&
85
79
  typeof formattedMessageParts[0] === 'string') {
86
- return formattedMessageParts[0] || defaultMessage || id;
80
+ return formattedMessageParts[0] || defaultMessage || String(id);
87
81
  }
88
- return formattedMessageParts;
82
+ return prepareIntlMessageFormatHtmlOutput(formattedMessageParts);
89
83
  }
90
84
  export function formatHTMLMessage(config, state, messageDescriptor = { id: '' }, rawValues = {}) {
91
85
  // Process all the values before they are used when formatting the ICU
package/lib/index.d.ts CHANGED
@@ -19,11 +19,11 @@ export declare const FormattedNumber: React.FC<UnifiedNumberFormatOptions & Cust
19
19
  export declare const FormattedList: React.FC<IntlListFormatOptions & {
20
20
  value: React.ReactNode[];
21
21
  }>;
22
- export declare const FormattedDateParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
22
+ export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
23
23
  value: string | number | Date | undefined;
24
24
  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;
25
25
  }>;
26
- export declare const FormattedTimeParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
26
+ export declare const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
27
27
  value: string | number | Date | undefined;
28
28
  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;
29
29
  }>;
@@ -46,7 +46,7 @@ export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & Custom
46
46
  value: string | number | Date | undefined;
47
47
  }>;
48
48
 
49
- export declare const FormattedDateParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
49
+ export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
50
50
  value: string | number | Date | undefined;
51
51
  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;
52
52
  }>;
@@ -82,7 +82,7 @@ export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] &
82
82
  children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
83
83
  }>;
84
84
 
85
- export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "type" | "format" | "value"> & {
85
+ export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
86
86
  forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
87
87
  } & React.RefAttributes<any>> & {
88
88
  WrappedComponent: React.ComponentType<Props_2>;
@@ -106,7 +106,7 @@ export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & Custom
106
106
  value: string | number | Date | undefined;
107
107
  }>;
108
108
 
109
- export declare const FormattedTimeParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
109
+ export declare const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
110
110
  value: string | number | Date | undefined;
111
111
  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;
112
112
  }>;
@@ -169,6 +169,7 @@ export declare interface IntlFormatters {
169
169
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
170
170
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn>): string | React.ReactNodeArray;
171
171
  formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
172
+ formatList(values: Array<string>, opts?: FormatListOptions): string;
172
173
  formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
173
174
  }
174
175
 
@@ -186,7 +187,7 @@ export declare interface IntlShape extends IntlConfig, IntlFormatters {
186
187
  }
187
188
 
188
189
  export declare interface MessageDescriptor {
189
- id?: string;
190
+ id?: string | number;
190
191
  description?: string | object;
191
192
  defaultMessage?: string;
192
193
  }
@@ -226,7 +227,7 @@ declare interface Props_3<V extends Record<string, any> = Record<string, React.R
226
227
  children?(...nodes: React.ReactNodeArray): React.ReactNode;
227
228
  }
228
229
 
229
- export declare const RawIntlProvider: React.ProviderExoticComponent<React.ProviderProps<IntlShape>>;
230
+ export declare const RawIntlProvider: React.Provider<IntlShape>;
230
231
 
231
232
  declare interface State {
232
233
  /**
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.6.2"
8
+ "packageVersion": "7.7.1"
9
9
  }
10
10
  ]
11
11
  }
package/lib/types.d.ts CHANGED
@@ -37,6 +37,7 @@ export interface IntlFormatters {
37
37
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
38
38
  formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn>): string | React.ReactNodeArray;
39
39
  formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
40
+ formatList(values: Array<string>, opts?: FormatListOptions): string;
40
41
  formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
41
42
  }
42
43
  export interface Formatters {
@@ -59,7 +60,7 @@ export interface IntlCache {
59
60
  list: Record<string, IntlListFormat>;
60
61
  }
61
62
  export interface MessageDescriptor {
62
- id?: string;
63
+ id?: string | number;
63
64
  description?: string | object;
64
65
  defaultMessage?: string;
65
66
  }
package/lib/utils.d.ts CHANGED
@@ -2,7 +2,7 @@ import { IntlConfig, IntlCache, CustomFormats, Formatters } from './types';
2
2
  import { IntlRelativeTimeFormatOptions } from '@formatjs/intl-relativetimeformat';
3
3
  export declare function escape(str: string): string;
4
4
  export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, whitelist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
5
- export declare function invariantIntlContext(intl?: any): void;
5
+ export declare function invariantIntlContext(intl?: any): asserts intl;
6
6
  export declare function createError(message: string, exception?: Error): string;
7
7
  export declare function defaultErrorHandler(error: string): void;
8
8
  export declare const DEFAULT_INTL_CONFIG: Pick<IntlConfig, 'formats' | 'messages' | 'timeZone' | 'textComponent' | 'defaultLocale' | 'defaultFormats' | 'onError'>;
package/lib/utils.js CHANGED
@@ -11,12 +11,7 @@ file in the root directory of React's source tree.
11
11
  import * as React from 'react';
12
12
  import IntlMessageFormat from 'intl-messageformat';
13
13
  import memoizeIntlConstructor from 'intl-format-cache';
14
- // Since rollup cannot deal with namespace being a function,
15
- // this is to interop with TypeScript since `invariant`
16
- // does not export a default
17
- // https://github.com/rollup/rollup/issues/1267
18
- import * as invariant_ from 'invariant';
19
- const invariant = invariant_.default || invariant_;
14
+ import { invariant } from '@formatjs/intl-utils';
20
15
  const ESCAPED_CHARS = {
21
16
  38: '&amp;',
22
17
  62: '&gt;',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intl",
3
- "version": "3.9.1",
3
+ "version": "3.11.0",
4
4
  "description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.",
5
5
  "keywords": [
6
6
  "intl",
@@ -131,49 +131,49 @@
131
131
  "types": "./lib/react-intl.d.ts",
132
132
  "sideEffects": false,
133
133
  "dependencies": {
134
- "@formatjs/intl-listformat": "^1.3.1",
135
- "@formatjs/intl-relativetimeformat": "^4.5.1",
136
- "@formatjs/intl-unified-numberformat": "^2.2.0",
134
+ "@formatjs/intl-listformat": "^1.3.7",
135
+ "@formatjs/intl-relativetimeformat": "^4.5.7",
136
+ "@formatjs/intl-unified-numberformat": "^3.0.4",
137
+ "@formatjs/intl-utils": "^2.0.4",
137
138
  "@formatjs/macro": "^0.2.6",
138
139
  "@types/hoist-non-react-statics": "^3.3.1",
139
- "@types/invariant": "^2.2.30",
140
+ "@types/invariant": "^2.2.31",
140
141
  "hoist-non-react-statics": "^3.3.1",
141
- "intl-format-cache": "^4.2.13",
142
+ "intl-format-cache": "^4.2.19",
142
143
  "intl-locales-supported": "^1.8.4",
143
- "intl-messageformat": "^7.7.0",
144
- "intl-messageformat-parser": "^3.5.0",
145
- "invariant": "^2.1.1",
146
- "shallow-equal": "^1.1.0"
144
+ "intl-messageformat": "^7.8.2",
145
+ "intl-messageformat-parser": "^3.6.2",
146
+ "shallow-equal": "^1.2.1"
147
147
  },
148
148
  "peerDependencies": {
149
149
  "react": "^16.3.0"
150
150
  },
151
151
  "devDependencies": {
152
- "@babel/core": "^7.7.4",
153
- "@babel/node": "^7.7.4",
152
+ "@babel/core": "^7.7.7",
153
+ "@babel/node": "^7.7.7",
154
154
  "@babel/plugin-proposal-class-properties": "^7.7.4",
155
- "@babel/plugin-transform-modules-commonjs": "^7.7.4",
156
- "@babel/preset-env": "^7.7.4",
155
+ "@babel/plugin-transform-modules-commonjs": "^7.7.5",
156
+ "@babel/preset-env": "^7.7.7",
157
157
  "@babel/preset-react": "^7.7.4",
158
- "@formatjs/intl-pluralrules": "^1.3.9",
159
- "@microsoft/api-documenter": "^7.7.0",
160
- "@microsoft/api-extractor": "^7.6.2",
158
+ "@formatjs/intl-pluralrules": "^1.5.0",
159
+ "@microsoft/api-documenter": "^7.7.3",
160
+ "@microsoft/api-extractor": "^7.7.1",
161
161
  "@types/benchmark": "^1.0.31",
162
- "@types/enzyme": "^3.10.3",
163
- "@types/jest": "^24.0.23",
162
+ "@types/enzyme": "^3.10.4",
163
+ "@types/jest": "^24.0.25",
164
164
  "@types/prop-types": "^15.7.3",
165
- "@types/react": "^16.9.13",
165
+ "@types/react": "^16.9.17",
166
166
  "@types/react-dom": "^16.9.4",
167
- "@typescript-eslint/eslint-plugin": "^2.9.0",
168
- "@typescript-eslint/parser": "^2.9.0",
167
+ "@typescript-eslint/eslint-plugin": "^2.15.0",
168
+ "@typescript-eslint/parser": "^2.15.0",
169
169
  "babel-jest": "^24.9.0",
170
170
  "benchmark": "^2.1.0",
171
- "core-js": "^3.4.5",
171
+ "core-js": "^3.6.2",
172
172
  "cross-env": "^6.0.3",
173
- "enzyme": "^3.6.0",
174
- "enzyme-adapter-react-16": "^1.15.1",
173
+ "enzyme": "^3.11.0",
174
+ "enzyme-adapter-react-16": "^1.15.2",
175
175
  "enzyme-to-json": "^3.4.3",
176
- "eslint": "^6.7.2",
176
+ "eslint": "^6.8.0",
177
177
  "eslint-plugin-react": "^7.17.0",
178
178
  "fs-extra": "^8.1.0",
179
179
  "full-icu": "^1.3.0",
@@ -187,18 +187,18 @@
187
187
  "react": "^16.12.0",
188
188
  "react-dom": "^16.12.0",
189
189
  "rimraf": "^3.0.0",
190
- "rollup": "^1.27.8",
190
+ "rollup": "^1.29.0",
191
191
  "rollup-plugin-babel": "^4.3.3",
192
192
  "rollup-plugin-commonjs": "^10.1.0",
193
193
  "rollup-plugin-node-resolve": "^5.2.0",
194
194
  "rollup-plugin-replace": "^2.0.0",
195
- "rollup-plugin-typescript2": "^0.25.0",
196
- "rollup-plugin-uglify": "^6.0.3",
195
+ "rollup-plugin-typescript2": "^0.25.3",
196
+ "rollup-plugin-uglify": "^6.0.4",
197
197
  "standard-version": "^7.0.1",
198
- "ts-jest": "^24.2.0",
198
+ "ts-jest": "^24.3.0",
199
199
  "ts-node": "^8.5.4",
200
200
  "tslib": "^1.9.3",
201
- "typescript": "~3.3.0"
201
+ "typescript": "^3.7.0"
202
202
  },
203
203
  "scripts": {
204
204
  "benchmark": "cross-env NODE_ENV=production TS_NODE_PROJECT=./tsconfig.cjs.json ts-node test/perf/index.tsx",
@@ -178,6 +178,6 @@ export default class IntlProvider extends React.PureComponent<
178
178
 
179
179
  render(): JSX.Element {
180
180
  invariantIntlContext(this.state.intl);
181
- return <Provider value={this.state.intl!}>{this.props.children}</Provider>;
181
+ return <Provider value={this.state.intl}>{this.props.children}</Provider>;
182
182
  }
183
183
  }
@@ -8,13 +8,7 @@ import {Context} from './injectIntl';
8
8
  import {FormatRelativeTimeOptions} from '../types';
9
9
  import {Unit} from '@formatjs/intl-relativetimeformat';
10
10
  import {invariantIntlContext} from '../utils';
11
-
12
- // Since rollup cannot deal with namespace being a function,
13
- // this is to interop with TypeScript since `invariant`
14
- // does not export a default
15
- // https://github.com/rollup/rollup/issues/1267
16
- import * as invariant_ from 'invariant';
17
- const invariant: typeof invariant_ = (invariant_ as any).default || invariant_;
11
+ import {invariant} from '@formatjs/intl-utils';
18
12
  const MINUTE = 60;
19
13
  const HOUR = 60 * 60;
20
14
  const DAY = 60 * 60 * 24;
@@ -82,13 +76,6 @@ function canIncrement(unit: Unit = 'second'): boolean {
82
76
  return INCREMENTABLE_UNITS.includes(unit);
83
77
  }
84
78
 
85
- function verifyProps(updateIntervalInSeconds?: number, unit?: Unit): void {
86
- invariant(
87
- !updateIntervalInSeconds || (updateIntervalInSeconds && canIncrement(unit)),
88
- 'Cannot schedule update with unit longer than hour'
89
- );
90
- }
91
-
92
79
  export class FormattedRelativeTime extends React.PureComponent<Props, State> {
93
80
  // Public for testing
94
81
  _updateTimer: any = null;
@@ -107,7 +94,11 @@ export class FormattedRelativeTime extends React.PureComponent<Props, State> {
107
94
 
108
95
  constructor(props: Props) {
109
96
  super(props);
110
- verifyProps(props.updateIntervalInSeconds, props.unit);
97
+ invariant(
98
+ !props.updateIntervalInSeconds ||
99
+ !!(props.updateIntervalInSeconds && canIncrement(props.unit)),
100
+ 'Cannot schedule update with unit longer than hour'
101
+ );
111
102
  }
112
103
 
113
104
  scheduleNextUpdate(
@@ -15,12 +15,18 @@ function generateToken(i: number): string {
15
15
  return `${now}_${i}_${now}`;
16
16
  }
17
17
 
18
+ export function formatList(
19
+ {locale, onError}: Pick<IntlConfig, 'locale' | 'onError'>,
20
+ getListFormat: Formatters['getListFormat'],
21
+ values: Array<string>,
22
+ options: Parameters<IntlFormatters['formatList']>[1]
23
+ ): string;
18
24
  export function formatList(
19
25
  {locale, onError}: Pick<IntlConfig, 'locale' | 'onError'>,
20
26
  getListFormat: Formatters['getListFormat'],
21
27
  values: Parameters<IntlFormatters['formatList']>[0],
22
28
  options: Parameters<IntlFormatters['formatList']>[1] = {}
23
- ): string | React.ReactNode {
29
+ ): React.ReactNode {
24
30
  const ListFormat: typeof IntlListFormat = (Intl as any).ListFormat;
25
31
  if (!ListFormat) {
26
32
  onError(