intl-messageformat 9.12.0 → 10.1.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/intl-messageformat.esm.js +3255 -1266
- package/intl-messageformat.iife.js +3304 -1355
- package/lib/src/core.d.ts +2 -0
- package/lib/src/core.d.ts.map +1 -1
- package/lib/src/core.js +21 -5
- package/lib/src/formatters.d.ts +15 -3
- package/lib/src/formatters.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/core.d.ts +2 -0
- package/src/core.d.ts.map +1 -1
- package/src/core.js +21 -5
- package/src/formatters.d.ts +15 -3
- package/src/formatters.d.ts.map +1 -1
package/lib/src/core.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface Options {
|
|
|
13
13
|
export declare class IntlMessageFormat {
|
|
14
14
|
private readonly ast;
|
|
15
15
|
private readonly locales;
|
|
16
|
+
private readonly resolvedLocale?;
|
|
16
17
|
private readonly formatters;
|
|
17
18
|
private readonly formats;
|
|
18
19
|
private readonly message;
|
|
@@ -26,6 +27,7 @@ export declare class IntlMessageFormat {
|
|
|
26
27
|
getAst: () => MessageFormatElement[];
|
|
27
28
|
private static memoizedDefaultLocale;
|
|
28
29
|
static get defaultLocale(): string;
|
|
30
|
+
static resolveLocale: (locales: string | string[]) => Intl.Locale | undefined;
|
|
29
31
|
static __parse: typeof parse | undefined;
|
|
30
32
|
static formats: Formats;
|
|
31
33
|
}
|
package/lib/src/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl-messageformat/src/core.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAE,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EAElB,MAAM,cAAc,CAAA;AAsCrB,MAAM,WAAW,OAAO;IACtB,UA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AO,CAAC,QAAQ,CAAC,cAAc,CAI9B;gBAEC,OAAO,EAAE,MAAM,GAAG,oBAAoB,EAAE,EACxC,OAAO,GAAE,MAAM,GAAG,MAAM,EAAoC,EAC5D,eAAe,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAClC,IAAI,CAAC,EAAE,OAAO;IAkChB,MAAM,yJAyBL;IACD,aAAa,6IAWV;IACH,eAAe;;MAIb;IACF,MAAM,+BAAiB;IACvB,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAsB;IAE1D,MAAM,KAAK,aAAa,WAOvB;IACD,MAAM,CAAC,aAAa,YACT,MAAM,GAAG,MAAM,EAAE,KACzB,KAAK,MAAM,GAAG,SAAS,CAUzB;IACD,MAAM,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,SAAS,CAAQ;IAIhD,MAAM,CAAC,OAAO,EAAE,OAAO,CAmEtB;CACF"}
|
package/lib/src/core.js
CHANGED
|
@@ -116,10 +116,17 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
116
116
|
this.formatToParts = function (values) {
|
|
117
117
|
return formatToParts(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
|
|
118
118
|
};
|
|
119
|
-
this.resolvedOptions = function () {
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
this.resolvedOptions = function () {
|
|
120
|
+
var _a;
|
|
121
|
+
return ({
|
|
122
|
+
locale: ((_a = _this.resolvedLocale) === null || _a === void 0 ? void 0 : _a.toString()) ||
|
|
123
|
+
Intl.NumberFormat.supportedLocalesOf(_this.locales)[0],
|
|
124
|
+
});
|
|
125
|
+
};
|
|
122
126
|
this.getAst = function () { return _this.ast; };
|
|
127
|
+
// Defined first because it's used to build the format pattern.
|
|
128
|
+
this.locales = locales;
|
|
129
|
+
this.resolvedLocale = IntlMessageFormat.resolveLocale(locales);
|
|
123
130
|
if (typeof message === 'string') {
|
|
124
131
|
this.message = message;
|
|
125
132
|
if (!IntlMessageFormat.__parse) {
|
|
@@ -128,6 +135,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
128
135
|
// Parse string messages into an AST.
|
|
129
136
|
this.ast = IntlMessageFormat.__parse(message, {
|
|
130
137
|
ignoreTag: opts === null || opts === void 0 ? void 0 : opts.ignoreTag,
|
|
138
|
+
locale: this.resolvedLocale,
|
|
131
139
|
});
|
|
132
140
|
}
|
|
133
141
|
else {
|
|
@@ -139,8 +147,6 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
139
147
|
// Creates a new object with the specified `formats` merged with the default
|
|
140
148
|
// formats.
|
|
141
149
|
this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
|
|
142
|
-
// Defined first because it's used to build the format pattern.
|
|
143
|
-
this.locales = locales;
|
|
144
150
|
this.formatters =
|
|
145
151
|
(opts && opts.formatters) || createDefaultFormatters(this.formatterCache);
|
|
146
152
|
}
|
|
@@ -156,6 +162,16 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
156
162
|
configurable: true
|
|
157
163
|
});
|
|
158
164
|
IntlMessageFormat.memoizedDefaultLocale = null;
|
|
165
|
+
IntlMessageFormat.resolveLocale = function (locales) {
|
|
166
|
+
if (typeof Intl.Locale === 'undefined') {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
var supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales);
|
|
170
|
+
if (supportedLocales.length > 0) {
|
|
171
|
+
return new Intl.Locale(supportedLocales[0]);
|
|
172
|
+
}
|
|
173
|
+
return new Intl.Locale(typeof locales === 'string' ? locales : locales[0]);
|
|
174
|
+
};
|
|
159
175
|
IntlMessageFormat.__parse = parse;
|
|
160
176
|
// Default format options used as the prototype of the `formats` provided to the
|
|
161
177
|
// constructor. These are used when constructing the internal Intl.NumberFormat
|
package/lib/src/formatters.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
|
|
2
2
|
import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
|
3
|
+
declare global {
|
|
4
|
+
namespace FormatjsIntl {
|
|
5
|
+
interface Message {
|
|
6
|
+
}
|
|
7
|
+
interface IntlConfig {
|
|
8
|
+
}
|
|
9
|
+
interface Formats {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
declare type Format<Source = string> = Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
|
|
3
14
|
export interface Formats {
|
|
4
|
-
number: Record<
|
|
5
|
-
date: Record<
|
|
6
|
-
time: Record<
|
|
15
|
+
number: Record<Format<'number'>, NumberFormatOptions>;
|
|
16
|
+
date: Record<Format<'date'>, Intl.DateTimeFormatOptions>;
|
|
17
|
+
time: Record<Format<'time'>, Intl.DateTimeFormatOptions>;
|
|
7
18
|
}
|
|
8
19
|
export interface FormatterCache {
|
|
9
20
|
number: Record<string, NumberFormatOptions>;
|
|
@@ -32,4 +43,5 @@ export declare type PrimitiveType = string | number | boolean | null | undefined
|
|
|
32
43
|
export declare function isFormatXMLElementFn<T>(el: PrimitiveType | T | FormatXMLElementFn<T>): el is FormatXMLElementFn<T>;
|
|
33
44
|
export declare function formatToParts<T>(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, currentPluralValue?: number, originalMessage?: string): MessageFormatPart<T>[];
|
|
34
45
|
export declare type FormatXMLElementFn<T, R = string | T | Array<string | T>> = (parts: Array<string | T>) => R;
|
|
46
|
+
export {};
|
|
35
47
|
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl-messageformat/src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAWL,oBAAoB,EAGrB,MAAM,oCAAoC,CAAA;AAS3C,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl-messageformat/src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAWL,oBAAoB,EAGrB,MAAM,oCAAoC,CAAA;AAS3C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,YAAY,CAAC;QACrB,UAAU,OAAO;SAAG;QACpB,UAAU,UAAU;SAAG;QACvB,UAAU,OAAO;SAAG;KACrB;CACF;AAED,aAAK,MAAM,CAAC,MAAM,GAAG,MAAM,IAAI,MAAM,SAAS,MAAM,YAAY,CAAC,OAAO,GACpE,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,GAC5B,MAAM,CAAA;AAEV,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,CAAA;IACrD,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAA;IACxD,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAA;CACzD;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;IAC3C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IAC7C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;CAC9C;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,CACb,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,IAAI,CAAC,EAAE,mBAAmB,GACzB,IAAI,C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CA6LxB;AAED,oBAAY,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CACtE,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KACrB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-messageformat",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"module": "lib/index.js",
|
|
32
32
|
"types": "index.d.ts",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@formatjs/ecma402-abstract": "1.11.
|
|
35
|
-
"@formatjs/fast-memoize": "1.2.
|
|
36
|
-
"@formatjs/icu-messageformat-parser": "2.
|
|
37
|
-
"tslib": "
|
|
34
|
+
"@formatjs/ecma402-abstract": "1.11.7",
|
|
35
|
+
"@formatjs/fast-memoize": "1.2.4",
|
|
36
|
+
"@formatjs/icu-messageformat-parser": "2.1.3",
|
|
37
|
+
"tslib": "2.4.0"
|
|
38
38
|
},
|
|
39
39
|
"sideEffects": false,
|
|
40
40
|
"homepage": "https://github.com/formatjs/formatjs",
|
package/src/core.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface Options {
|
|
|
13
13
|
export declare class IntlMessageFormat {
|
|
14
14
|
private readonly ast;
|
|
15
15
|
private readonly locales;
|
|
16
|
+
private readonly resolvedLocale?;
|
|
16
17
|
private readonly formatters;
|
|
17
18
|
private readonly formats;
|
|
18
19
|
private readonly message;
|
|
@@ -26,6 +27,7 @@ export declare class IntlMessageFormat {
|
|
|
26
27
|
getAst: () => MessageFormatElement[];
|
|
27
28
|
private static memoizedDefaultLocale;
|
|
28
29
|
static get defaultLocale(): string;
|
|
30
|
+
static resolveLocale: (locales: string | string[]) => Intl.Locale | undefined;
|
|
29
31
|
static __parse: typeof parse | undefined;
|
|
30
32
|
static formats: Formats;
|
|
31
33
|
}
|
package/src/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-messageformat/src/core.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAE,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EAElB,MAAM,cAAc,CAAA;AAsCrB,MAAM,WAAW,OAAO;IACtB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAwCD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAI9B;gBAEC,OAAO,EAAE,MAAM,GAAG,oBAAoB,EAAE,EACxC,OAAO,GAAE,MAAM,GAAG,MAAM,EAAoC,EAC5D,eAAe,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAClC,IAAI,CAAC,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-messageformat/src/core.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAE,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EAElB,MAAM,cAAc,CAAA;AAsCrB,MAAM,WAAW,OAAO;IACtB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAwCD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAa;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAI9B;gBAEC,OAAO,EAAE,MAAM,GAAG,oBAAoB,EAAE,EACxC,OAAO,GAAE,MAAM,GAAG,MAAM,EAAoC,EAC5D,eAAe,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAClC,IAAI,CAAC,EAAE,OAAO;IAkChB,MAAM,yJAyBL;IACD,aAAa,6IAWV;IACH,eAAe;;MAIb;IACF,MAAM,+BAAiB;IACvB,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAsB;IAE1D,MAAM,KAAK,aAAa,WAOvB;IACD,MAAM,CAAC,aAAa,YACT,MAAM,GAAG,MAAM,EAAE,KACzB,KAAK,MAAM,GAAG,SAAS,CAUzB;IACD,MAAM,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,SAAS,CAAQ;IAIhD,MAAM,CAAC,OAAO,EAAE,OAAO,CAmEtB;CACF"}
|
package/src/core.js
CHANGED
|
@@ -119,10 +119,17 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
119
119
|
this.formatToParts = function (values) {
|
|
120
120
|
return (0, formatters_1.formatToParts)(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
|
|
121
121
|
};
|
|
122
|
-
this.resolvedOptions = function () {
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
this.resolvedOptions = function () {
|
|
123
|
+
var _a;
|
|
124
|
+
return ({
|
|
125
|
+
locale: ((_a = _this.resolvedLocale) === null || _a === void 0 ? void 0 : _a.toString()) ||
|
|
126
|
+
Intl.NumberFormat.supportedLocalesOf(_this.locales)[0],
|
|
127
|
+
});
|
|
128
|
+
};
|
|
125
129
|
this.getAst = function () { return _this.ast; };
|
|
130
|
+
// Defined first because it's used to build the format pattern.
|
|
131
|
+
this.locales = locales;
|
|
132
|
+
this.resolvedLocale = IntlMessageFormat.resolveLocale(locales);
|
|
126
133
|
if (typeof message === 'string') {
|
|
127
134
|
this.message = message;
|
|
128
135
|
if (!IntlMessageFormat.__parse) {
|
|
@@ -131,6 +138,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
131
138
|
// Parse string messages into an AST.
|
|
132
139
|
this.ast = IntlMessageFormat.__parse(message, {
|
|
133
140
|
ignoreTag: opts === null || opts === void 0 ? void 0 : opts.ignoreTag,
|
|
141
|
+
locale: this.resolvedLocale,
|
|
134
142
|
});
|
|
135
143
|
}
|
|
136
144
|
else {
|
|
@@ -142,8 +150,6 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
142
150
|
// Creates a new object with the specified `formats` merged with the default
|
|
143
151
|
// formats.
|
|
144
152
|
this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
|
|
145
|
-
// Defined first because it's used to build the format pattern.
|
|
146
|
-
this.locales = locales;
|
|
147
153
|
this.formatters =
|
|
148
154
|
(opts && opts.formatters) || createDefaultFormatters(this.formatterCache);
|
|
149
155
|
}
|
|
@@ -159,6 +165,16 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
159
165
|
configurable: true
|
|
160
166
|
});
|
|
161
167
|
IntlMessageFormat.memoizedDefaultLocale = null;
|
|
168
|
+
IntlMessageFormat.resolveLocale = function (locales) {
|
|
169
|
+
if (typeof Intl.Locale === 'undefined') {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
var supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales);
|
|
173
|
+
if (supportedLocales.length > 0) {
|
|
174
|
+
return new Intl.Locale(supportedLocales[0]);
|
|
175
|
+
}
|
|
176
|
+
return new Intl.Locale(typeof locales === 'string' ? locales : locales[0]);
|
|
177
|
+
};
|
|
162
178
|
IntlMessageFormat.__parse = icu_messageformat_parser_1.parse;
|
|
163
179
|
// Default format options used as the prototype of the `formats` provided to the
|
|
164
180
|
// constructor. These are used when constructing the internal Intl.NumberFormat
|
package/src/formatters.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
|
|
2
2
|
import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
|
3
|
+
declare global {
|
|
4
|
+
namespace FormatjsIntl {
|
|
5
|
+
interface Message {
|
|
6
|
+
}
|
|
7
|
+
interface IntlConfig {
|
|
8
|
+
}
|
|
9
|
+
interface Formats {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
declare type Format<Source = string> = Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
|
|
3
14
|
export interface Formats {
|
|
4
|
-
number: Record<
|
|
5
|
-
date: Record<
|
|
6
|
-
time: Record<
|
|
15
|
+
number: Record<Format<'number'>, NumberFormatOptions>;
|
|
16
|
+
date: Record<Format<'date'>, Intl.DateTimeFormatOptions>;
|
|
17
|
+
time: Record<Format<'time'>, Intl.DateTimeFormatOptions>;
|
|
7
18
|
}
|
|
8
19
|
export interface FormatterCache {
|
|
9
20
|
number: Record<string, NumberFormatOptions>;
|
|
@@ -32,4 +43,5 @@ export declare type PrimitiveType = string | number | boolean | null | undefined
|
|
|
32
43
|
export declare function isFormatXMLElementFn<T>(el: PrimitiveType | T | FormatXMLElementFn<T>): el is FormatXMLElementFn<T>;
|
|
33
44
|
export declare function formatToParts<T>(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, currentPluralValue?: number, originalMessage?: string): MessageFormatPart<T>[];
|
|
34
45
|
export declare type FormatXMLElementFn<T, R = string | T | Array<string | T>> = (parts: Array<string | T>) => R;
|
|
46
|
+
export {};
|
|
35
47
|
//# sourceMappingURL=formatters.d.ts.map
|
package/src/formatters.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-messageformat/src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAWL,oBAAoB,EAGrB,MAAM,oCAAoC,CAAA;AAS3C,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-messageformat/src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAWL,oBAAoB,EAGrB,MAAM,oCAAoC,CAAA;AAS3C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,YAAY,CAAC;QACrB,UAAU,OAAO;SAAG;QACpB,UAAU,UAAU;SAAG;QACvB,UAAU,OAAO;SAAG;KACrB;CACF;AAED,aAAK,MAAM,CAAC,MAAM,GAAG,MAAM,IAAI,MAAM,SAAS,MAAM,YAAY,CAAC,OAAO,GACpE,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,GAC5B,MAAM,CAAA;AAEV,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,CAAA;IACrD,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,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