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.
- package/CHANGELOG.md +28 -0
- package/dist/components/createFormattedComponent.js +4 -2
- package/dist/components/html-message.js +1 -1
- package/dist/components/injectIntl.d.ts +1 -1
- package/dist/components/message.js +13 -4
- package/dist/components/plural.d.ts +1 -1
- package/dist/components/provider.js +2 -2
- package/dist/components/relative.js +3 -10
- package/dist/formatters/dateTime.js +2 -2
- package/dist/formatters/list.d.ts +1 -2
- package/dist/formatters/message.d.ts +1 -0
- package/dist/formatters/message.js +19 -18
- package/dist/index.d.ts +2 -2
- package/dist/react-intl.api.md +7 -5
- package/dist/react-intl.d.ts +30 -9
- package/dist/react-intl.js +563 -386
- package/dist/react-intl.js.map +1 -1
- package/dist/react-intl.min.js +1 -1
- package/dist/react-intl.min.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +2 -7
- package/lib/components/createFormattedComponent.js +4 -2
- package/lib/components/html-message.js +1 -1
- package/lib/components/injectIntl.d.ts +1 -1
- package/lib/components/message.js +5 -3
- package/lib/components/plural.d.ts +1 -1
- package/lib/components/provider.js +2 -2
- package/lib/components/relative.js +3 -10
- package/lib/formatters/dateTime.js +2 -2
- package/lib/formatters/list.d.ts +1 -2
- package/lib/formatters/message.d.ts +1 -0
- package/lib/formatters/message.js +12 -18
- package/lib/index.d.ts +2 -2
- package/lib/react-intl.d.ts +6 -5
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +2 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +1 -6
- package/package.json +31 -31
- package/src/components/provider.tsx +1 -1
- package/src/components/relative.tsx +6 -15
- package/src/formatters/list.ts +7 -1
- package/src/formatters/message.ts +13 -18
- package/src/types.ts +5 -1
- package/src/utils.ts +2 -7
|
@@ -5,12 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as React from 'react';
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
+
|
|
206
|
+
return prepareIntlMessageFormatHtmlOutput(formattedMessageParts);
|
|
212
207
|
}
|
|
213
208
|
|
|
214
209
|
export function formatHTMLMessage(
|
package/src/types.ts
CHANGED
|
@@ -107,6 +107,10 @@ export interface IntlFormatters {
|
|
|
107
107
|
descriptor: MessageDescriptor,
|
|
108
108
|
values?: Record<string, PrimitiveType>
|
|
109
109
|
): React.ReactNode;
|
|
110
|
+
formatList(
|
|
111
|
+
values: Array<string>,
|
|
112
|
+
opts?: FormatListOptions
|
|
113
|
+
): string;
|
|
110
114
|
formatList(
|
|
111
115
|
values: Array<string | React.ReactNode>,
|
|
112
116
|
opts?: FormatListOptions
|
|
@@ -148,7 +152,7 @@ export interface IntlCache {
|
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
export interface MessageDescriptor {
|
|
151
|
-
id?: string;
|
|
155
|
+
id?: string | number;
|
|
152
156
|
description?: string | object;
|
|
153
157
|
defaultMessage?: string;
|
|
154
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
|
-
|
|
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: '&',
|
|
@@ -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):
|
|
52
|
+
export function invariantIntlContext(intl?: any): asserts intl {
|
|
58
53
|
invariant(
|
|
59
54
|
intl,
|
|
60
55
|
'[React Intl] Could not find required `intl` object. ' +
|