react-intl 4.2.2 → 4.5.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/README.md +1 -1
- package/dist/components/createFormattedComponent.js +3 -1
- package/dist/components/injectIntl.js +2 -3
- package/dist/components/message.d.ts +1 -1
- package/dist/error.d.ts +4 -2
- package/dist/error.js +2 -1
- package/dist/formatters/message.js +4 -4
- package/dist/formatters/relativeTime.js +1 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/react-intl.api.md +42 -35
- package/dist/react-intl.d.ts +72 -59
- package/dist/react-intl.js +74 -31
- 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 -2
- package/lib/components/createFormattedComponent.js +3 -1
- package/lib/components/injectIntl.js +2 -3
- package/lib/components/message.d.ts +1 -1
- package/lib/error.d.ts +4 -2
- package/lib/error.js +2 -1
- package/lib/formatters/message.js +4 -4
- package/lib/formatters/relativeTime.js +1 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/lib/react-intl.d.ts +51 -47
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +2 -2
- package/package.json +32 -39
- package/src/components/createFormattedComponent.tsx +50 -48
- package/src/components/injectIntl.tsx +33 -34
- package/src/components/message.tsx +33 -32
- package/src/components/plural.tsx +22 -22
- package/src/components/provider.tsx +36 -36
- package/src/components/relative.tsx +70 -70
- package/src/components/useIntl.ts +7 -7
- package/src/error.ts +26 -13
- package/src/formatters/dateTime.ts +25 -33
- package/src/formatters/displayName.ts +11 -11
- package/src/formatters/list.ts +29 -29
- package/src/formatters/message.ts +47 -50
- package/src/formatters/number.ts +15 -15
- package/src/formatters/plural.ts +10 -10
- package/src/formatters/relativeTime.ts +18 -19
- package/src/index.ts +49 -36
- package/src/tsconfig.cjs.json +8 -8
- package/src/tsconfig.json +7 -7
- package/src/types.ts +59 -59
- package/src/utils.ts +29 -24
- package/src/vendor.d.ts +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare type FormatRelativeTimeOptions = Exclude<IntlRelativeTimeFormatOp
|
|
|
29
29
|
export declare type FormatPluralOptions = Exclude<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
30
30
|
export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;
|
|
31
31
|
export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
|
|
32
|
-
export interface IntlFormatters<T = React.ReactNode> {
|
|
32
|
+
export interface IntlFormatters<T = React.ReactNode, R = T> {
|
|
33
33
|
formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
34
34
|
formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
35
35
|
formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
|
|
@@ -39,7 +39,7 @@ export interface IntlFormatters<T = React.ReactNode> {
|
|
|
39
39
|
formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
|
|
40
40
|
formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
|
|
41
41
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
42
|
-
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
|
|
42
|
+
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T, R>>): string | React.ReactNodeArray;
|
|
43
43
|
formatList(values: Array<string>, opts?: FormatListOptions): string;
|
|
44
44
|
formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
|
|
45
45
|
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
|
|
@@ -51,7 +51,9 @@ export function createFormattedDateTimePartsComponent(name) {
|
|
|
51
51
|
export function createFormattedComponent(name) {
|
|
52
52
|
const Component = props => (React.createElement(Context.Consumer, null, (intl) => {
|
|
53
53
|
invariantIntlContext(intl);
|
|
54
|
-
const { value, children } = props, formatProps = __rest(props
|
|
54
|
+
const { value, children } = props, formatProps = __rest(props
|
|
55
|
+
// TODO: fix TS type definition for localeMatcher upstream
|
|
56
|
+
, ["value", "children"]);
|
|
55
57
|
// TODO: fix TS type definition for localeMatcher upstream
|
|
56
58
|
const formattedValue = intl[name](value, formatProps);
|
|
57
59
|
if (typeof children === 'function') {
|
|
@@ -20,9 +20,8 @@ export default function injectIntl(WrappedComponent, options) {
|
|
|
20
20
|
if (enforceContext) {
|
|
21
21
|
invariantIntlContext(intl);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}, { ref: forwardRef ? props.forwardedRef : null })));
|
|
23
|
+
const intlProp = { [intlPropName]: intl };
|
|
24
|
+
return (React.createElement(WrappedComponent, Object.assign({}, props, intlProp, { ref: forwardRef ? props.forwardedRef : null })));
|
|
26
25
|
}));
|
|
27
26
|
WithIntl.displayName = `injectIntl(${getDisplayName(WrappedComponent)})`;
|
|
28
27
|
WithIntl.WrappedComponent = WrappedComponent;
|
|
@@ -6,7 +6,7 @@ export interface Props<V extends Record<string, any> = Record<string, React.Reac
|
|
|
6
6
|
tagName?: React.ElementType<any>;
|
|
7
7
|
children?(...nodes: React.ReactNodeArray): React.ReactNode;
|
|
8
8
|
}
|
|
9
|
-
declare class FormattedMessage<
|
|
9
|
+
declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<React.ReactNode, React.ReactNode>>> extends React.Component<Props<V>> {
|
|
10
10
|
static displayName: string;
|
|
11
11
|
static defaultProps: {
|
|
12
12
|
values: {};
|
package/lib/error.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageDescriptor } from './types';
|
|
1
2
|
export declare const enum ReactIntlErrorCode {
|
|
2
3
|
FORMAT_ERROR = "FORMAT_ERROR",
|
|
3
4
|
UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
|
|
@@ -6,6 +7,7 @@ export declare const enum ReactIntlErrorCode {
|
|
|
6
7
|
MISSING_TRANSLATION = "MISSING_TRANSLATION"
|
|
7
8
|
}
|
|
8
9
|
export declare class ReactIntlError extends Error {
|
|
9
|
-
code: ReactIntlErrorCode;
|
|
10
|
-
|
|
10
|
+
readonly code: ReactIntlErrorCode;
|
|
11
|
+
readonly descriptor?: MessageDescriptor;
|
|
12
|
+
constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error);
|
|
11
13
|
}
|
package/lib/error.js
CHANGED
|
@@ -7,9 +7,10 @@ export var ReactIntlErrorCode;
|
|
|
7
7
|
ReactIntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
|
|
8
8
|
})(ReactIntlErrorCode || (ReactIntlErrorCode = {}));
|
|
9
9
|
export class ReactIntlError extends Error {
|
|
10
|
-
constructor(code, message, exception) {
|
|
10
|
+
constructor(code, message, descriptor, exception) {
|
|
11
11
|
super(`[React Intl Error ${code}] ${message} ${exception ? `\n${exception.stack}` : ''}`);
|
|
12
12
|
this.code = code;
|
|
13
|
+
this.descriptor = descriptor;
|
|
13
14
|
if (typeof Error.captureStackTrace === 'function') {
|
|
14
15
|
Error.captureStackTrace(this, ReactIntlError);
|
|
15
16
|
}
|
|
@@ -47,7 +47,7 @@ export function formatMessage({ locale, formats, messages, defaultLocale, defaul
|
|
|
47
47
|
}
|
|
48
48
|
catch (e) {
|
|
49
49
|
onError(new ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, `Error formatting message: "${id}" for locale: "${locale}"` +
|
|
50
|
-
(defaultMessage ? ', using default message as fallback.' : ''), e));
|
|
50
|
+
(defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor, e));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
else if (!defaultMessage ||
|
|
@@ -56,7 +56,7 @@ export function formatMessage({ locale, formats, messages, defaultLocale, defaul
|
|
|
56
56
|
// when no `messages` are passed into the <IntlProvider> for the
|
|
57
57
|
// default locale.
|
|
58
58
|
onError(new ReactIntlError("MISSING_TRANSLATION" /* MISSING_TRANSLATION */, `Missing message: "${id}" for locale: "${locale}"` +
|
|
59
|
-
(defaultMessage ? ', using default message as fallback.' : '')));
|
|
59
|
+
(defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor));
|
|
60
60
|
}
|
|
61
61
|
if (!formattedMessageParts && defaultMessage) {
|
|
62
62
|
try {
|
|
@@ -64,12 +64,12 @@ export function formatMessage({ locale, formats, messages, defaultLocale, defaul
|
|
|
64
64
|
formattedMessageParts = formatter.format(values);
|
|
65
65
|
}
|
|
66
66
|
catch (e) {
|
|
67
|
-
onError(new ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, `Error formatting the default message for: "${id}"`, e));
|
|
67
|
+
onError(new ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, `Error formatting the default message for: "${id}"`, messageDescriptor, e));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
if (!formattedMessageParts) {
|
|
71
71
|
onError(new ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, `Cannot format message: "${id}", ` +
|
|
72
|
-
`using message ${message || defaultMessage ? 'source' : 'id'} as fallback
|
|
72
|
+
`using message ${message || defaultMessage ? 'source' : 'id'} as fallback.`, messageDescriptor));
|
|
73
73
|
if (typeof message === 'string') {
|
|
74
74
|
return message || defaultMessage || String(id);
|
|
75
75
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { getNamedFormat, filterProps } from '../utils';
|
|
2
2
|
import { FormatError } from 'intl-messageformat';
|
|
3
3
|
import { ReactIntlError } from '../error';
|
|
4
|
-
const RELATIVE_TIME_FORMAT_OPTIONS = [
|
|
5
|
-
'numeric',
|
|
6
|
-
'style',
|
|
7
|
-
];
|
|
4
|
+
const RELATIVE_TIME_FORMAT_OPTIONS = ['numeric', 'style'];
|
|
8
5
|
function getFormatter({ locale, formats, onError, }, getRelativeTimeFormat, options = {}) {
|
|
9
6
|
const { format } = options;
|
|
10
7
|
const defaults = (!!format && getNamedFormat(formats, 'relative', format, onError)) || {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export declare function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
|
|
4
|
+
export declare function defineMessage<T>(msg: T): T;
|
|
4
5
|
import { CustomFormatConfig } from './types';
|
|
5
6
|
import { UnifiedNumberFormatOptions } from '@formatjs/intl-unified-numberformat';
|
|
6
7
|
import { IntlListFormatOptions } from '@formatjs/intl-listformat';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export function defineMessages(msgs) {
|
|
2
2
|
return msgs;
|
|
3
3
|
}
|
|
4
|
+
export function defineMessage(msg) {
|
|
5
|
+
return msg;
|
|
6
|
+
}
|
|
4
7
|
import { createFormattedComponent, createFormattedDateTimePartsComponent, } from './components/createFormattedComponent';
|
|
5
8
|
export { default as injectIntl, Provider as RawIntlProvider, Context as IntlContext, } from './components/injectIntl';
|
|
6
9
|
export { default as useIntl } from './components/useIntl';
|
package/lib/react-intl.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import IntlRelativeTimeFormat from '@formatjs/intl-relativetimeformat';
|
|
|
11
11
|
import { IntlRelativeTimeFormatOptions } from '@formatjs/intl-relativetimeformat';
|
|
12
12
|
import { MessageFormatElement } from 'intl-messageformat-parser';
|
|
13
13
|
import { PrimitiveType } from 'intl-messageformat';
|
|
14
|
-
import * as
|
|
14
|
+
import * as React_2 from 'react';
|
|
15
15
|
import { UnifiedNumberFormatOptions } from '@formatjs/intl-unified-numberformat';
|
|
16
16
|
import { Unit } from '@formatjs/intl-relativetimeformat';
|
|
17
17
|
|
|
@@ -34,6 +34,8 @@ export declare interface CustomFormats extends Partial<Formats> {
|
|
|
34
34
|
|
|
35
35
|
declare const DEFAULT_INTL_CONFIG: Pick<IntlConfig, 'formats' | 'messages' | 'timeZone' | 'textComponent' | 'defaultLocale' | 'defaultFormats' | 'onError'>;
|
|
36
36
|
|
|
37
|
+
export declare function defineMessage<T>(msg: T): T;
|
|
38
|
+
|
|
37
39
|
export declare function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
|
|
38
40
|
|
|
39
41
|
export declare type FormatDateOptions = Exclude<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
@@ -48,24 +50,24 @@ export declare type FormatPluralOptions = Exclude<Intl.PluralRulesOptions, 'loca
|
|
|
48
50
|
|
|
49
51
|
export declare type FormatRelativeTimeOptions = Exclude<IntlRelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
50
52
|
|
|
51
|
-
export declare const FormattedDate:
|
|
53
|
+
export declare const FormattedDate: React_2.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
52
54
|
value: string | number | Date | undefined;
|
|
53
55
|
}>;
|
|
54
56
|
|
|
55
|
-
export declare const FormattedDateParts:
|
|
57
|
+
export declare const FormattedDateParts: React_2.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
56
58
|
value: string | number | Date | undefined;
|
|
57
|
-
children(val: Intl.DateTimeFormatPart[]):
|
|
59
|
+
children(val: Intl.DateTimeFormatPart[]): React_2.ReactElement<any, string | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, any>)> | null;
|
|
58
60
|
}>;
|
|
59
61
|
|
|
60
|
-
export declare const FormattedDisplayName:
|
|
62
|
+
export declare const FormattedDisplayName: React_2.FC<DisplayNamesOptions_2 & {
|
|
61
63
|
value: string | number | object;
|
|
62
64
|
}>;
|
|
63
65
|
|
|
64
|
-
export declare const FormattedList:
|
|
65
|
-
value:
|
|
66
|
+
export declare const FormattedList: React_2.FC<IntlListFormatOptions & {
|
|
67
|
+
value: React_2.ReactNode[];
|
|
66
68
|
}>;
|
|
67
69
|
|
|
68
|
-
export declare class FormattedMessage<
|
|
70
|
+
export declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React_2.ReactElement | FormatXMLElementFn<React_2.ReactNode, React_2.ReactNode>>> extends React_2.Component<Props_3<V>> {
|
|
69
71
|
static displayName: string;
|
|
70
72
|
static defaultProps: {
|
|
71
73
|
values: {};
|
|
@@ -74,22 +76,22 @@ export declare class FormattedMessage<T = React.ReactNode, V extends Record<stri
|
|
|
74
76
|
render(): JSX.Element;
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
export declare const FormattedNumber:
|
|
79
|
+
export declare const FormattedNumber: React_2.FC<UnifiedNumberFormatOptions & CustomFormatConfig & {
|
|
78
80
|
value: number;
|
|
79
81
|
}>;
|
|
80
82
|
|
|
81
|
-
export declare const FormattedNumberParts:
|
|
83
|
+
export declare const FormattedNumberParts: React_2.FC<Formatter['formatNumber'] & {
|
|
82
84
|
value: Parameters<IntlShape['formatNumber']>[0];
|
|
83
|
-
children(val: Intl.NumberFormatPart[]):
|
|
85
|
+
children(val: Intl.NumberFormatPart[]): React_2.ReactElement | null;
|
|
84
86
|
}>;
|
|
85
87
|
|
|
86
|
-
export declare const FormattedPlural:
|
|
87
|
-
forwardedRef?: ((instance: any) => void) |
|
|
88
|
-
} &
|
|
89
|
-
WrappedComponent:
|
|
88
|
+
export declare const FormattedPlural: React_2.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
|
|
89
|
+
forwardedRef?: ((instance: any) => void) | React_2.RefObject<any> | null | undefined;
|
|
90
|
+
} & React_2.RefAttributes<any>> & {
|
|
91
|
+
WrappedComponent: React_2.ComponentType<Props_2>;
|
|
90
92
|
};
|
|
91
93
|
|
|
92
|
-
export declare class FormattedRelativeTime extends
|
|
94
|
+
export declare class FormattedRelativeTime extends React_2.PureComponent<Props, State_2> {
|
|
93
95
|
_updateTimer: any;
|
|
94
96
|
static displayName: string;
|
|
95
97
|
static defaultProps: Pick<Props, 'unit' | 'value'>;
|
|
@@ -103,13 +105,13 @@ export declare class FormattedRelativeTime extends React.PureComponent<Props, St
|
|
|
103
105
|
render(): JSX.Element;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
export declare const FormattedTime:
|
|
108
|
+
export declare const FormattedTime: React_2.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
107
109
|
value: string | number | Date | undefined;
|
|
108
110
|
}>;
|
|
109
111
|
|
|
110
|
-
export declare const FormattedTimeParts:
|
|
112
|
+
export declare const FormattedTimeParts: React_2.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
111
113
|
value: string | number | Date | undefined;
|
|
112
|
-
children(val: Intl.DateTimeFormatPart[]):
|
|
114
|
+
children(val: Intl.DateTimeFormatPart[]): React_2.ReactElement<any, string | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, any>)> | null;
|
|
113
115
|
}>;
|
|
114
116
|
|
|
115
117
|
declare type Formatter = {
|
|
@@ -130,12 +132,12 @@ export declare interface Formatters {
|
|
|
130
132
|
getDisplayNames(...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
|
|
131
133
|
}
|
|
132
134
|
|
|
133
|
-
export declare function injectIntl<IntlPropName extends string, P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>>(WrappedComponent:
|
|
134
|
-
WrappedComponent:
|
|
135
|
+
export declare function injectIntl<IntlPropName extends string, P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>>(WrappedComponent: React_2.ComponentType<P>, options?: Opts<IntlPropName, false>): React_2.FC<WithIntlProps<P>> & {
|
|
136
|
+
WrappedComponent: React_2.ComponentType<P>;
|
|
135
137
|
};
|
|
136
138
|
|
|
137
|
-
export declare function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>, T extends
|
|
138
|
-
WrappedComponent:
|
|
139
|
+
export declare function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>, T extends React_2.ComponentType<P> = any>(WrappedComponent: React_2.ComponentType<P>, options?: Opts<IntlPropName, true>): React_2.ForwardRefExoticComponent<React_2.PropsWithoutRef<WithIntlProps<P>> & React_2.RefAttributes<T>> & {
|
|
140
|
+
WrappedComponent: React_2.ComponentType<P>;
|
|
139
141
|
};
|
|
140
142
|
|
|
141
143
|
export declare interface IntlCache {
|
|
@@ -152,7 +154,7 @@ export declare interface IntlConfig {
|
|
|
152
154
|
locale: string;
|
|
153
155
|
timeZone?: string;
|
|
154
156
|
formats: CustomFormats;
|
|
155
|
-
textComponent?:
|
|
157
|
+
textComponent?: React_2.ComponentType | keyof React_2.ReactHTML;
|
|
156
158
|
messages: Record<string, string> | Record<string, MessageFormatElement[]>;
|
|
157
159
|
defaultLocale: string;
|
|
158
160
|
defaultFormats: CustomFormats;
|
|
@@ -160,9 +162,9 @@ export declare interface IntlConfig {
|
|
|
160
162
|
onError(err: ReactIntlError | FormatError): void;
|
|
161
163
|
}
|
|
162
164
|
|
|
163
|
-
export declare const IntlContext:
|
|
165
|
+
export declare const IntlContext: React_2.Context<IntlShape>;
|
|
164
166
|
|
|
165
|
-
export declare interface IntlFormatters<T =
|
|
167
|
+
export declare interface IntlFormatters<T = React_2.ReactNode, R = T> {
|
|
166
168
|
formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
167
169
|
formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
168
170
|
formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
|
|
@@ -172,13 +174,13 @@ export declare interface IntlFormatters<T = React.ReactNode> {
|
|
|
172
174
|
formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
|
|
173
175
|
formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
|
|
174
176
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
175
|
-
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType |
|
|
177
|
+
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React_2.ReactElement | FormatXMLElementFn<T, R>>): string | React_2.ReactNodeArray;
|
|
176
178
|
formatList(values: Array<string>, opts?: FormatListOptions): string;
|
|
177
|
-
formatList(values: Array<string |
|
|
179
|
+
formatList(values: Array<string | React_2.ReactNode>, opts?: FormatListOptions): React_2.ReactNode;
|
|
178
180
|
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
|
|
179
181
|
}
|
|
180
182
|
|
|
181
|
-
export declare class IntlProvider extends
|
|
183
|
+
export declare class IntlProvider extends React_2.PureComponent<OptionalIntlConfig, State> {
|
|
182
184
|
static displayName: string;
|
|
183
185
|
static defaultProps: Pick<IntlConfig, "formats" | "messages" | "timeZone" | "textComponent" | "defaultLocale" | "defaultFormats" | "onError">;
|
|
184
186
|
private cache;
|
|
@@ -197,9 +199,10 @@ export declare interface MessageDescriptor {
|
|
|
197
199
|
defaultMessage?: string;
|
|
198
200
|
}
|
|
199
201
|
|
|
200
|
-
|
|
202
|
+
declare type Omit_2<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
|
|
203
|
+
export { Omit_2 as Omit }
|
|
201
204
|
|
|
202
|
-
declare type OptionalIntlConfig =
|
|
205
|
+
declare type OptionalIntlConfig = Omit_2<IntlConfig, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
|
|
203
206
|
|
|
204
207
|
declare interface Opts<IntlPropName extends string = 'intl', ForwardRef extends boolean = false> {
|
|
205
208
|
intlPropName?: IntlPropName;
|
|
@@ -211,32 +214,33 @@ declare interface Props extends FormatRelativeTimeOptions {
|
|
|
211
214
|
value?: number;
|
|
212
215
|
unit?: Unit;
|
|
213
216
|
updateIntervalInSeconds?: number;
|
|
214
|
-
children?(value: string):
|
|
217
|
+
children?(value: string): React_2.ReactChild;
|
|
215
218
|
}
|
|
216
219
|
|
|
217
220
|
declare interface Props_2 extends FormatPluralOptions {
|
|
218
221
|
value: number;
|
|
219
222
|
intl: IntlShape;
|
|
220
|
-
other:
|
|
221
|
-
zero?:
|
|
222
|
-
one?:
|
|
223
|
-
two?:
|
|
224
|
-
few?:
|
|
225
|
-
many?:
|
|
226
|
-
children?(value:
|
|
223
|
+
other: React_2.ReactNode;
|
|
224
|
+
zero?: React_2.ReactNode;
|
|
225
|
+
one?: React_2.ReactNode;
|
|
226
|
+
two?: React_2.ReactNode;
|
|
227
|
+
few?: React_2.ReactNode;
|
|
228
|
+
many?: React_2.ReactNode;
|
|
229
|
+
children?(value: React_2.ReactNode): React_2.ReactElement | null;
|
|
227
230
|
}
|
|
228
231
|
|
|
229
|
-
declare interface Props_3<V extends Record<string, any> = Record<string,
|
|
232
|
+
declare interface Props_3<V extends Record<string, any> = Record<string, React_2.ReactNode>> extends MessageDescriptor {
|
|
230
233
|
values?: V;
|
|
231
|
-
tagName?:
|
|
232
|
-
children?(...nodes:
|
|
234
|
+
tagName?: React_2.ElementType<any>;
|
|
235
|
+
children?(...nodes: React_2.ReactNodeArray): React_2.ReactNode;
|
|
233
236
|
}
|
|
234
237
|
|
|
235
|
-
export declare const RawIntlProvider:
|
|
238
|
+
export declare const RawIntlProvider: React_2.Provider<IntlShape>;
|
|
236
239
|
|
|
237
240
|
export declare class ReactIntlError extends Error {
|
|
238
|
-
code: ReactIntlErrorCode;
|
|
239
|
-
|
|
241
|
+
readonly code: ReactIntlErrorCode;
|
|
242
|
+
readonly descriptor?: MessageDescriptor;
|
|
243
|
+
constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error);
|
|
240
244
|
}
|
|
241
245
|
|
|
242
246
|
export declare const enum ReactIntlErrorCode {
|
|
@@ -272,8 +276,8 @@ declare interface State_2 {
|
|
|
272
276
|
|
|
273
277
|
export declare function useIntl(): IntlShape;
|
|
274
278
|
|
|
275
|
-
export declare type WithIntlProps<P> =
|
|
276
|
-
forwardedRef?:
|
|
279
|
+
export declare type WithIntlProps<P> = Omit_2<P, keyof WrappedComponentProps> & {
|
|
280
|
+
forwardedRef?: React_2.Ref<any>;
|
|
277
281
|
};
|
|
278
282
|
|
|
279
283
|
export declare type WrappedComponentProps<IntlPropName extends string = 'intl'> = {
|
package/lib/tsdoc-metadata.json
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare type FormatRelativeTimeOptions = Exclude<IntlRelativeTimeFormatOp
|
|
|
29
29
|
export declare type FormatPluralOptions = Exclude<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
30
30
|
export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;
|
|
31
31
|
export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
|
|
32
|
-
export interface IntlFormatters<T = React.ReactNode> {
|
|
32
|
+
export interface IntlFormatters<T = React.ReactNode, R = T> {
|
|
33
33
|
formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
34
34
|
formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
35
35
|
formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
|
|
@@ -39,7 +39,7 @@ export interface IntlFormatters<T = React.ReactNode> {
|
|
|
39
39
|
formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
|
|
40
40
|
formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
|
|
41
41
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
42
|
-
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
|
|
42
|
+
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T, R>>): string | React.ReactNodeArray;
|
|
43
43
|
formatList(values: Array<string>, opts?: FormatListOptions): string;
|
|
44
44
|
formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
|
|
45
45
|
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intl",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.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,17 +131,17 @@
|
|
|
131
131
|
"types": "./lib/react-intl.d.ts",
|
|
132
132
|
"sideEffects": false,
|
|
133
133
|
"dependencies": {
|
|
134
|
-
"@formatjs/intl-displaynames": "^1.2.
|
|
135
|
-
"@formatjs/intl-listformat": "^1.4.
|
|
136
|
-
"@formatjs/intl-relativetimeformat": "^4.5.
|
|
137
|
-
"@formatjs/intl-unified-numberformat": "^3.3.
|
|
138
|
-
"@formatjs/intl-utils": "^2.2.
|
|
134
|
+
"@formatjs/intl-displaynames": "^1.2.5",
|
|
135
|
+
"@formatjs/intl-listformat": "^1.4.4",
|
|
136
|
+
"@formatjs/intl-relativetimeformat": "^4.5.12",
|
|
137
|
+
"@formatjs/intl-unified-numberformat": "^3.3.3",
|
|
138
|
+
"@formatjs/intl-utils": "^2.2.2",
|
|
139
139
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
140
140
|
"@types/invariant": "^2.2.31",
|
|
141
141
|
"hoist-non-react-statics": "^3.3.2",
|
|
142
|
-
"intl-format-cache": "^4.2.
|
|
143
|
-
"intl-messageformat": "^8.
|
|
144
|
-
"intl-messageformat-parser": "^
|
|
142
|
+
"intl-format-cache": "^4.2.24",
|
|
143
|
+
"intl-messageformat": "^8.3.7",
|
|
144
|
+
"intl-messageformat-parser": "^5.0.0",
|
|
145
145
|
"shallow-equal": "^1.2.1"
|
|
146
146
|
},
|
|
147
147
|
"peerDependencies": {
|
|
@@ -152,52 +152,48 @@
|
|
|
152
152
|
"@babel/node": "^7.8.7",
|
|
153
153
|
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
|
154
154
|
"@babel/plugin-transform-modules-commonjs": "^7.9.0",
|
|
155
|
-
"@babel/preset-env": "^7.9.
|
|
156
|
-
"@babel/preset-react": "^7.9.
|
|
157
|
-
"@formatjs/intl-pluralrules": "^1.5.
|
|
158
|
-
"@microsoft/api-documenter": "^7.7.
|
|
159
|
-
"@microsoft/api-extractor": "^7.7.
|
|
155
|
+
"@babel/preset-env": "^7.9.5",
|
|
156
|
+
"@babel/preset-react": "^7.9.4",
|
|
157
|
+
"@formatjs/intl-pluralrules": "^1.5.5",
|
|
158
|
+
"@microsoft/api-documenter": "^7.7.18",
|
|
159
|
+
"@microsoft/api-extractor": "^7.7.13",
|
|
160
160
|
"@types/benchmark": "^1.0.31",
|
|
161
161
|
"@types/enzyme": "^3.10.5",
|
|
162
|
-
"@types/jest": "^25.1
|
|
162
|
+
"@types/jest": "^25.2.1",
|
|
163
163
|
"@types/prop-types": "^15.7.3",
|
|
164
|
-
"@types/react": "^16.9.
|
|
165
|
-
"@types/react-dom": "^16.9.
|
|
166
|
-
"
|
|
167
|
-
"@typescript-eslint/parser": "^2.24.0",
|
|
168
|
-
"babel-jest": "^25.1.0",
|
|
164
|
+
"@types/react": "^16.9.34",
|
|
165
|
+
"@types/react-dom": "^16.9.6",
|
|
166
|
+
"babel-jest": "^25.4.0",
|
|
169
167
|
"benchmark": "^2.1.4",
|
|
170
|
-
"core-js": "^3.6.
|
|
168
|
+
"core-js": "^3.6.5",
|
|
171
169
|
"cross-env": "^7.0.2",
|
|
172
170
|
"enzyme": "^3.11.0",
|
|
173
171
|
"enzyme-adapter-react-16": "^1.15.2",
|
|
174
172
|
"enzyme-to-json": "^3.4.4",
|
|
175
|
-
"eslint": "^6.8.0",
|
|
176
|
-
"eslint-plugin-react": "^7.19.0",
|
|
177
173
|
"fs-extra": "^9.0.0",
|
|
178
174
|
"full-icu": "^1.3.1",
|
|
179
175
|
"glob": "^7.1.6",
|
|
180
|
-
"jest": "^25.
|
|
176
|
+
"jest": "^25.4.0",
|
|
181
177
|
"markdown-toc": "^1.2.0",
|
|
182
|
-
"mkdirp": "^1.0.
|
|
178
|
+
"mkdirp": "^1.0.4",
|
|
183
179
|
"parcel": "^1.12.4",
|
|
184
180
|
"pre-commit": "^1.2.2",
|
|
185
|
-
"prettier": "^
|
|
181
|
+
"prettier": "^2.0.0",
|
|
186
182
|
"react": "^16.13.1",
|
|
187
183
|
"react-dom": "^16.13.1",
|
|
188
184
|
"rimraf": "^3.0.2",
|
|
189
|
-
"rollup": "^2.1
|
|
185
|
+
"rollup": "^2.6.1",
|
|
190
186
|
"rollup-plugin-babel": "^4.4.0",
|
|
191
187
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
192
188
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
193
189
|
"rollup-plugin-replace": "^2.2.0",
|
|
194
|
-
"rollup-plugin-typescript2": "^0.
|
|
190
|
+
"rollup-plugin-typescript2": "^0.27.0",
|
|
195
191
|
"rollup-plugin-uglify": "^6.0.4",
|
|
196
192
|
"standard-version": "^7.1.0",
|
|
197
|
-
"ts-jest": "^25.
|
|
198
|
-
"ts-node": "^8.
|
|
193
|
+
"ts-jest": "^25.4.0",
|
|
194
|
+
"ts-node": "^8.8.2",
|
|
199
195
|
"tslib": "^1.11.1",
|
|
200
|
-
"typescript": "
|
|
196
|
+
"typescript": "3.8"
|
|
201
197
|
},
|
|
202
198
|
"scripts": {
|
|
203
199
|
"benchmark": "cross-env NODE_ENV=production TS_NODE_PROJECT=./tsconfig.cjs.json ts-node test/perf/index.tsx",
|
|
@@ -209,14 +205,12 @@
|
|
|
209
205
|
"build": "npm run build:lib && npm run build:dts && npm run build:dist",
|
|
210
206
|
"clean": "rimraf coverage/ dist/ lib/ core.js core.d.ts",
|
|
211
207
|
"example": "parcel examples/index.html",
|
|
212
|
-
"
|
|
213
|
-
"
|
|
214
|
-
"
|
|
215
|
-
"lint": "eslint src --ext .ts,.tsx",
|
|
216
|
-
"postchangelog": "npm run toc && npm run format:fix",
|
|
208
|
+
"prettier": "prettier --write \"{src,scripts,test,docs,examples}/**/*\"",
|
|
209
|
+
"prettier:check": "prettier \"{src,scripts,test,docs,examples}/**/*\" --check",
|
|
210
|
+
"postchangelog": "npm run toc && npm run prettier",
|
|
217
211
|
"prerelease": "npm run clean && npm run build && npm run test:all",
|
|
218
212
|
"release": "standard-version",
|
|
219
|
-
"test:all": "npm run
|
|
213
|
+
"test:all": "npm run prettier:check && npm run test",
|
|
220
214
|
"test:perf": "cross-env NODE_ENV=production babel-node test/perf",
|
|
221
215
|
"test:watch": "cross-env NODE_ICU_DATA=./node_modules/full-icu jest --watch",
|
|
222
216
|
"test": "cross-env TZ=UTC NODE_ICU_DATA=./node_modules/full-icu jest --coverage --verbose",
|
|
@@ -224,8 +218,7 @@
|
|
|
224
218
|
},
|
|
225
219
|
"pre-commit": [
|
|
226
220
|
"toc",
|
|
227
|
-
"
|
|
228
|
-
"lint:fix"
|
|
221
|
+
"prettier"
|
|
229
222
|
],
|
|
230
223
|
"browserslist": [
|
|
231
224
|
"ie 11"
|