react-intl 3.9.2 → 3.12.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 (54) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/components/createFormattedComponent.d.ts +2 -1
  3. package/dist/components/createFormattedComponent.js +7 -2
  4. package/dist/components/html-message.js +1 -1
  5. package/dist/components/injectIntl.d.ts +1 -1
  6. package/dist/components/message.js +13 -4
  7. package/dist/components/plural.d.ts +1 -1
  8. package/dist/components/provider.js +3 -2
  9. package/dist/components/relative.js +3 -10
  10. package/dist/formatters/dateTime.js +2 -2
  11. package/dist/formatters/displayName.d.ts +2 -0
  12. package/dist/formatters/displayName.js +25 -0
  13. package/dist/formatters/message.d.ts +1 -0
  14. package/dist/formatters/message.js +19 -18
  15. package/dist/index.d.ts +6 -2
  16. package/dist/index.js +1 -0
  17. package/dist/react-intl.api.md +22 -5
  18. package/dist/react-intl.d.ts +42 -9
  19. package/dist/react-intl.js +595 -389
  20. package/dist/react-intl.js.map +1 -1
  21. package/dist/react-intl.min.js +1 -1
  22. package/dist/react-intl.min.js.map +1 -1
  23. package/dist/types.d.ts +6 -1
  24. package/dist/utils.d.ts +1 -1
  25. package/dist/utils.js +5 -7
  26. package/lib/components/createFormattedComponent.d.ts +2 -1
  27. package/lib/components/createFormattedComponent.js +7 -2
  28. package/lib/components/html-message.js +1 -1
  29. package/lib/components/injectIntl.d.ts +1 -1
  30. package/lib/components/message.js +5 -3
  31. package/lib/components/plural.d.ts +1 -1
  32. package/lib/components/provider.js +3 -2
  33. package/lib/components/relative.js +3 -10
  34. package/lib/formatters/dateTime.js +2 -2
  35. package/lib/formatters/displayName.d.ts +2 -0
  36. package/lib/formatters/displayName.js +22 -0
  37. package/lib/formatters/message.d.ts +1 -0
  38. package/lib/formatters/message.js +12 -18
  39. package/lib/index.d.ts +6 -2
  40. package/lib/index.js +1 -0
  41. package/lib/react-intl.d.ts +18 -5
  42. package/lib/tsdoc-metadata.json +1 -1
  43. package/lib/types.d.ts +6 -1
  44. package/lib/utils.d.ts +1 -1
  45. package/lib/utils.js +4 -6
  46. package/package.json +28 -27
  47. package/src/components/createFormattedComponent.tsx +5 -0
  48. package/src/components/provider.tsx +7 -1
  49. package/src/components/relative.tsx +6 -15
  50. package/src/formatters/displayName.ts +35 -0
  51. package/src/formatters/message.ts +13 -18
  52. package/src/index.ts +4 -0
  53. package/src/types.ts +16 -5
  54. package/src/utils.ts +5 -7
