@formatjs/intl 2.3.1 → 2.3.2
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/BUILD +79 -0
- package/CHANGELOG.md +537 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/index.ts +38 -0
- package/package.json +12 -8
- package/src/create-intl.ts +159 -0
- package/src/dateTime.ts +204 -0
- package/src/displayName.ts +54 -0
- package/src/error.ts +106 -0
- package/src/list.ts +119 -0
- package/src/message.ts +246 -0
- package/src/number.ts +101 -0
- package/src/plural.ts +45 -0
- package/src/relativeTime.ts +74 -0
- package/src/types.ts +234 -0
- package/src/utils.ts +177 -0
- package/tests/__snapshots__/formatDate.test.ts.snap +13 -0
- package/tests/__snapshots__/formatMessage.test.ts.snap +45 -0
- package/tests/__snapshots__/formatNumber.test.ts.snap +13 -0
- package/tests/__snapshots__/formatRelativeTime.test.ts.snap +19 -0
- package/tests/__snapshots__/formatTime.test.ts.snap +13 -0
- package/tests/create-intl.test.ts +60 -0
- package/tests/error.test.ts +25 -0
- package/tests/formatDate.test.ts +167 -0
- package/tests/formatDisplayNames.test.ts +63 -0
- package/tests/formatList.test.ts +51 -0
- package/tests/formatMessage.test.ts +495 -0
- package/tests/formatNumber.test.ts +172 -0
- package/tests/formatPlural.test.ts +119 -0
- package/tests/formatRelativeTime.test.ts +145 -0
- package/tests/formatTime.test.ts +234 -0
- package/tests/global.d.ts +7 -0
- package/tsconfig.json +5 -0
- package/index.d.ts +0 -17
- package/index.d.ts.map +0 -1
- package/index.js +0 -40
- package/lib/index.d.ts +0 -17
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -17
- package/lib/src/create-intl.d.ts +0 -11
- package/lib/src/create-intl.d.ts.map +0 -1
- package/lib/src/create-intl.js +0 -51
- package/lib/src/dateTime.d.ts +0 -38
- package/lib/src/dateTime.d.ts.map +0 -1
- package/lib/src/dateTime.js +0 -117
- package/lib/src/displayName.d.ts +0 -6
- package/lib/src/displayName.d.ts.map +0 -1
- package/lib/src/displayName.js +0 -22
- package/lib/src/error.d.ts +0 -34
- package/lib/src/error.d.ts.map +0 -1
- package/lib/src/error.js +0 -88
- package/lib/src/list.d.ts +0 -11
- package/lib/src/list.d.ts.map +0 -1
- package/lib/src/list.js +0 -61
- package/lib/src/message.d.ts +0 -16
- package/lib/src/message.d.ts.map +0 -1
- package/lib/src/message.js +0 -103
- package/lib/src/number.d.ts +0 -17
- package/lib/src/number.d.ts.map +0 -1
- package/lib/src/number.js +0 -54
- package/lib/src/plural.d.ts +0 -7
- package/lib/src/plural.d.ts.map +0 -1
- package/lib/src/plural.js +0 -19
- package/lib/src/relativeTime.d.ts +0 -7
- package/lib/src/relativeTime.d.ts.map +0 -1
- package/lib/src/relativeTime.js +0 -29
- package/lib/src/types.d.ts +0 -103
- package/lib/src/types.d.ts.map +0 -1
- package/lib/src/types.js +0 -1
- package/lib/src/utils.d.ts +0 -12
- package/lib/src/utils.d.ts.map +0 -1
- package/lib/src/utils.js +0 -162
- package/src/create-intl.d.ts +0 -11
- package/src/create-intl.d.ts.map +0 -1
- package/src/create-intl.js +0 -55
- package/src/dateTime.d.ts +0 -38
- package/src/dateTime.d.ts.map +0 -1
- package/src/dateTime.js +0 -126
- package/src/displayName.d.ts +0 -6
- package/src/displayName.d.ts.map +0 -1
- package/src/displayName.js +0 -26
- package/src/error.d.ts +0 -34
- package/src/error.d.ts.map +0 -1
- package/src/error.js +0 -91
- package/src/list.d.ts +0 -11
- package/src/list.d.ts.map +0 -1
- package/src/list.js +0 -66
- package/src/message.d.ts +0 -16
- package/src/message.d.ts.map +0 -1
- package/src/message.js +0 -107
- package/src/number.d.ts +0 -17
- package/src/number.d.ts.map +0 -1
- package/src/number.js +0 -60
- package/src/plural.d.ts +0 -7
- package/src/plural.d.ts.map +0 -1
- package/src/plural.js +0 -23
- package/src/relativeTime.d.ts +0 -7
- package/src/relativeTime.d.ts.map +0 -1
- package/src/relativeTime.js +0 -33
- package/src/types.d.ts +0 -103
- package/src/types.d.ts.map +0 -1
- package/src/types.js +0 -2
- package/src/utils.d.ts +0 -12
- package/src/utils.d.ts.map +0 -1
- package/src/utils.js +0 -169
package/lib/src/create-intl.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
|
-
import { createFormatters, DEFAULT_INTL_CONFIG } from './utils';
|
|
3
|
-
import { InvalidConfigError, MissingDataError } from './error';
|
|
4
|
-
import { formatNumber, formatNumberToParts } from './number';
|
|
5
|
-
import { formatRelativeTime } from './relativeTime';
|
|
6
|
-
import { formatDate, formatDateToParts, formatTime, formatTimeToParts, formatDateTimeRange, } from './dateTime';
|
|
7
|
-
import { formatPlural } from './plural';
|
|
8
|
-
import { formatMessage } from './message';
|
|
9
|
-
import { formatList, formatListToParts } from './list';
|
|
10
|
-
import { formatDisplayName } from './displayName';
|
|
11
|
-
function messagesContainString(messages) {
|
|
12
|
-
var firstMessage = messages ? messages[Object.keys(messages)[0]] : undefined;
|
|
13
|
-
return typeof firstMessage === 'string';
|
|
14
|
-
}
|
|
15
|
-
function verifyConfigMessages(config) {
|
|
16
|
-
if (config.onWarn &&
|
|
17
|
-
config.defaultRichTextElements &&
|
|
18
|
-
messagesContainString(config.messages || {})) {
|
|
19
|
-
config.onWarn("[@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.io/docs/getting-started/message-distribution");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create intl object
|
|
24
|
-
* @param config intl config
|
|
25
|
-
* @param cache cache for formatter instances to prevent memory leak
|
|
26
|
-
*/
|
|
27
|
-
export function createIntl(config, cache) {
|
|
28
|
-
var formatters = createFormatters(cache);
|
|
29
|
-
var resolvedConfig = __assign(__assign({}, DEFAULT_INTL_CONFIG), config);
|
|
30
|
-
var locale = resolvedConfig.locale, defaultLocale = resolvedConfig.defaultLocale, onError = resolvedConfig.onError;
|
|
31
|
-
if (!locale) {
|
|
32
|
-
if (onError) {
|
|
33
|
-
onError(new InvalidConfigError("\"locale\" was not configured, using \"".concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl/api#intlshape for more details")));
|
|
34
|
-
}
|
|
35
|
-
// Since there's no registered locale data for `locale`, this will
|
|
36
|
-
// fallback to the `defaultLocale` to make sure things can render.
|
|
37
|
-
// The `messages` are overridden to the `defaultProps` empty object
|
|
38
|
-
// to maintain referential equality across re-renders. It's assumed
|
|
39
|
-
// each <FormattedMessage> contains a `defaultMessage` prop.
|
|
40
|
-
resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
|
|
41
|
-
}
|
|
42
|
-
else if (!Intl.NumberFormat.supportedLocalesOf(locale).length && onError) {
|
|
43
|
-
onError(new MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.NumberFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details")));
|
|
44
|
-
}
|
|
45
|
-
else if (!Intl.DateTimeFormat.supportedLocalesOf(locale).length &&
|
|
46
|
-
onError) {
|
|
47
|
-
onError(new MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.DateTimeFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details")));
|
|
48
|
-
}
|
|
49
|
-
verifyConfigMessages(resolvedConfig);
|
|
50
|
-
return __assign(__assign({}, resolvedConfig), { formatters: formatters, formatNumber: formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: formatMessage.bind(null, resolvedConfig, formatters), $t: formatMessage.bind(null, resolvedConfig, formatters), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatListToParts: formatListToParts.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
|
|
51
|
-
}
|
package/lib/src/dateTime.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Formatters, IntlFormatters, CustomFormats, OnErrorFn } from './types';
|
|
2
|
-
import { DateTimeFormat } from '@formatjs/ecma402-abstract';
|
|
3
|
-
export declare function getFormatter({ locale, formats, onError, timeZone, }: {
|
|
4
|
-
locale: string;
|
|
5
|
-
timeZone?: string;
|
|
6
|
-
formats: CustomFormats;
|
|
7
|
-
onError: OnErrorFn;
|
|
8
|
-
}, type: 'date' | 'time', getDateTimeFormat: Formatters['getDateTimeFormat'], options?: Parameters<IntlFormatters['formatDate']>[1]): DateTimeFormat;
|
|
9
|
-
export declare function formatDate(config: {
|
|
10
|
-
locale: string;
|
|
11
|
-
timeZone?: string;
|
|
12
|
-
formats: CustomFormats;
|
|
13
|
-
onError: OnErrorFn;
|
|
14
|
-
}, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[value, options]: Parameters<IntlFormatters['formatDate']>): string;
|
|
15
|
-
export declare function formatTime(config: {
|
|
16
|
-
locale: string;
|
|
17
|
-
timeZone?: string;
|
|
18
|
-
formats: CustomFormats;
|
|
19
|
-
onError: OnErrorFn;
|
|
20
|
-
}, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[value, options]: Parameters<IntlFormatters['formatTime']>): string;
|
|
21
|
-
export declare function formatDateTimeRange(config: {
|
|
22
|
-
locale: string;
|
|
23
|
-
timeZone?: string;
|
|
24
|
-
onError: OnErrorFn;
|
|
25
|
-
}, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[from, to, options]: Parameters<IntlFormatters['formatDateTimeRange']>): string;
|
|
26
|
-
export declare function formatDateToParts(config: {
|
|
27
|
-
locale: string;
|
|
28
|
-
timeZone?: string;
|
|
29
|
-
formats: CustomFormats;
|
|
30
|
-
onError: OnErrorFn;
|
|
31
|
-
}, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[value, options]: Parameters<IntlFormatters['formatDate']>): Intl.DateTimeFormatPart[];
|
|
32
|
-
export declare function formatTimeToParts(config: {
|
|
33
|
-
locale: string;
|
|
34
|
-
timeZone?: string;
|
|
35
|
-
formats: CustomFormats;
|
|
36
|
-
onError: OnErrorFn;
|
|
37
|
-
}, getDateTimeFormat: Formatters['getDateTimeFormat'], ...[value, options]: Parameters<IntlFormatters['formatTimeToParts']>): Intl.DateTimeFormatPart[];
|
|
38
|
-
//# sourceMappingURL=dateTime.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dateTime.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/dateTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAI5E,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAA;AA0BzD,wBAAgB,YAAY,CAC1B,EACE,MAAM,EACN,OAAO,EACP,OAAO,EACP,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,iBAAiB,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAClD,OAAO,GAAE,U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,CAAC,mBAAmB,CAAC,EAClD,GAAG,CAAC,KAAK,EAAE,OAAY,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,GACjE,IAAI,CAAC,kBAAkB,EAAE,CAgB3B;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,iBAAiB,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAClD,GAAG,CAAC,KAAK,EAAE,OAAY,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,GACxE,IAAI,CAAC,kBAAkB,EAAE,CAiB3B"}
|
package/lib/src/dateTime.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
|
-
import { filterProps, getNamedFormat } from './utils';
|
|
3
|
-
import { IntlError, IntlErrorCode } from './error';
|
|
4
|
-
var DATE_TIME_FORMAT_OPTIONS = [
|
|
5
|
-
'formatMatcher',
|
|
6
|
-
'timeZone',
|
|
7
|
-
'hour12',
|
|
8
|
-
'weekday',
|
|
9
|
-
'era',
|
|
10
|
-
'year',
|
|
11
|
-
'month',
|
|
12
|
-
'day',
|
|
13
|
-
'hour',
|
|
14
|
-
'minute',
|
|
15
|
-
'second',
|
|
16
|
-
'timeZoneName',
|
|
17
|
-
'hourCycle',
|
|
18
|
-
'dateStyle',
|
|
19
|
-
'timeStyle',
|
|
20
|
-
'calendar',
|
|
21
|
-
// 'dayPeriod',
|
|
22
|
-
'numberingSystem',
|
|
23
|
-
'fractionalSecondDigits',
|
|
24
|
-
];
|
|
25
|
-
export function getFormatter(_a, type, getDateTimeFormat, options) {
|
|
26
|
-
var locale = _a.locale, formats = _a.formats, onError = _a.onError, timeZone = _a.timeZone;
|
|
27
|
-
if (options === void 0) { options = {}; }
|
|
28
|
-
var format = options.format;
|
|
29
|
-
var defaults = __assign(__assign({}, (timeZone && { timeZone: timeZone })), (format && getNamedFormat(formats, type, format, onError)));
|
|
30
|
-
var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults);
|
|
31
|
-
if (type === 'time' &&
|
|
32
|
-
!filteredOptions.hour &&
|
|
33
|
-
!filteredOptions.minute &&
|
|
34
|
-
!filteredOptions.second &&
|
|
35
|
-
!filteredOptions.timeStyle &&
|
|
36
|
-
!filteredOptions.dateStyle) {
|
|
37
|
-
// Add default formatting options if hour, minute, or second isn't defined.
|
|
38
|
-
filteredOptions = __assign(__assign({}, filteredOptions), { hour: 'numeric', minute: 'numeric' });
|
|
39
|
-
}
|
|
40
|
-
return getDateTimeFormat(locale, filteredOptions);
|
|
41
|
-
}
|
|
42
|
-
export function formatDate(config, getDateTimeFormat) {
|
|
43
|
-
var _a = [];
|
|
44
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
45
|
-
_a[_i - 2] = arguments[_i];
|
|
46
|
-
}
|
|
47
|
-
var value = _a[0], _b = _a[1], options = _b === void 0 ? {} : _b;
|
|
48
|
-
var date = typeof value === 'string' ? new Date(value || 0) : value;
|
|
49
|
-
try {
|
|
50
|
-
return getFormatter(config, 'date', getDateTimeFormat, options).format(date);
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting date.', e));
|
|
54
|
-
}
|
|
55
|
-
return String(date);
|
|
56
|
-
}
|
|
57
|
-
export function formatTime(config, getDateTimeFormat) {
|
|
58
|
-
var _a = [];
|
|
59
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
60
|
-
_a[_i - 2] = arguments[_i];
|
|
61
|
-
}
|
|
62
|
-
var value = _a[0], _b = _a[1], options = _b === void 0 ? {} : _b;
|
|
63
|
-
var date = typeof value === 'string' ? new Date(value || 0) : value;
|
|
64
|
-
try {
|
|
65
|
-
return getFormatter(config, 'time', getDateTimeFormat, options).format(date);
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting time.', e));
|
|
69
|
-
}
|
|
70
|
-
return String(date);
|
|
71
|
-
}
|
|
72
|
-
export function formatDateTimeRange(config, getDateTimeFormat) {
|
|
73
|
-
var _a = [];
|
|
74
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
75
|
-
_a[_i - 2] = arguments[_i];
|
|
76
|
-
}
|
|
77
|
-
var from = _a[0], to = _a[1], _b = _a[2], options = _b === void 0 ? {} : _b;
|
|
78
|
-
var timeZone = config.timeZone, locale = config.locale, onError = config.onError;
|
|
79
|
-
var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, timeZone ? { timeZone: timeZone } : {});
|
|
80
|
-
try {
|
|
81
|
-
return getDateTimeFormat(locale, filteredOptions).formatRange(from, to);
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting date time range.', e));
|
|
85
|
-
}
|
|
86
|
-
return String(from);
|
|
87
|
-
}
|
|
88
|
-
export function formatDateToParts(config, getDateTimeFormat) {
|
|
89
|
-
var _a = [];
|
|
90
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
91
|
-
_a[_i - 2] = arguments[_i];
|
|
92
|
-
}
|
|
93
|
-
var value = _a[0], _b = _a[1], options = _b === void 0 ? {} : _b;
|
|
94
|
-
var date = typeof value === 'string' ? new Date(value || 0) : value;
|
|
95
|
-
try {
|
|
96
|
-
return getFormatter(config, 'date', getDateTimeFormat, options).formatToParts(date);
|
|
97
|
-
}
|
|
98
|
-
catch (e) {
|
|
99
|
-
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting date.', e));
|
|
100
|
-
}
|
|
101
|
-
return [];
|
|
102
|
-
}
|
|
103
|
-
export function formatTimeToParts(config, getDateTimeFormat) {
|
|
104
|
-
var _a = [];
|
|
105
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
106
|
-
_a[_i - 2] = arguments[_i];
|
|
107
|
-
}
|
|
108
|
-
var value = _a[0], _b = _a[1], options = _b === void 0 ? {} : _b;
|
|
109
|
-
var date = typeof value === 'string' ? new Date(value || 0) : value;
|
|
110
|
-
try {
|
|
111
|
-
return getFormatter(config, 'time', getDateTimeFormat, options).formatToParts(date);
|
|
112
|
-
}
|
|
113
|
-
catch (e) {
|
|
114
|
-
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting time.', e));
|
|
115
|
-
}
|
|
116
|
-
return [];
|
|
117
|
-
}
|
package/lib/src/displayName.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Formatters, IntlFormatters, OnErrorFn } from './types';
|
|
2
|
-
export declare function formatDisplayName({ locale, onError, }: {
|
|
3
|
-
locale: string;
|
|
4
|
-
onError: OnErrorFn;
|
|
5
|
-
}, getDisplayNames: Formatters['getDisplayNames'], value: Parameters<IntlFormatters['formatDisplayName']>[0], options: Parameters<IntlFormatters['formatDisplayName']>[1]): string | undefined;
|
|
6
|
-
//# sourceMappingURL=displayName.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"displayName.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/displayName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAe7D,wBAAgB,iBAAiB,CAC/B,EACE,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAC9C,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,EACzD,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1D,MAAM,GAAG,SAAS,CA2BpB"}
|
package/lib/src/displayName.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { filterProps } from './utils';
|
|
2
|
-
import { FormatError, ErrorCode } from 'intl-messageformat';
|
|
3
|
-
import { IntlErrorCode, IntlError } from './error';
|
|
4
|
-
var DISPLAY_NAMES_OPTONS = [
|
|
5
|
-
'style',
|
|
6
|
-
'type',
|
|
7
|
-
'fallback',
|
|
8
|
-
];
|
|
9
|
-
export function formatDisplayName(_a, getDisplayNames, value, options) {
|
|
10
|
-
var locale = _a.locale, onError = _a.onError;
|
|
11
|
-
var DisplayNames = Intl.DisplayNames;
|
|
12
|
-
if (!DisplayNames) {
|
|
13
|
-
onError(new FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", ErrorCode.MISSING_INTL_API));
|
|
14
|
-
}
|
|
15
|
-
var filteredOptions = filterProps(options, DISPLAY_NAMES_OPTONS);
|
|
16
|
-
try {
|
|
17
|
-
return getDisplayNames(locale, filteredOptions).of(value);
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting display name.', e));
|
|
21
|
-
}
|
|
22
|
-
}
|
package/lib/src/error.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { MessageDescriptor } from './types';
|
|
2
|
-
export declare enum IntlErrorCode {
|
|
3
|
-
FORMAT_ERROR = "FORMAT_ERROR",
|
|
4
|
-
UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
|
|
5
|
-
INVALID_CONFIG = "INVALID_CONFIG",
|
|
6
|
-
MISSING_DATA = "MISSING_DATA",
|
|
7
|
-
MISSING_TRANSLATION = "MISSING_TRANSLATION"
|
|
8
|
-
}
|
|
9
|
-
export declare class IntlError<T extends IntlErrorCode = IntlErrorCode.FORMAT_ERROR> extends Error {
|
|
10
|
-
readonly code: T;
|
|
11
|
-
constructor(code: T, message: string, exception?: Error | unknown);
|
|
12
|
-
}
|
|
13
|
-
export declare class UnsupportedFormatterError extends IntlError<IntlErrorCode.UNSUPPORTED_FORMATTER> {
|
|
14
|
-
constructor(message: string, exception?: Error | unknown);
|
|
15
|
-
}
|
|
16
|
-
export declare class InvalidConfigError extends IntlError<IntlErrorCode.INVALID_CONFIG> {
|
|
17
|
-
constructor(message: string, exception?: Error | unknown);
|
|
18
|
-
}
|
|
19
|
-
export declare class MissingDataError extends IntlError<IntlErrorCode.MISSING_DATA> {
|
|
20
|
-
constructor(message: string, exception?: Error | unknown);
|
|
21
|
-
}
|
|
22
|
-
export declare class IntlFormatError extends IntlError<IntlErrorCode.FORMAT_ERROR> {
|
|
23
|
-
readonly descriptor?: MessageDescriptor;
|
|
24
|
-
constructor(message: string, locale: string, exception?: Error | unknown);
|
|
25
|
-
}
|
|
26
|
-
export declare class MessageFormatError extends IntlFormatError {
|
|
27
|
-
readonly descriptor?: MessageDescriptor;
|
|
28
|
-
constructor(message: string, locale: string, descriptor?: MessageDescriptor, exception?: Error | unknown);
|
|
29
|
-
}
|
|
30
|
-
export declare class MissingTranslationError extends IntlError<IntlErrorCode.MISSING_TRANSLATION> {
|
|
31
|
-
readonly descriptor?: MessageDescriptor;
|
|
32
|
-
constructor(descriptor: MessageDescriptor, locale: string);
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=error.d.ts.map
|
package/lib/src/error.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAA;AAEzC,oBAAY,aAAa;IACvB,YAAY,iBAAiB;IAC7B,qBAAqB,0BAA0B;IAC/C,cAAc,mBAAmB;IACjC,Y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,iBAAiB,EAAE,MAAM,EAAE,MAAM;CAiB1D"}
|
package/lib/src/error.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
|
-
export var IntlErrorCode;
|
|
3
|
-
(function (IntlErrorCode) {
|
|
4
|
-
IntlErrorCode["FORMAT_ERROR"] = "FORMAT_ERROR";
|
|
5
|
-
IntlErrorCode["UNSUPPORTED_FORMATTER"] = "UNSUPPORTED_FORMATTER";
|
|
6
|
-
IntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
|
|
7
|
-
IntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
|
|
8
|
-
IntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
|
|
9
|
-
})(IntlErrorCode || (IntlErrorCode = {}));
|
|
10
|
-
var IntlError = /** @class */ (function (_super) {
|
|
11
|
-
__extends(IntlError, _super);
|
|
12
|
-
function IntlError(code, message, exception) {
|
|
13
|
-
var _this = this;
|
|
14
|
-
var err = exception
|
|
15
|
-
? exception instanceof Error
|
|
16
|
-
? exception
|
|
17
|
-
: new Error(String(exception))
|
|
18
|
-
: undefined;
|
|
19
|
-
_this = _super.call(this, "[@formatjs/intl Error ".concat(code, "] ").concat(message, "\n").concat(err ? "\n".concat(err.message, "\n").concat(err.stack) : '')) || this;
|
|
20
|
-
_this.code = code;
|
|
21
|
-
// @ts-ignore just so we don't need to declare dep on @types/node
|
|
22
|
-
if (typeof Error.captureStackTrace === 'function') {
|
|
23
|
-
// @ts-ignore just so we don't need to declare dep on @types/node
|
|
24
|
-
Error.captureStackTrace(_this, IntlError);
|
|
25
|
-
}
|
|
26
|
-
return _this;
|
|
27
|
-
}
|
|
28
|
-
return IntlError;
|
|
29
|
-
}(Error));
|
|
30
|
-
export { IntlError };
|
|
31
|
-
var UnsupportedFormatterError = /** @class */ (function (_super) {
|
|
32
|
-
__extends(UnsupportedFormatterError, _super);
|
|
33
|
-
function UnsupportedFormatterError(message, exception) {
|
|
34
|
-
return _super.call(this, IntlErrorCode.UNSUPPORTED_FORMATTER, message, exception) || this;
|
|
35
|
-
}
|
|
36
|
-
return UnsupportedFormatterError;
|
|
37
|
-
}(IntlError));
|
|
38
|
-
export { UnsupportedFormatterError };
|
|
39
|
-
var InvalidConfigError = /** @class */ (function (_super) {
|
|
40
|
-
__extends(InvalidConfigError, _super);
|
|
41
|
-
function InvalidConfigError(message, exception) {
|
|
42
|
-
return _super.call(this, IntlErrorCode.INVALID_CONFIG, message, exception) || this;
|
|
43
|
-
}
|
|
44
|
-
return InvalidConfigError;
|
|
45
|
-
}(IntlError));
|
|
46
|
-
export { InvalidConfigError };
|
|
47
|
-
var MissingDataError = /** @class */ (function (_super) {
|
|
48
|
-
__extends(MissingDataError, _super);
|
|
49
|
-
function MissingDataError(message, exception) {
|
|
50
|
-
return _super.call(this, IntlErrorCode.MISSING_DATA, message, exception) || this;
|
|
51
|
-
}
|
|
52
|
-
return MissingDataError;
|
|
53
|
-
}(IntlError));
|
|
54
|
-
export { MissingDataError };
|
|
55
|
-
var IntlFormatError = /** @class */ (function (_super) {
|
|
56
|
-
__extends(IntlFormatError, _super);
|
|
57
|
-
function IntlFormatError(message, locale, exception) {
|
|
58
|
-
return _super.call(this, IntlErrorCode.FORMAT_ERROR, "".concat(message, "\nLocale: ").concat(locale, "\n"), exception) || this;
|
|
59
|
-
}
|
|
60
|
-
return IntlFormatError;
|
|
61
|
-
}(IntlError));
|
|
62
|
-
export { IntlFormatError };
|
|
63
|
-
var MessageFormatError = /** @class */ (function (_super) {
|
|
64
|
-
__extends(MessageFormatError, _super);
|
|
65
|
-
function MessageFormatError(message, locale, descriptor, exception) {
|
|
66
|
-
var _this = _super.call(this, "".concat(message, "\nMessageID: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.id, "\nDefault Message: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.defaultMessage, "\nDescription: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.description, "\n"), locale, exception) || this;
|
|
67
|
-
_this.descriptor = descriptor;
|
|
68
|
-
return _this;
|
|
69
|
-
}
|
|
70
|
-
return MessageFormatError;
|
|
71
|
-
}(IntlFormatError));
|
|
72
|
-
export { MessageFormatError };
|
|
73
|
-
var MissingTranslationError = /** @class */ (function (_super) {
|
|
74
|
-
__extends(MissingTranslationError, _super);
|
|
75
|
-
function MissingTranslationError(descriptor, locale) {
|
|
76
|
-
var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"".concat(descriptor.id, "\" for locale \"").concat(locale, "\", using ").concat(descriptor.defaultMessage
|
|
77
|
-
? "default message (".concat(typeof descriptor.defaultMessage === 'string'
|
|
78
|
-
? descriptor.defaultMessage
|
|
79
|
-
: descriptor.defaultMessage
|
|
80
|
-
.map(function (e) { var _a; return (_a = e.value) !== null && _a !== void 0 ? _a : JSON.stringify(e); })
|
|
81
|
-
.join(), ")")
|
|
82
|
-
: 'id', " as fallback.")) || this;
|
|
83
|
-
_this.descriptor = descriptor;
|
|
84
|
-
return _this;
|
|
85
|
-
}
|
|
86
|
-
return MissingTranslationError;
|
|
87
|
-
}(IntlError));
|
|
88
|
-
export { MissingTranslationError };
|
package/lib/src/list.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Formatters, IntlFormatters, OnErrorFn } from './types';
|
|
2
|
-
import type { Part } from '@formatjs/intl-listformat';
|
|
3
|
-
export declare function formatList(opts: {
|
|
4
|
-
locale: string;
|
|
5
|
-
onError: OnErrorFn;
|
|
6
|
-
}, getListFormat: Formatters['getListFormat'], values: ReadonlyArray<string>, options: Parameters<IntlFormatters['formatList']>[1]): string;
|
|
7
|
-
export declare function formatListToParts<T>(opts: {
|
|
8
|
-
locale: string;
|
|
9
|
-
onError: OnErrorFn;
|
|
10
|
-
}, getListFormat: Formatters['getListFormat'], values: ReadonlyArray<string>, options: Parameters<IntlFormatters['formatList']>[1]): Part[];
|
|
11
|
-
//# sourceMappingURL=list.d.ts.map
|
package/lib/src/list.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAG7D,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,2BAA2B,CAAA;AAgBnD,wBAAgB,UAAU,CACxB,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,aAAa,EAAE,UAAU,CAAC,eAAe,CAAC,EAC1C,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GACnD,MAAM,CAAA;AA6BT,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,aAAa,EAAE,UAAU,CAAC,eAAe,CAAC,EAC1C,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GACnD,IAAI,EAAE,CAAA"}
|
package/lib/src/list.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
|
-
import { filterProps } from './utils';
|
|
3
|
-
import { FormatError, ErrorCode } from 'intl-messageformat';
|
|
4
|
-
import { IntlError, IntlErrorCode } from './error';
|
|
5
|
-
var LIST_FORMAT_OPTIONS = [
|
|
6
|
-
'type',
|
|
7
|
-
'style',
|
|
8
|
-
];
|
|
9
|
-
var now = Date.now();
|
|
10
|
-
function generateToken(i) {
|
|
11
|
-
return "".concat(now, "_").concat(i, "_").concat(now);
|
|
12
|
-
}
|
|
13
|
-
export function formatList(opts, getListFormat, values, options) {
|
|
14
|
-
if (options === void 0) { options = {}; }
|
|
15
|
-
var results = formatListToParts(opts, getListFormat, values, options).reduce(function (all, el) {
|
|
16
|
-
var val = el.value;
|
|
17
|
-
if (typeof val !== 'string') {
|
|
18
|
-
all.push(val);
|
|
19
|
-
}
|
|
20
|
-
else if (typeof all[all.length - 1] === 'string') {
|
|
21
|
-
all[all.length - 1] += val;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
all.push(val);
|
|
25
|
-
}
|
|
26
|
-
return all;
|
|
27
|
-
}, []);
|
|
28
|
-
return results.length === 1 ? results[0] : results;
|
|
29
|
-
}
|
|
30
|
-
export function formatListToParts(_a, getListFormat, values, options) {
|
|
31
|
-
var locale = _a.locale, onError = _a.onError;
|
|
32
|
-
if (options === void 0) { options = {}; }
|
|
33
|
-
var ListFormat = Intl.ListFormat;
|
|
34
|
-
if (!ListFormat) {
|
|
35
|
-
onError(new FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", ErrorCode.MISSING_INTL_API));
|
|
36
|
-
}
|
|
37
|
-
var filteredOptions = filterProps(options, LIST_FORMAT_OPTIONS);
|
|
38
|
-
try {
|
|
39
|
-
var richValues_1 = {};
|
|
40
|
-
var serializedValues = values.map(function (v, i) {
|
|
41
|
-
if (typeof v === 'object') {
|
|
42
|
-
var id = generateToken(i);
|
|
43
|
-
richValues_1[id] = v;
|
|
44
|
-
return id;
|
|
45
|
-
}
|
|
46
|
-
return String(v);
|
|
47
|
-
});
|
|
48
|
-
return getListFormat(locale, filteredOptions)
|
|
49
|
-
.formatToParts(serializedValues)
|
|
50
|
-
.map(function (part) {
|
|
51
|
-
return part.type === 'literal'
|
|
52
|
-
? part
|
|
53
|
-
: __assign(__assign({}, part), { value: richValues_1[part.value] || part.value });
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting list.', e));
|
|
58
|
-
}
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
return values;
|
|
61
|
-
}
|
package/lib/src/message.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Formatters, MessageDescriptor, CustomFormats, OnErrorFn } from './types';
|
|
2
|
-
import { FormatXMLElementFn, PrimitiveType, Formatters as IntlMessageFormatFormatters, Options } from 'intl-messageformat';
|
|
3
|
-
import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
|
4
|
-
export declare type FormatMessageFn<T> = ({ locale, formats, messages, defaultLocale, defaultFormats, fallbackOnEmptyString, onError, timeZone, defaultRichTextElements, }: {
|
|
5
|
-
locale: string;
|
|
6
|
-
timeZone?: string;
|
|
7
|
-
formats: CustomFormats;
|
|
8
|
-
messages: Record<string, string> | Record<string, MessageFormatElement[]>;
|
|
9
|
-
defaultLocale: string;
|
|
10
|
-
defaultFormats: CustomFormats;
|
|
11
|
-
defaultRichTextElements?: Record<string, FormatXMLElementFn<T>>;
|
|
12
|
-
fallbackOnEmptyString?: boolean;
|
|
13
|
-
onError: OnErrorFn;
|
|
14
|
-
}, state: IntlMessageFormatFormatters & Pick<Formatters, 'getMessageFormat'>, messageDescriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: Options) => T extends string ? string : Array<T | string> | string | T;
|
|
15
|
-
export declare const formatMessage: FormatMessageFn<any>;
|
|
16
|
-
//# sourceMappingURL=message.d.ts.map
|
package/lib/src/message.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAE/E,OAAO,EAEL,kBAAkB,EAClB,aAAa,EACb,UAAU,IAA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
-
import { IntlMessageFormat, } from 'intl-messageformat';
|
|
4
|
-
import { MissingTranslationError, MessageFormatError } from './error';
|
|
5
|
-
import { TYPE } from '@formatjs/icu-messageformat-parser';
|
|
6
|
-
function setTimeZoneInOptions(opts, timeZone) {
|
|
7
|
-
return Object.keys(opts).reduce(function (all, k) {
|
|
8
|
-
all[k] = __assign({ timeZone: timeZone }, opts[k]);
|
|
9
|
-
return all;
|
|
10
|
-
}, {});
|
|
11
|
-
}
|
|
12
|
-
function deepMergeOptions(opts1, opts2) {
|
|
13
|
-
var keys = Object.keys(__assign(__assign({}, opts1), opts2));
|
|
14
|
-
return keys.reduce(function (all, k) {
|
|
15
|
-
all[k] = __assign(__assign({}, (opts1[k] || {})), (opts2[k] || {}));
|
|
16
|
-
return all;
|
|
17
|
-
}, {});
|
|
18
|
-
}
|
|
19
|
-
function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
|
|
20
|
-
if (!timeZone) {
|
|
21
|
-
return f1;
|
|
22
|
-
}
|
|
23
|
-
var mfFormats = IntlMessageFormat.formats;
|
|
24
|
-
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)) });
|
|
25
|
-
}
|
|
26
|
-
export var formatMessage = function (_a, state, messageDescriptor, values, opts) {
|
|
27
|
-
var locale = _a.locale, formats = _a.formats, messages = _a.messages, defaultLocale = _a.defaultLocale, defaultFormats = _a.defaultFormats, fallbackOnEmptyString = _a.fallbackOnEmptyString, onError = _a.onError, timeZone = _a.timeZone, defaultRichTextElements = _a.defaultRichTextElements;
|
|
28
|
-
if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; }
|
|
29
|
-
var msgId = messageDescriptor.id, defaultMessage = messageDescriptor.defaultMessage;
|
|
30
|
-
// `id` is a required field of a Message Descriptor.
|
|
31
|
-
invariant(!!msgId, "[@formatjs/intl] An `id` must be provided to format a message. You can either:\n1. Configure your build toolchain with [babel-plugin-formatjs](https://formatjs.io/docs/tooling/babel-plugin)\nor [@formatjs/ts-transformer](https://formatjs.io/docs/tooling/ts-transformer) OR\n2. Configure your `eslint` config to include [eslint-plugin-formatjs](https://formatjs.io/docs/tooling/linter#enforce-id)\nto autofix this issue");
|
|
32
|
-
var id = String(msgId);
|
|
33
|
-
var message =
|
|
34
|
-
// In case messages is Object.create(null)
|
|
35
|
-
// e.g import('foo.json') from webpack)
|
|
36
|
-
// See https://github.com/formatjs/formatjs/issues/1914
|
|
37
|
-
messages &&
|
|
38
|
-
Object.prototype.hasOwnProperty.call(messages, id) &&
|
|
39
|
-
messages[id];
|
|
40
|
-
// IMPORTANT: Hot path if `message` is AST with a single literal node
|
|
41
|
-
if (Array.isArray(message) &&
|
|
42
|
-
message.length === 1 &&
|
|
43
|
-
message[0].type === TYPE.literal) {
|
|
44
|
-
return message[0].value;
|
|
45
|
-
}
|
|
46
|
-
// IMPORTANT: Hot path straight lookup for performance
|
|
47
|
-
if (!values &&
|
|
48
|
-
message &&
|
|
49
|
-
typeof message === 'string' &&
|
|
50
|
-
!defaultRichTextElements) {
|
|
51
|
-
return message.replace(/'\{(.*?)\}'/gi, "{$1}");
|
|
52
|
-
}
|
|
53
|
-
values = __assign(__assign({}, defaultRichTextElements), (values || {}));
|
|
54
|
-
formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
|
|
55
|
-
defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
|
|
56
|
-
if (!message) {
|
|
57
|
-
if (fallbackOnEmptyString === false && message === '') {
|
|
58
|
-
return message;
|
|
59
|
-
}
|
|
60
|
-
if (!defaultMessage ||
|
|
61
|
-
(locale && locale.toLowerCase() !== defaultLocale.toLowerCase())) {
|
|
62
|
-
// This prevents warnings from littering the console in development
|
|
63
|
-
// when no `messages` are passed into the <IntlProvider> for the
|
|
64
|
-
// default locale.
|
|
65
|
-
onError(new MissingTranslationError(messageDescriptor, locale));
|
|
66
|
-
}
|
|
67
|
-
if (defaultMessage) {
|
|
68
|
-
try {
|
|
69
|
-
var formatter = state.getMessageFormat(defaultMessage, defaultLocale, defaultFormats, opts);
|
|
70
|
-
return formatter.format(values);
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
onError(new MessageFormatError("Error formatting default message for: \"".concat(id, "\", rendering default message verbatim"), locale, messageDescriptor, e));
|
|
74
|
-
return typeof defaultMessage === 'string' ? defaultMessage : id;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return id;
|
|
78
|
-
}
|
|
79
|
-
// We have the translated message
|
|
80
|
-
try {
|
|
81
|
-
var formatter = state.getMessageFormat(message, locale, formats, __assign({ formatters: state }, (opts || {})));
|
|
82
|
-
return formatter.format(values);
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
onError(new MessageFormatError("Error formatting message: \"".concat(id, "\", using ").concat(defaultMessage ? 'default message' : 'id', " as fallback."), locale, messageDescriptor, e));
|
|
86
|
-
}
|
|
87
|
-
if (defaultMessage) {
|
|
88
|
-
try {
|
|
89
|
-
var formatter = state.getMessageFormat(defaultMessage, defaultLocale, defaultFormats, opts);
|
|
90
|
-
return formatter.format(values);
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
93
|
-
onError(new MessageFormatError("Error formatting the default message for: \"".concat(id, "\", rendering message verbatim"), locale, messageDescriptor, e));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (typeof message === 'string') {
|
|
97
|
-
return message;
|
|
98
|
-
}
|
|
99
|
-
if (typeof defaultMessage === 'string') {
|
|
100
|
-
return defaultMessage;
|
|
101
|
-
}
|
|
102
|
-
return id;
|
|
103
|
-
};
|
package/lib/src/number.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Formatters, IntlFormatters, CustomFormats, OnErrorFn } from './types';
|
|
2
|
-
export declare function getFormatter({ locale, formats, onError, }: {
|
|
3
|
-
locale: string;
|
|
4
|
-
formats: CustomFormats;
|
|
5
|
-
onError: OnErrorFn;
|
|
6
|
-
}, getNumberFormat: Formatters['getNumberFormat'], options?: Parameters<IntlFormatters['formatNumber']>[1]): Intl.NumberFormat;
|
|
7
|
-
export declare function formatNumber(config: {
|
|
8
|
-
locale: string;
|
|
9
|
-
formats: CustomFormats;
|
|
10
|
-
onError: OnErrorFn;
|
|
11
|
-
}, getNumberFormat: Formatters['getNumberFormat'], value: Parameters<IntlFormatters['formatNumber']>[0], options?: Parameters<IntlFormatters['formatNumber']>[1]): string;
|
|
12
|
-
export declare function formatNumberToParts(config: {
|
|
13
|
-
locale: string;
|
|
14
|
-
formats: CustomFormats;
|
|
15
|
-
onError: OnErrorFn;
|
|
16
|
-
}, getNumberFormat: Formatters['getNumberFormat'], value: Parameters<IntlFormatters['formatNumber']>[0], options?: Parameters<IntlFormatters['formatNumber']>[1]): Intl.NumberFormatPart[];
|
|
17
|
-
//# sourceMappingURL=number.d.ts.map
|
package/lib/src/number.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AA8B5E,wBAAgB,YAAY,CAC1B,EACE,MAAM,EACN,OAAO,EACP,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IAEd,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAC9C,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAM,GAC1D,IAAI,CAAC,YAAY,CAYnB;AAED,wBAAgB,YAAY,CAC1B,MAAM,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