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/dist/types.d.ts CHANGED
@@ -60,7 +60,7 @@ export interface IntlCache {
60
60
  list: Record<string, IntlListFormat>;
61
61
  }
62
62
  export interface MessageDescriptor {
63
- id?: string;
63
+ id?: string | number;
64
64
  description?: string | object;
65
65
  defaultMessage?: string;
66
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;
@@ -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);
@@ -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) {
@@ -31,14 +27,12 @@ function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
31
27
  const mfFormats = IntlMessageFormat.formats;
32
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
@@ -187,7 +187,7 @@ export declare interface IntlShape extends IntlConfig, IntlFormatters {
187
187
  }
188
188
 
189
189
  export declare interface MessageDescriptor {
190
- id?: string;
190
+ id?: string | number;
191
191
  description?: string | object;
192
192
  defaultMessage?: string;
193
193
  }
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.7.0"
8
+ "packageVersion": "7.7.1"
9
9
  }
10
10
  ]
11
11
  }
package/lib/types.d.ts CHANGED
@@ -60,7 +60,7 @@ export interface IntlCache {
60
60
  list: Record<string, IntlListFormat>;
61
61
  }
62
62
  export interface MessageDescriptor {
63
- id?: string;
63
+ id?: string | number;
64
64
  description?: string | object;
65
65
  defaultMessage?: string;
66
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.10.0",
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,18 +131,18 @@
131
131
  "types": "./lib/react-intl.d.ts",
132
132
  "sideEffects": false,
133
133
  "dependencies": {
134
- "@formatjs/intl-listformat": "^1.3.2",
135
- "@formatjs/intl-relativetimeformat": "^4.5.2",
136
- "@formatjs/intl-unified-numberformat": "^3.0.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
140
  "@types/invariant": "^2.2.31",
140
141
  "hoist-non-react-statics": "^3.3.1",
141
- "intl-format-cache": "^4.2.14",
142
+ "intl-format-cache": "^4.2.19",
142
143
  "intl-locales-supported": "^1.8.4",
143
- "intl-messageformat": "^7.7.3",
144
- "intl-messageformat-parser": "^3.5.2",
145
- "invariant": "^2.1.1",
144
+ "intl-messageformat": "^7.8.2",
145
+ "intl-messageformat-parser": "^3.6.2",
146
146
  "shallow-equal": "^1.2.1"
147
147
  },
148
148
  "peerDependencies": {
@@ -155,20 +155,20 @@
155
155
  "@babel/plugin-transform-modules-commonjs": "^7.7.5",
156
156
  "@babel/preset-env": "^7.7.7",
157
157
  "@babel/preset-react": "^7.7.4",
158
- "@formatjs/intl-pluralrules": "^1.4.0",
159
- "@microsoft/api-documenter": "^7.7.2",
160
- "@microsoft/api-extractor": "^7.7.0",
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
162
  "@types/enzyme": "^3.10.4",
163
163
  "@types/jest": "^24.0.25",
164
164
  "@types/prop-types": "^15.7.3",
165
165
  "@types/react": "^16.9.17",
166
166
  "@types/react-dom": "^16.9.4",
167
- "@typescript-eslint/eslint-plugin": "^2.13.0",
168
- "@typescript-eslint/parser": "^2.13.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.6.1",
171
+ "core-js": "^3.6.2",
172
172
  "cross-env": "^6.0.3",
173
173
  "enzyme": "^3.11.0",
174
174
  "enzyme-adapter-react-16": "^1.15.2",
@@ -187,7 +187,7 @@
187
187
  "react": "^16.12.0",
188
188
  "react-dom": "^16.12.0",
189
189
  "rimraf": "^3.0.0",
190
- "rollup": "^1.27.14",
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",
@@ -195,7 +195,7 @@
195
195
  "rollup-plugin-typescript2": "^0.25.3",
196
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
201
  "typescript": "^3.7.0"
@@ -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(
@@ -5,12 +5,7 @@
5
5
  */
6
6
 
7
7
  import * as React from 'react';
8
- // Since rollup cannot deal with namespace being a function,
9
- // this is to interop with TypeScript since `invariant`
10
- // does not export a default
11
- // https://github.com/rollup/rollup/issues/1267
12
- import * as invariant_ from 'invariant';
13
- const invariant: typeof invariant_ = (invariant_ as any).default || invariant_;
8
+ import {invariant} from '@formatjs/intl-utils';
14
9
 
15
10
  import {
16
11
  Formatters,
@@ -77,6 +72,10 @@ function deepMergeFormatsAndSetTimeZone(
77
72
  };
78
73
  }
79
74
 
75
+ export const prepareIntlMessageFormatHtmlOutput = (
76
+ chunks: (string | object)[]
77
+ ): React.ReactElement => React.createElement(React.Fragment, null, ...chunks);
78
+
80
79
  export function formatMessage(
81
80
  {
82
81
  locale,
@@ -123,17 +122,12 @@ export function formatMessage(
123
122
  string,
124
123
  PrimitiveType | React.ReactElement | FormatXMLElementFn
125
124
  > = {}
126
- ): string | React.ReactNodeArray {
125
+ ): string | React.ReactNodeArray | React.ReactElement {
127
126
  const {id, defaultMessage} = messageDescriptor;
128
127
 
129
128
  // `id` is a required field of a Message Descriptor.
130
- invariant(id, '[React Intl] An `id` must be provided to format a message.');
131
- if (!id) {
132
- throw new Error(
133
- '[React Intl] An `id` must be provided to format a message.'
134
- );
135
- }
136
- const message = messages && messages[id];
129
+ invariant(!!id, '[React Intl] An `id` must be provided to format a message.');
130
+ const message = messages && messages[String(id)];
137
131
  formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
138
132
  defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
139
133
 
@@ -198,17 +192,18 @@ export function formatMessage(
198
192
  )
199
193
  );
200
194
  if (typeof message === 'string') {
201
- return message || defaultMessage || id;
195
+ return message || defaultMessage || String(id);
202
196
  }
203
- return defaultMessage || id;
197
+ return defaultMessage || String(id);
204
198
  }
205
199
  if (
206
200
  formattedMessageParts.length === 1 &&
207
201
  typeof formattedMessageParts[0] === 'string'
208
202
  ) {
209
- return (formattedMessageParts[0] as string) || defaultMessage || id;
203
+ return (formattedMessageParts[0] as string) || defaultMessage || String(id);
210
204
  }
211
- return formattedMessageParts;
205
+
206
+ return prepareIntlMessageFormatHtmlOutput(formattedMessageParts);
212
207
  }
213
208
 
214
209
  export function formatHTMLMessage(
package/src/types.ts CHANGED
@@ -152,7 +152,7 @@ export interface IntlCache {
152
152
  }
153
153
 
154
154
  export interface MessageDescriptor {
155
- id?: string;
155
+ id?: string | number;
156
156
  description?: string | object;
157
157
  defaultMessage?: string;
158
158
  }
package/src/utils.ts CHANGED
@@ -13,13 +13,8 @@ import {IntlConfig, IntlCache, CustomFormats, Formatters} from './types';
13
13
  import * as React from 'react';
14
14
  import IntlMessageFormat from 'intl-messageformat';
15
15
  import memoizeIntlConstructor from '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
- import * as invariant_ from 'invariant';
16
+ import {invariant} from '@formatjs/intl-utils'
21
17
  import {IntlRelativeTimeFormatOptions} from '@formatjs/intl-relativetimeformat';
22
- const invariant: typeof invariant_ = (invariant_ as any).default || invariant_;
23
18
 
24
19
  const ESCAPED_CHARS: Record<number, string> = {
25
20
  38: '&amp;',
@@ -54,7 +49,7 @@ export function filterProps<T extends Record<string, any>, K extends string>(
54
49
  }, {} as Pick<T, K>);
55
50
  }
56
51
 
57
- export function invariantIntlContext(intl?: any): void {
52
+ export function invariantIntlContext(intl?: any): asserts intl {
58
53
  invariant(
59
54
  intl,
60
55
  '[React Intl] Could not find required `intl` object. ' +