package/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
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
+ ## [3.12.0](https://github.com/formatjs/react-intl/compare/v3.11.0...v3.12.0) (2020-02-04)
6
+
7
+
8
+ ### Features
9
+
10
+ * add formatDisplayName and FormattedDisplayName ([#1567](https://github.com/formatjs/react-intl/issues/1567)) ([10bcbe2](https://github.com/formatjs/react-intl/commit/10bcbe2e7e92902d60810a7c00568d3043b09db3)), closes [#1547](https://github.com/formatjs/react-intl/issues/1547)
11
+
12
+ ## [3.11.0](https://github.com/formatjs/react-intl/compare/v3.10.0...v3.11.0) (2020-01-09)
13
+
14
+
15
+ ### Features
16
+
17
+ * Allow MessageDescriptor ID to be `number` ([#1553](https://github.com/formatjs/react-intl/issues/1553)) ([95298b2](https://github.com/formatjs/react-intl/commit/95298b2b5f09173258fe9648d49fc9fa1ad673fc))
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * add a parser for chunks emitted from formatHTMLMessage ([#1550](https://github.com/formatjs/react-intl/issues/1550)) ([8c3c5c7](https://github.com/formatjs/react-intl/commit/8c3c5c78afa16d605933c82571f3b92b15363c27))
23
+ * update formatjs deps ([1745c21](https://github.com/formatjs/react-intl/commit/1745c21b9ae5e6443f1ad5209f77cc9cb6ad66eb))
24
+
25
+ ## [3.10.0](https://github.com/formatjs/react-intl/compare/v3.9.2...v3.10.0) (2019-12-26)
26
+
27
+
28
+ ### Features
29
+
30
+ * Upgrade intl-unified-numberformat & TypeScript ([ddf411a](https://github.com/formatjs/react-intl/commit/ddf411a6089005671f3d1ab8d11e04564da0f2e7))
31
+
5
32
  ### [3.9.2](https://github.com/formatjs/react-intl/compare/v3.9.1...v3.9.2) (2019-12-10)
6
33
 
7
34
 
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react';
2
- import { IntlShape, FormatDateOptions, FormatNumberOptions, FormatListOptions } from '../types';
2
+ import { IntlShape, FormatDateOptions, FormatNumberOptions, FormatListOptions, FormatDisplayNameOptions } from '../types';
3
3
  declare type Formatter = {
4
4
  formatDate: FormatDateOptions;
5
5
  formatTime: FormatDateOptions;
6
6
  formatNumber: FormatNumberOptions;
7
7
  formatList: FormatListOptions;
8
+ formatDisplayName: FormatDisplayNameOptions;
8
9
  };
9
10
  export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] & {
10
11
  value: Parameters<IntlShape['formatNumber']>[0];
@@ -4,8 +4,10 @@ var __rest = (this && this.__rest) || function (s, e) {
4
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
5
  t[p] = s[p];
6
6
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
8
- t[p[i]] = s[p[i]];
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
9
11
  return t;
10
12
  };
11
13
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -18,6 +20,9 @@ var DisplayName;
18
20
  DisplayName["formatTime"] = "FormattedTime";
19
21
  DisplayName["formatNumber"] = "FormattedNumber";
20
22
  DisplayName["formatList"] = "FormattedList";
23
+ // Note that this DisplayName is the locale display name, not to be confused with
24
+ // the name of the enum, which is for React component display name in dev tools.
25
+ DisplayName["formatDisplayName"] = "FormattedDisplayName";
21
26
  })(DisplayName || (DisplayName = {}));
22
27
  var DisplayNameParts;
23
28
  (function (DisplayNameParts) {
@@ -69,7 +69,7 @@ var FormattedHTMLMessage = /** @class */ (function (_super) {
69
69
  }));
70
70
  };
71
71
  FormattedHTMLMessage.displayName = 'FormattedHTMLMessage';
72
- FormattedHTMLMessage.defaultProps = __assign({}, message_1.default.defaultProps, { tagName: 'span' });
72
+ FormattedHTMLMessage.defaultProps = __assign(__assign({}, message_1.default.defaultProps), { tagName: 'span' });
73
73
  return FormattedHTMLMessage;
74
74
  }(message_1.default));
75
75
  exports.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;
@@ -33,10 +33,19 @@ var __rest = (this && this.__rest) || function (s, e) {
33
33
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
34
34
  t[p] = s[p];
35
35
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
36
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
37
- t[p[i]] = s[p[i]];
36
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
37
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
38
+ t[p[i]] = s[p[i]];
39
+ }
38
40
  return t;
39
41
  };
42
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
43
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
44
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
45
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
46
+ r[k] = a[j];
47
+ return r;
48
+ };
40
49
  Object.defineProperty(exports, "__esModule", { value: true });
41
50
  var React = require("react");
42
51
  var injectIntl_1 = require("./injectIntl");
@@ -48,7 +57,7 @@ var defaultFormatMessage = function (descriptor, values) {
48
57
  if (process.env.NODE_ENV !== 'production') {
49
58
  console.error('[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry. Using default message as fallback.');
50
59
  }
51
- return message_1.formatMessage(__assign({}, utils_1.DEFAULT_INTL_CONFIG, { locale: 'en' }), utils_1.createFormatters(), descriptor, values);
60
+ return message_1.formatMessage(__assign(__assign({}, utils_1.DEFAULT_INTL_CONFIG), { locale: 'en' }), utils_1.createFormatters(), descriptor, values);
52
61
  };
53
62
  var FormattedMessage = /** @class */ (function (_super) {
54
63
  __extends(FormattedMessage, _super);
@@ -80,7 +89,7 @@ var FormattedMessage = /** @class */ (function (_super) {
80
89
  if (Component) {
81
90
  // Needs to use `createElement()` instead of JSX, otherwise React will
82
91
  // warn about a missing `key` prop with rich-text message formatting.
83
- return React.createElement.apply(React, [Component, null].concat(nodes));
92
+ return React.createElement.apply(React, __spreadArrays([Component, null], nodes));
84
93
  }
85
94
  return nodes;
86
95
  }));
@@ -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>;
@@ -40,6 +40,7 @@ var plural_1 = require("../formatters/plural");
40
40
  var message_1 = require("../formatters/message");
41
41
  var shallowEquals_ = require("shallow-equal/objects");
42
42
  var list_1 = require("../formatters/list");
43
+ var displayName_1 = require("../formatters/displayName");
43
44
  var shallowEquals = shallowEquals_.default || shallowEquals_;
44
45
  function processIntlConfig(config) {
45
46
  return {
@@ -60,7 +61,7 @@ function processIntlConfig(config) {
60
61
  */
61
62
  function createIntl(config, cache) {
62
63
  var formatters = utils_1.createFormatters(cache);
63
- var resolvedConfig = __assign({}, utils_1.DEFAULT_INTL_CONFIG, config);
64
+ var resolvedConfig = __assign(__assign({}, utils_1.DEFAULT_INTL_CONFIG), config);
64
65
  if (!resolvedConfig.locale ||
65
66
  !intl_locales_supported_1.default(resolvedConfig.locale)) {
66
67
  var locale = resolvedConfig.locale, defaultLocale = resolvedConfig.defaultLocale, onError = resolvedConfig.onError;
@@ -75,7 +76,7 @@ function createIntl(config, cache) {
75
76
  // each <FormattedMessage> contains a `defaultMessage` prop.
76
77
  resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
77
78
  }
78
- return __assign({}, resolvedConfig, { formatters: formatters, formatNumber: number_1.formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: number_1.formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: relativeTime_1.formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: dateTime_1.formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: dateTime_1.formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: dateTime_1.formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: dateTime_1.formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: plural_1.formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: message_1.formatMessage.bind(null, resolvedConfig, formatters), formatHTMLMessage: message_1.formatHTMLMessage.bind(null, resolvedConfig, formatters), formatList: list_1.formatList.bind(null, resolvedConfig, formatters.getListFormat) });
79
+ return __assign(__assign({}, resolvedConfig), { formatters: formatters, formatNumber: number_1.formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: number_1.formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: relativeTime_1.formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: dateTime_1.formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: dateTime_1.formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: dateTime_1.formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: dateTime_1.formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: plural_1.formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: message_1.formatMessage.bind(null, resolvedConfig, formatters), formatHTMLMessage: message_1.formatHTMLMessage.bind(null, resolvedConfig, formatters), formatList: list_1.formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: displayName_1.formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
79
80
  }
80
81
  exports.createIntl = createIntl;
81
82
  var IntlProvider = /** @class */ (function (_super) {
@@ -32,12 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  var React = require("react");
33
33
  var injectIntl_1 = require("./injectIntl");
34
34
  var utils_1 = require("../utils");
35
- // Since rollup cannot deal with namespace being a function,
36
- // this is to interop with TypeScript since `invariant`
37
- // does not export a default
38
- // https://github.com/rollup/rollup/issues/1267
39
- var invariant_ = require("invariant");
40
- var invariant = invariant_.default || invariant_;
35
+ var intl_utils_1 = require("@formatjs/intl-utils");
41
36
  var MINUTE = 60;
42
37
  var HOUR = 60 * 60;
43
38
  var DAY = 60 * 60 * 24;
@@ -84,9 +79,6 @@ function canIncrement(unit) {
84
79
  if (unit === void 0) { unit = 'second'; }
85
80
  return INCREMENTABLE_UNITS.includes(unit);
86
81
  }
87
- function verifyProps(updateIntervalInSeconds, unit) {
88
- invariant(!updateIntervalInSeconds || (updateIntervalInSeconds && canIncrement(unit)), 'Cannot schedule update with unit longer than hour');
89
- }
90
82
  var FormattedRelativeTime = /** @class */ (function (_super) {
91
83
  __extends(FormattedRelativeTime, _super);
92
84
  function FormattedRelativeTime(props) {
@@ -100,7 +92,8 @@ var FormattedRelativeTime = /** @class */ (function (_super) {
100
92
  ? valueToSeconds(_this.props.value, _this.props.unit)
101
93
  : 0,
102
94
  };
103
- verifyProps(props.updateIntervalInSeconds, props.unit);
95
+ intl_utils_1.invariant(!props.updateIntervalInSeconds ||
96
+ !!(props.updateIntervalInSeconds && canIncrement(props.unit)), 'Cannot schedule update with unit longer than hour');
104
97
  return _this;
105
98
  }
106
99
  FormattedRelativeTime.prototype.scheduleNextUpdate = function (_a, _b) {
@@ -36,14 +36,14 @@ function getFormatter(_a, type, getDateTimeFormat, options) {
36
36
  var locale = _a.locale, formats = _a.formats, onError = _a.onError, timeZone = _a.timeZone;
37
37
  if (options === void 0) { options = {}; }
38
38
  var format = options.format;
39
- var defaults = __assign({}, (timeZone && { timeZone: timeZone }), (format && utils_1.getNamedFormat(formats, type, format, onError)));
39
+ var defaults = __assign(__assign({}, (timeZone && { timeZone: timeZone })), (format && utils_1.getNamedFormat(formats, type, format, onError)));
40
40
  var filteredOptions = utils_1.filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults);
41
41
  if (type === 'time' &&
42
42
  !filteredOptions.hour &&
43
43
  !filteredOptions.minute &&
44
44
  !filteredOptions.second) {
45
45
  // Add default formatting options if hour, minute, or second isn't defined.
46
- filteredOptions = __assign({}, filteredOptions, { hour: 'numeric', minute: 'numeric' });
46
+ filteredOptions = __assign(__assign({}, filteredOptions), { hour: 'numeric', minute: 'numeric' });
47
47
  }
48
48
  return getDateTimeFormat(locale, filteredOptions);
49
49
  }
@@ -0,0 +1,2 @@
1
+ import { IntlConfig, Formatters, IntlFormatters } from '../types';
2
+ export declare function formatDisplayName({ locale, onError }: Pick<IntlConfig, 'locale' | 'onError'>, getDisplayNames: Formatters['getDisplayNames'], value: Parameters<IntlFormatters['formatDisplayName']>[0], options?: Parameters<IntlFormatters['formatDisplayName']>[1]): string | undefined;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var utils_1 = require("../utils");
4
+ var DISPLAY_NAMES_OPTONS = [
5
+ 'localeMatcher',
6
+ 'style',
7
+ 'type',
8
+ 'fallback',
9
+ ];
10
+ function formatDisplayName(_a, getDisplayNames, value, options) {
11
+ var locale = _a.locale, onError = _a.onError;
12
+ if (options === void 0) { options = {}; }
13
+ var DisplayNames = Intl.DisplayNames;
14
+ if (!DisplayNames) {
15
+ onError(utils_1.createError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n"));
16
+ }
17
+ var filteredOptions = utils_1.filterProps(options, DISPLAY_NAMES_OPTONS);
18
+ try {
19
+ return getDisplayNames(locale, filteredOptions).of(value);
20
+ }
21
+ catch (e) {
22
+ onError(utils_1.createError('Error formatting display name.', e));
23
+ }
24
+ }
25
+ exports.formatDisplayName = formatDisplayName;
@@ -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;
@@ -15,13 +15,16 @@ var __assign = (this && this.__assign) || function () {
15
15
  };
16
16
  return __assign.apply(this, arguments);
17
17
  };
18
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
19
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
20
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
21
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
22
+ r[k] = a[j];
23
+ return r;
24
+ };
18
25
  Object.defineProperty(exports, "__esModule", { value: true });
19
- // Since rollup cannot deal with namespace being a function,
20
- // this is to interop with TypeScript since `invariant`
21
- // does not export a default
22
- // https://github.com/rollup/rollup/issues/1267
23
- var invariant_ = require("invariant");
24
- var invariant = invariant_.default || invariant_;
26
+ var React = require("react");
27
+ var intl_utils_1 = require("@formatjs/intl-utils");
25
28
  var utils_1 = require("../utils");
26
29
  var intl_messageformat_1 = require("intl-messageformat");
27
30
  function setTimeZoneInOptions(opts, timeZone) {
@@ -31,9 +34,9 @@ function setTimeZoneInOptions(opts, timeZone) {
31
34
  }, {});
32
35
  }
33
36
  function deepMergeOptions(opts1, opts2) {
34
- var keys = Object.keys(__assign({}, opts1, opts2));
37
+ var keys = Object.keys(__assign(__assign({}, opts1), opts2));
35
38
  return keys.reduce(function (all, k) {
36
- all[k] = __assign({}, (opts1[k] || {}), (opts2[k] || {}));
39
+ all[k] = __assign(__assign({}, (opts1[k] || {})), (opts2[k] || {}));
37
40
  return all;
38
41
  }, {});
39
42
  }
@@ -42,19 +45,17 @@ function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
42
45
  return f1;
43
46
  }
44
47
  var mfFormats = intl_messageformat_1.default.formats;
45
- return __assign({}, mfFormats, f1, { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
48
+ return __assign(__assign(__assign({}, mfFormats), f1), { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
46
49
  }
50
+ exports.prepareIntlMessageFormatHtmlOutput = function (chunks) { return React.createElement.apply(React, __spreadArrays([React.Fragment, null], chunks)); };
47
51
  function formatMessage(_a, state, messageDescriptor, values) {
48
52
  var locale = _a.locale, formats = _a.formats, messages = _a.messages, defaultLocale = _a.defaultLocale, defaultFormats = _a.defaultFormats, onError = _a.onError, timeZone = _a.timeZone;
49
53
  if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; }
50
54
  if (values === void 0) { values = {}; }
51
55
  var id = messageDescriptor.id, defaultMessage = messageDescriptor.defaultMessage;
52
56
  // `id` is a required field of a Message Descriptor.
53
- invariant(id, '[React Intl] An `id` must be provided to format a message.');
54
- if (!id) {
55
- throw new Error('[React Intl] An `id` must be provided to format a message.');
56
- }
57
- var message = messages && messages[id];
57
+ intl_utils_1.invariant(!!id, '[React Intl] An `id` must be provided to format a message.');
58
+ var message = messages && messages[String(id)];
58
59
  formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
59
60
  defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
60
61
  var formattedMessageParts = [];
@@ -93,15 +94,15 @@ function formatMessage(_a, state, messageDescriptor, values) {
93
94
  onError(utils_1.createError("Cannot format message: \"" + id + "\", " +
94
95
  ("using message " + (message || defaultMessage ? 'source' : 'id') + " as fallback.")));
95
96
  if (typeof message === 'string') {
96
- return message || defaultMessage || id;
97
+ return message || defaultMessage || String(id);
97
98
  }
98
- return defaultMessage || id;
99
+ return defaultMessage || String(id);
99
100
  }
100
101
  if (formattedMessageParts.length === 1 &&
101
102
  typeof formattedMessageParts[0] === 'string') {
102
- return formattedMessageParts[0] || defaultMessage || id;
103
+ return formattedMessageParts[0] || defaultMessage || String(id);
103
104
  }
104
- return formattedMessageParts;
105
+ return exports.prepareIntlMessageFormatHtmlOutput(formattedMessageParts);
105
106
  }
106
107
  exports.formatMessage = formatMessage;
107
108
  function formatHTMLMessage(config, state, messageDescriptor, rawValues) {
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { defineMessages } from '@formatjs/macro';
4
4
  import { CustomFormatConfig } from './types';
5
5
  import { UnifiedNumberFormatOptions } from '@formatjs/intl-unified-numberformat';
6
6
  import { IntlListFormatOptions } from '@formatjs/intl-listformat';
7
+ import { DisplayNamesOptions } from '@formatjs/intl-displaynames/lib';
7
8
  export { default as injectIntl, Provider as RawIntlProvider, Context as IntlContext, WithIntlProps, WrappedComponentProps, } from './components/injectIntl';
8
9
  export { default as useIntl } from './components/useIntl';
9
10
  export { default as IntlProvider, createIntl } from './components/provider';
@@ -19,11 +20,14 @@ export declare const FormattedNumber: React.FC<UnifiedNumberFormatOptions & Cust
19
20
  export declare const FormattedList: React.FC<IntlListFormatOptions & {
20
21
  value: React.ReactNode[];
21
22
  }>;
22
- export declare const FormattedDateParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
23
+ export declare const FormattedDisplayName: React.FC<DisplayNamesOptions & {
24
+ value: string | number | object;
25
+ }>;
26
+ export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
23
27
  value: string | number | Date | undefined;
24
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;
25
29
  }>;
26
- export declare const FormattedTimeParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
30
+ export declare const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
27
31
  value: string | number | Date | undefined;
28
32
  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
33
  }>;
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ exports.FormattedDate = createFormattedComponent_1.createFormattedComponent('for
17
17
  exports.FormattedTime = createFormattedComponent_1.createFormattedComponent('formatTime');
18
18
  exports.FormattedNumber = createFormattedComponent_1.createFormattedComponent('formatNumber');
19
19
  exports.FormattedList = createFormattedComponent_1.createFormattedComponent('formatList');
20
+ exports.FormattedDisplayName = createFormattedComponent_1.createFormattedComponent('formatDisplayName');
20
21
  exports.FormattedDateParts = createFormattedComponent_1.createFormattedDateTimePartsComponent('formatDate');
21
22
  exports.FormattedTimeParts = createFormattedComponent_1.createFormattedDateTimePartsComponent('formatTime');
22
23
  var createFormattedComponent_2 = require("./components/createFormattedComponent");
@@ -4,6 +4,9 @@
4
4
 
5
5
  ```ts
6
6
 
7
+ import { DisplayNames } from '@formatjs/intl-displaynames';
8
+ import { DisplayNamesOptions } from '@formatjs/intl-displaynames';
9
+ import { DisplayNamesOptions as DisplayNamesOptions_2 } from '@formatjs/intl-displaynames/lib';
7
10
  import * as React from 'react';
8
11
 
9
12
  // Warning: (ae-forgotten-export) The symbol "OptionalIntlConfig" needs to be exported by the entry point index.d.ts
@@ -36,6 +39,9 @@ export function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
36
39
  // @public (undocumented)
37
40
  export type FormatDateOptions = Exclude<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
38
41
 
42
+ // @public (undocumented)
43
+ export type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
44
+
39
45
  // Warning: (ae-forgotten-export) The symbol "IntlListFormatOptions" needs to be exported by the entry point index.d.ts
40
46
  //
41
47
  // @public (undocumented)
@@ -58,11 +64,16 @@ export const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatCo
58
64
  }>;
59
65
 
60
66
  // @public (undocumented)
61
- export const FormattedDateParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
67
+ export const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
62
68
  value: string | number | Date | undefined;
63
69
  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;
64
70
  }>;
65
71
 
72
+ // @public (undocumented)
73
+ export const FormattedDisplayName: React.FC<DisplayNamesOptions_2 & {
74
+ value: string | number | object;
75
+ }>;
76
+
66
77
  // Warning: (ae-forgotten-export) The symbol "PrimitiveType" needs to be exported by the entry point index.d.ts
67
78
  //
68
79
  // @public (undocumented)
@@ -116,7 +127,7 @@ export const FormattedNumberParts: React.FC<Formatter['formatNumber'] & {
116
127
  // Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts
117
128
  //
118
129
  // @public (undocumented)
119
- export const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "type" | "format" | "value"> & {
130
+ export const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
120
131
  forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
121
132
  } & React.RefAttributes<any>> & {
122
133
  WrappedComponent: React.ComponentType<Props_2>;
@@ -156,7 +167,7 @@ export const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatCo
156
167
  }>;
157
168
 
158
169
  // @public (undocumented)
159
- export const FormattedTimeParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
170
+ export const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
160
171
  value: string | number | Date | undefined;
161
172
  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;
162
173
  }>;
@@ -165,6 +176,8 @@ export const FormattedTimeParts: React.FunctionComponent<Intl.DateTimeFormatOpti
165
176
  export interface Formatters {
166
177
  // (undocumented)
167
178
  getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
179
+ // (undocumented)
180
+ getDisplayNames(...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
168
181
  // Warning: (ae-forgotten-export) The symbol "ListFormat" needs to be exported by the entry point index.d.ts
169
182
  //
170
183
  // (undocumented)
@@ -200,6 +213,8 @@ export interface IntlCache {
200
213
  // (undocumented)
201
214
  dateTime: Record<string, Intl.DateTimeFormat>;
202
215
  // (undocumented)
216
+ displayNames: Record<string, DisplayNames>;
217
+ // (undocumented)
203
218
  list: Record<string, ListFormat>;
204
219
  // (undocumented)
205
220
  message: Record<string, IntlMessageFormat>;
@@ -243,6 +258,8 @@ export interface IntlFormatters {
243
258
  // (undocumented)
244
259
  formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
245
260
  // (undocumented)
261
+ formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
262
+ // (undocumented)
246
263
  formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
247
264
  // (undocumented)
248
265
  formatList(values: Array<string>, opts?: FormatListOptions): string;
@@ -295,14 +312,14 @@ export interface MessageDescriptor {
295
312
  // (undocumented)
296
313
  description?: string | object;
297
314
  // (undocumented)
298
- id?: string;
315
+ id?: string | number;
299
316
  }
300
317
 
301
318
  // @public (undocumented)
302
319
  export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
303
320
 
304
321
  // @public (undocumented)
305
- export const RawIntlProvider: React.ProviderExoticComponent<React.ProviderProps<IntlShape>>;
322
+ export const RawIntlProvider: React.Provider<IntlShape>;
306
323
 
307
324
  // @public (undocumented)
308
325
  export function useIntl(): IntlShape;
@@ -1,3 +1,6 @@
1
+ import { DisplayNames } from '@formatjs/intl-displaynames';
2
+ import { DisplayNamesOptions } from '@formatjs/intl-displaynames';
3
+ import { DisplayNamesOptions as DisplayNamesOptions_2 } from '@formatjs/intl-displaynames/lib';
1
4
  import * as React from 'react';
2
5
 
3
6
  declare type ArgumentElement = BaseElement<TYPE.argument>;
@@ -61,6 +64,8 @@ declare interface FieldData {
61
64
 
62
65
  export declare type FormatDateOptions = Exclude<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
63
66
 
67
+ export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
68
+
64
69
  export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;
65
70
 
66
71
  export declare type FormatNumberOptions = Exclude<UnifiedNumberFormatOptions, 'localeMatcher'> & CustomFormatConfig;
@@ -81,11 +86,15 @@ export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & Custom
81
86
  value: string | number | Date | undefined;
82
87
  }>;
83
88
 
84
- export declare const FormattedDateParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
89
+ export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
85
90
  value: string | number | Date | undefined;
86
91
  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;
87
92
  }>;
88
93
 
94
+ export declare const FormattedDisplayName: React.FC<DisplayNamesOptions_2 & {
95
+ value: string | number | object;
96
+ }>;
97
+
89
98
  export declare class FormattedHTMLMessage extends FormattedMessage<Record<string, PrimitiveType>> {
90
99
  static displayName: string;
91
100
  static defaultProps: {
@@ -117,7 +126,7 @@ export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] &
117
126
  children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
118
127
  }>;
119
128
 
120
- export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "type" | "format" | "value"> & {
129
+ export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
121
130
  forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
122
131
  } & React.RefAttributes<any>> & {
123
132
  WrappedComponent: React.ComponentType<Props_2>;
@@ -141,7 +150,7 @@ export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & Custom
141
150
  value: string | number | Date | undefined;
142
151
  }>;
143
152
 
144
- export declare const FormattedTimeParts: React.FunctionComponent<Intl.DateTimeFormatOptions & CustomFormatConfig & {
153
+ export declare const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
145
154
  value: string | number | Date | undefined;
146
155
  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;
147
156
  }>;
@@ -151,6 +160,7 @@ declare type Formatter = {
151
160
  formatTime: FormatDateOptions;
152
161
  formatNumber: FormatNumberOptions;
153
162
  formatList: FormatListOptions;
163
+ formatDisplayName: FormatDisplayNameOptions;
154
164
  };
155
165
 
156
166
  export declare interface Formatters {
@@ -160,6 +170,7 @@ export declare interface Formatters {
160
170
  getRelativeTimeFormat(...args: ConstructorParameters<typeof RelativeTimeFormat>): RelativeTimeFormat;
161
171
  getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
162
172
  getListFormat(...args: ConstructorParameters<typeof ListFormat>): ListFormat;
173
+ getDisplayNames(...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
163
174
  }
164
175
 
165
176
  declare interface Formatters_2 {
@@ -185,6 +196,7 @@ export declare interface IntlCache {
185
196
  relativeTime: Record<string, RelativeTimeFormat>;
186
197
  pluralRules: Record<string, Intl.PluralRules>;
187
198
  list: Record<string, ListFormat>;
199
+ displayNames: Record<string, DisplayNames>;
188
200
  }
189
201
 
190
202
  export declare interface IntlConfig {
@@ -214,6 +226,7 @@ export declare interface IntlFormatters {
214
226
  formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
215
227
  formatList(values: Array<string>, opts?: FormatListOptions): string;
216
228
  formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
229
+ formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
217
230
  }
218
231
 
219
232
  declare interface IntlListFormatOptions {
@@ -441,17 +454,25 @@ declare interface LocationDetails {
441
454
  }
442
455
 
443
456
  export declare interface MessageDescriptor {
444
- id?: string;
457
+ id?: string | number;
445
458
  description?: string | object;
446
459
  defaultMessage?: string;
447
460
  }
448
461
 
449
- declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement;
462
+ declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement | PoundElement;
450
463
 
451
464
  declare type MessageFormatPart = LiteralPart_2 | ArgumentPart;
452
465
 
453
466
  declare type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;
454
467
 
468
+ declare interface NumberFormatDigitOptions {
469
+ minimumIntegerDigits?: number;
470
+ minimumFractionDigits?: number;
471
+ maximumFractionDigits?: number;
472
+ minimumSignificantDigits?: number;
473
+ maximumSignificantDigits?: number;
474
+ }
475
+
455
476
  declare interface NumberSkeleton {
456
477
  type: SKELETON_TYPE.number;
457
478
  tokens: NumberSkeletonToken[];
@@ -515,6 +536,11 @@ declare interface PluralOrSelectOption {
515
536
  location?: Location;
516
537
  }
517
538
 
539
+ declare interface PoundElement {
540
+ type: TYPE.pound;
541
+ location?: Location;
542
+ }
543
+
518
544
  declare type PrimitiveType = string | number | boolean | null | undefined | Date;
519
545
 
520
546
  declare interface Props extends FormatRelativeTimeOptions {
@@ -542,7 +568,7 @@ declare interface Props_3<V extends Record<string, any> = Record<string, React.R
542
568
  children?(...nodes: React.ReactNodeArray): React.ReactNode;
543
569
  }
544
570
 
545
- export declare const RawIntlProvider: React.ProviderExoticComponent<React.ProviderProps<IntlShape>>;
571
+ export declare const RawIntlProvider: React.Provider<IntlShape>;
546
572
 
547
573
  declare type RelativeTimeData = {
548
574
  [u in LDMLPluralRule]?: string;
@@ -683,10 +709,17 @@ declare enum TYPE {
683
709
  /**
684
710
  * Variable w/ plural format
685
711
  */
686
- plural = 6
712
+ plural = 6,
713
+ /**
714
+ * Only possible within plural argument.
715
+ * This is the `#` symbol that will be substituted with the count.
716
+ */
717
+ pound = 7
687
718
  }
688
719
 
689
- declare interface UnifiedNumberFormatOptions extends Intl.NumberFormatOptions {
720
+ declare type UnifiedNumberFormatOptions = Intl.NumberFormatOptions & NumberFormatDigitOptions & {
721
+ localeMatcher?: 'lookup' | 'best fit';
722
+ style?: 'decimal' | 'percent' | 'currency' | 'unit';
690
723
  compactDisplay?: 'short' | 'long';
691
724
  currencyDisplay?: 'symbol' | 'code' | 'name' | 'narrowSymbol';
692
725
  currencySign?: 'standard' | 'accounting';
@@ -694,7 +727,7 @@ declare interface UnifiedNumberFormatOptions extends Intl.NumberFormatOptions {
694
727
  signDisplay?: 'auto' | 'always' | 'never' | 'exceptZero';
695
728
  unit?: Unit_2;
696
729
  unitDisplay?: 'long' | 'short' | 'narrow';
697
- }
730
+ };
698
731
 
699
732
  declare type Unit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
700
733