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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
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
|
+
|
|
18
|
+
## [3.10.0](https://github.com/formatjs/react-intl/compare/v3.9.2...v3.10.0) (2019-12-26)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* Upgrade intl-unified-numberformat & TypeScript ([ddf411a](https://github.com/formatjs/react-intl/commit/ddf411a6089005671f3d1ab8d11e04564da0f2e7))
|
|
24
|
+
|
|
25
|
+
### [3.9.2](https://github.com/formatjs/react-intl/compare/v3.9.1...v3.9.2) (2019-12-10)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* add type overload for formatList, fix [#1537](https://github.com/formatjs/react-intl/issues/1537) ([6629899](https://github.com/formatjs/react-intl/commit/662989973c8d08f7972a3ba75f70b19abc507bb9))
|
|
31
|
+
* fix list formatter generation types ([0e5f205](https://github.com/formatjs/react-intl/commit/0e5f2058d7cba2d886693e219f58366582f0a6ac))
|
|
32
|
+
|
|
5
33
|
### [3.9.1](https://github.com/formatjs/react-intl/compare/v3.9.0...v3.9.1) (2019-12-02)
|
|
6
34
|
|
|
7
35
|
|
|
@@ -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++)
|
|
8
|
-
|
|
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 });
|
|
@@ -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.
|
|
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++)
|
|
37
|
-
|
|
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]
|
|
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" | "
|
|
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>;
|
|
@@ -60,7 +60,7 @@ function processIntlConfig(config) {
|
|
|
60
60
|
*/
|
|
61
61
|
function createIntl(config, cache) {
|
|
62
62
|
var formatters = utils_1.createFormatters(cache);
|
|
63
|
-
var resolvedConfig = __assign({}, utils_1.DEFAULT_INTL_CONFIG, config);
|
|
63
|
+
var resolvedConfig = __assign(__assign({}, utils_1.DEFAULT_INTL_CONFIG), config);
|
|
64
64
|
if (!resolvedConfig.locale ||
|
|
65
65
|
!intl_locales_supported_1.default(resolvedConfig.locale)) {
|
|
66
66
|
var locale = resolvedConfig.locale, defaultLocale = resolvedConfig.defaultLocale, onError = resolvedConfig.onError;
|
|
@@ -75,7 +75,7 @@ function createIntl(config, cache) {
|
|
|
75
75
|
// each <FormattedMessage> contains a `defaultMessage` prop.
|
|
76
76
|
resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
|
|
77
77
|
}
|
|
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) });
|
|
78
|
+
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) });
|
|
79
79
|
}
|
|
80
80
|
exports.createIntl = createIntl;
|
|
81
81
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { IntlConfig, Formatters, IntlFormatters } from '../types';
|
|
3
|
-
export declare function formatList({ locale, onError }: Pick<IntlConfig, 'locale' | 'onError'>, getListFormat: Formatters['getListFormat'], values:
|
|
2
|
+
export declare function formatList({ locale, onError }: Pick<IntlConfig, 'locale' | 'onError'>, getListFormat: Formatters['getListFormat'], values: Array<string>, options: Parameters<IntlFormatters['formatList']>[1]): string;
|
|
@@ -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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
@@ -19,11 +19,11 @@ export declare const FormattedNumber: React.FC<UnifiedNumberFormatOptions & Cust
|
|
|
19
19
|
export declare const FormattedList: React.FC<IntlListFormatOptions & {
|
|
20
20
|
value: React.ReactNode[];
|
|
21
21
|
}>;
|
|
22
|
-
export declare const FormattedDateParts: React.
|
|
22
|
+
export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
23
23
|
value: string | number | Date | undefined;
|
|
24
24
|
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
25
|
}>;
|
|
26
|
-
export declare const FormattedTimeParts: React.
|
|
26
|
+
export declare const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
27
27
|
value: string | number | Date | undefined;
|
|
28
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;
|
|
29
29
|
}>;
|
package/dist/react-intl.api.md
CHANGED
|
@@ -58,7 +58,7 @@ export const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatCo
|
|
|
58
58
|
}>;
|
|
59
59
|
|
|
60
60
|
// @public (undocumented)
|
|
61
|
-
export const FormattedDateParts: React.
|
|
61
|
+
export const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
62
62
|
value: string | number | Date | undefined;
|
|
63
63
|
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
64
|
}>;
|
|
@@ -116,7 +116,7 @@ export const FormattedNumberParts: React.FC<Formatter['formatNumber'] & {
|
|
|
116
116
|
// Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts
|
|
117
117
|
//
|
|
118
118
|
// @public (undocumented)
|
|
119
|
-
export const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "
|
|
119
|
+
export const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
|
|
120
120
|
forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
|
|
121
121
|
} & React.RefAttributes<any>> & {
|
|
122
122
|
WrappedComponent: React.ComponentType<Props_2>;
|
|
@@ -156,7 +156,7 @@ export const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatCo
|
|
|
156
156
|
}>;
|
|
157
157
|
|
|
158
158
|
// @public (undocumented)
|
|
159
|
-
export const FormattedTimeParts: React.
|
|
159
|
+
export const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
160
160
|
value: string | number | Date | undefined;
|
|
161
161
|
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
162
|
}>;
|
|
@@ -245,6 +245,8 @@ export interface IntlFormatters {
|
|
|
245
245
|
// (undocumented)
|
|
246
246
|
formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
|
|
247
247
|
// (undocumented)
|
|
248
|
+
formatList(values: Array<string>, opts?: FormatListOptions): string;
|
|
249
|
+
// (undocumented)
|
|
248
250
|
formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
|
|
249
251
|
// (undocumented)
|
|
250
252
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
@@ -293,14 +295,14 @@ export interface MessageDescriptor {
|
|
|
293
295
|
// (undocumented)
|
|
294
296
|
description?: string | object;
|
|
295
297
|
// (undocumented)
|
|
296
|
-
id?: string;
|
|
298
|
+
id?: string | number;
|
|
297
299
|
}
|
|
298
300
|
|
|
299
301
|
// @public (undocumented)
|
|
300
302
|
export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
|
|
301
303
|
|
|
302
304
|
// @public (undocumented)
|
|
303
|
-
export const RawIntlProvider: React.
|
|
305
|
+
export const RawIntlProvider: React.Provider<IntlShape>;
|
|
304
306
|
|
|
305
307
|
// @public (undocumented)
|
|
306
308
|
export function useIntl(): IntlShape;
|
package/dist/react-intl.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & Custom
|
|
|
81
81
|
value: string | number | Date | undefined;
|
|
82
82
|
}>;
|
|
83
83
|
|
|
84
|
-
export declare const FormattedDateParts: React.
|
|
84
|
+
export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
85
85
|
value: string | number | Date | undefined;
|
|
86
86
|
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
87
|
}>;
|
|
@@ -117,7 +117,7 @@ export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] &
|
|
|
117
117
|
children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
|
|
118
118
|
}>;
|
|
119
119
|
|
|
120
|
-
export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "
|
|
120
|
+
export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
|
|
121
121
|
forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
|
|
122
122
|
} & React.RefAttributes<any>> & {
|
|
123
123
|
WrappedComponent: React.ComponentType<Props_2>;
|
|
@@ -141,7 +141,7 @@ export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & Custom
|
|
|
141
141
|
value: string | number | Date | undefined;
|
|
142
142
|
}>;
|
|
143
143
|
|
|
144
|
-
export declare const FormattedTimeParts: React.
|
|
144
|
+
export declare const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
145
145
|
value: string | number | Date | undefined;
|
|
146
146
|
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
147
|
}>;
|
|
@@ -212,6 +212,7 @@ export declare interface IntlFormatters {
|
|
|
212
212
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
213
213
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn>): string | React.ReactNodeArray;
|
|
214
214
|
formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
|
|
215
|
+
formatList(values: Array<string>, opts?: FormatListOptions): string;
|
|
215
216
|
formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
|
|
216
217
|
}
|
|
217
218
|
|
|
@@ -440,17 +441,25 @@ declare interface LocationDetails {
|
|
|
440
441
|
}
|
|
441
442
|
|
|
442
443
|
export declare interface MessageDescriptor {
|
|
443
|
-
id?: string;
|
|
444
|
+
id?: string | number;
|
|
444
445
|
description?: string | object;
|
|
445
446
|
defaultMessage?: string;
|
|
446
447
|
}
|
|
447
448
|
|
|
448
|
-
declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement;
|
|
449
|
+
declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement | PoundElement;
|
|
449
450
|
|
|
450
451
|
declare type MessageFormatPart = LiteralPart_2 | ArgumentPart;
|
|
451
452
|
|
|
452
453
|
declare type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;
|
|
453
454
|
|
|
455
|
+
declare interface NumberFormatDigitOptions {
|
|
456
|
+
minimumIntegerDigits?: number;
|
|
457
|
+
minimumFractionDigits?: number;
|
|
458
|
+
maximumFractionDigits?: number;
|
|
459
|
+
minimumSignificantDigits?: number;
|
|
460
|
+
maximumSignificantDigits?: number;
|
|
461
|
+
}
|
|
462
|
+
|
|
454
463
|
declare interface NumberSkeleton {
|
|
455
464
|
type: SKELETON_TYPE.number;
|
|
456
465
|
tokens: NumberSkeletonToken[];
|
|
@@ -514,6 +523,11 @@ declare interface PluralOrSelectOption {
|
|
|
514
523
|
location?: Location;
|
|
515
524
|
}
|
|
516
525
|
|
|
526
|
+
declare interface PoundElement {
|
|
527
|
+
type: TYPE.pound;
|
|
528
|
+
location?: Location;
|
|
529
|
+
}
|
|
530
|
+
|
|
517
531
|
declare type PrimitiveType = string | number | boolean | null | undefined | Date;
|
|
518
532
|
|
|
519
533
|
declare interface Props extends FormatRelativeTimeOptions {
|
|
@@ -541,7 +555,7 @@ declare interface Props_3<V extends Record<string, any> = Record<string, React.R
|
|
|
541
555
|
children?(...nodes: React.ReactNodeArray): React.ReactNode;
|
|
542
556
|
}
|
|
543
557
|
|
|
544
|
-
export declare const RawIntlProvider: React.
|
|
558
|
+
export declare const RawIntlProvider: React.Provider<IntlShape>;
|
|
545
559
|
|
|
546
560
|
declare type RelativeTimeData = {
|
|
547
561
|
[u in LDMLPluralRule]?: string;
|
|
@@ -682,10 +696,17 @@ declare enum TYPE {
|
|
|
682
696
|
/**
|
|
683
697
|
* Variable w/ plural format
|
|
684
698
|
*/
|
|
685
|
-
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
|
|
686
705
|
}
|
|
687
706
|
|
|
688
|
-
declare
|
|
707
|
+
declare type UnifiedNumberFormatOptions = Intl.NumberFormatOptions & NumberFormatDigitOptions & {
|
|
708
|
+
localeMatcher?: 'lookup' | 'best fit';
|
|
709
|
+
style?: 'decimal' | 'percent' | 'currency' | 'unit';
|
|
689
710
|
compactDisplay?: 'short' | 'long';
|
|
690
711
|
currencyDisplay?: 'symbol' | 'code' | 'name' | 'narrowSymbol';
|
|
691
712
|
currencySign?: 'standard' | 'accounting';
|
|
@@ -693,7 +714,7 @@ declare interface UnifiedNumberFormatOptions extends Intl.NumberFormatOptions {
|
|
|
693
714
|
signDisplay?: 'auto' | 'always' | 'never' | 'exceptZero';
|
|
694
715
|
unit?: Unit_2;
|
|
695
716
|
unitDisplay?: 'long' | 'short' | 'narrow';
|
|
696
|
-
}
|
|
717
|
+
};
|
|
697
718
|
|
|
698
719
|
declare type Unit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
699
720
|
|