react-intl 3.10.0 → 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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
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.11.0](https://github.com/formatjs/react-intl/compare/v3.10.0...v3.11.0) (2020-01-09)
6
+
7
+
8
+ ### Features
9
+
10
+ * Allow MessageDescriptor ID to be `number` ([#1553](https://github.com/formatjs/react-intl/issues/1553)) ([95298b2](https://github.com/formatjs/react-intl/commit/95298b2b5f09173258fe9648d49fc9fa1ad673fc))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * 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))
16
+ * update formatjs deps ([1745c21](https://github.com/formatjs/react-intl/commit/1745c21b9ae5e6443f1ad5209f77cc9cb6ad66eb))
17
+
5
18
  ## [3.10.0](https://github.com/formatjs/react-intl/compare/v3.9.2...v3.10.0) (2019-12-26)
6
19
 
7
20
 
@@ -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) {
@@ -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) {
@@ -44,17 +47,15 @@ function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
44
47
  var mfFormats = intl_messageformat_1.default.formats;
45
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) {
@@ -295,7 +295,7 @@ export interface MessageDescriptor {
295
295
  // (undocumented)
296
296
  description?: string | object;
297
297
  // (undocumented)
298
- id?: string;
298
+ id?: string | number;
299
299
  }
300
300
 
301
301
  // @public (undocumented)
@@ -441,12 +441,12 @@ declare interface LocationDetails {
441
441
  }
442
442
 
443
443
  export declare interface MessageDescriptor {
444
- id?: string;
444
+ id?: string | number;
445
445
  description?: string | object;
446
446
  defaultMessage?: string;
447
447
  }
448
448
 
449
- declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement;
449
+ declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement | PoundElement;
450
450
 
451
451
  declare type MessageFormatPart = LiteralPart_2 | ArgumentPart;
452
452
 
@@ -523,6 +523,11 @@ declare interface PluralOrSelectOption {
523
523
  location?: Location;
524
524
  }
525
525
 
526
+ declare interface PoundElement {
527
+ type: TYPE.pound;
528
+ location?: Location;
529
+ }
530
+
526
531
  declare type PrimitiveType = string | number | boolean | null | undefined | Date;
527
532
 
528
533
  declare interface Props extends FormatRelativeTimeOptions {
@@ -691,10 +696,16 @@ declare enum TYPE {
691
696
  /**
692
697
  * Variable w/ plural format
693
698
  */
694
- plural = 6
699
+ plural = 6,
700
+ /**
701
+ * Only possible within plural argument.
702
+ * This is the `#` symbol that will be substituted with the count.
703
+ */
704
+ pound = 7
695
705
  }
696
706
 
697
707
  declare type UnifiedNumberFormatOptions = Intl.NumberFormatOptions & NumberFormatDigitOptions & {
708
+ localeMatcher?: 'lookup' | 'best fit';
698
709
  style?: 'decimal' | 'percent' | 'currency' | 'unit';
699
710
  compactDisplay?: 'short' | 'long';
700
711
  currencyDisplay?: 'symbol' | 'code' | 'name' | 'narrowSymbol';