intl-messageformat 9.4.6 → 9.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/intl-messageformat.iife.js +3883 -0
- package/lib/src/core.d.ts +4 -59
- package/lib/src/core.d.ts.map +1 -1
- package/lib/src/core.js +6 -6
- package/lib/src/error.d.ts +1 -1
- package/lib/src/error.d.ts.map +1 -1
- package/lib/src/error.js +3 -3
- package/lib/src/formatters.d.ts +1 -1
- package/lib/src/formatters.d.ts.map +1 -1
- package/lib/src/formatters.js +12 -12
- package/package.json +2 -2
- package/src/core.d.ts +4 -59
- package/src/core.d.ts.map +1 -1
- package/src/core.js +4 -4
- package/src/error.d.ts +1 -1
- package/src/error.d.ts.map +1 -1
- package/src/error.js +3 -3
- package/src/formatters.d.ts +1 -1
- package/src/formatters.d.ts.map +1 -1
- package/src/formatters.js +11 -11
- package/intl-messageformat.umd.js +0 -4252
- package/intl-messageformat.umd.min.js +0 -15
package/lib/src/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse, MessageFormatElement } from 'intl-messageformat-parser';
|
|
2
|
-
import { Formatters, Formats, FormatXMLElementFn, MessageFormatPart } from './formatters';
|
|
2
|
+
import { Formatters, Formats, FormatXMLElementFn, PrimitiveType, MessageFormatPart } from './formatters';
|
|
3
3
|
export interface Options {
|
|
4
4
|
formatters?: Formatters;
|
|
5
5
|
/**
|
|
@@ -18,8 +18,8 @@ export declare class IntlMessageFormat {
|
|
|
18
18
|
private readonly message;
|
|
19
19
|
private readonly formatterCache;
|
|
20
20
|
constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
|
|
21
|
-
format: <T = void>(values?: Record<string,
|
|
22
|
-
formatToParts: <T>(values?: Record<string,
|
|
21
|
+
format: <T = void>(values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) => string | T | (string | T)[];
|
|
22
|
+
formatToParts: <T>(values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) => MessageFormatPart<T>[];
|
|
23
23
|
resolvedOptions: () => {
|
|
24
24
|
locale: string;
|
|
25
25
|
};
|
|
@@ -27,61 +27,6 @@ export declare class IntlMessageFormat {
|
|
|
27
27
|
private static memoizedDefaultLocale;
|
|
28
28
|
static get defaultLocale(): string;
|
|
29
29
|
static __parse: typeof parse | undefined;
|
|
30
|
-
static formats:
|
|
31
|
-
number: {
|
|
32
|
-
currency: {
|
|
33
|
-
style: string;
|
|
34
|
-
};
|
|
35
|
-
percent: {
|
|
36
|
-
style: string;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
date: {
|
|
40
|
-
short: {
|
|
41
|
-
month: string;
|
|
42
|
-
day: string;
|
|
43
|
-
year: string;
|
|
44
|
-
};
|
|
45
|
-
medium: {
|
|
46
|
-
month: string;
|
|
47
|
-
day: string;
|
|
48
|
-
year: string;
|
|
49
|
-
};
|
|
50
|
-
long: {
|
|
51
|
-
month: string;
|
|
52
|
-
day: string;
|
|
53
|
-
year: string;
|
|
54
|
-
};
|
|
55
|
-
full: {
|
|
56
|
-
weekday: string;
|
|
57
|
-
month: string;
|
|
58
|
-
day: string;
|
|
59
|
-
year: string;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
time: {
|
|
63
|
-
short: {
|
|
64
|
-
hour: string;
|
|
65
|
-
minute: string;
|
|
66
|
-
};
|
|
67
|
-
medium: {
|
|
68
|
-
hour: string;
|
|
69
|
-
minute: string;
|
|
70
|
-
second: string;
|
|
71
|
-
};
|
|
72
|
-
long: {
|
|
73
|
-
hour: string;
|
|
74
|
-
minute: string;
|
|
75
|
-
second: string;
|
|
76
|
-
timeZoneName: string;
|
|
77
|
-
};
|
|
78
|
-
full: {
|
|
79
|
-
hour: string;
|
|
80
|
-
minute: string;
|
|
81
|
-
second: string;
|
|
82
|
-
timeZoneName: string;
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
};
|
|
30
|
+
static formats: Formats;
|
|
86
31
|
}
|
|
87
32
|
//# sourceMappingURL=core.d.ts.map
|
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,2BAA2B,CAAC;AAGtE,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,
|
|
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,2BAA2B,CAAC;AAGtE,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EAElB,MAAM,cAAc,CAAC;AAsCtB,MAAM,WAAW,OAAO;IACtB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAkDD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAyB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAI7B;gBAEA,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;IAiChB,MAAM,yJAyBJ;IACF,aAAa,6IAWT;IACJ,eAAe;;MAEZ;IACH,MAAM,+BAAkB;IACxB,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAuB;IAE3D,MAAM,KAAK,aAAa,WAMvB;IACD,MAAM,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,SAAS,CAAS;IAIjD,MAAM,CAAC,OAAO,EAAE,OAAO,CAgErB;CACH"}
|
package/lib/src/core.js
CHANGED
|
@@ -3,10 +3,10 @@ Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
|
3
3
|
Copyrights licensed under the New BSD License.
|
|
4
4
|
See the accompanying LICENSE file for terms.
|
|
5
5
|
*/
|
|
6
|
-
import { __assign,
|
|
6
|
+
import { __assign, __spreadArray } from "tslib";
|
|
7
7
|
import { parse } from 'intl-messageformat-parser';
|
|
8
8
|
import * as memoize from 'fast-memoize';
|
|
9
|
-
import { formatToParts, } from './formatters';
|
|
9
|
+
import { formatToParts, PART_TYPE, } from './formatters';
|
|
10
10
|
// -- MessageFormat --------------------------------------------------------
|
|
11
11
|
function mergeConfig(c1, c2) {
|
|
12
12
|
if (!c2) {
|
|
@@ -59,7 +59,7 @@ function createDefaultFormatters(cache) {
|
|
|
59
59
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
60
60
|
args[_i] = arguments[_i];
|
|
61
61
|
}
|
|
62
|
-
return new ((_a = Intl.NumberFormat).bind.apply(_a,
|
|
62
|
+
return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args)))();
|
|
63
63
|
}, {
|
|
64
64
|
cache: createFastMemoizeCache(cache.number),
|
|
65
65
|
strategy: memoizeIntl.strategies.variadic,
|
|
@@ -70,7 +70,7 @@ function createDefaultFormatters(cache) {
|
|
|
70
70
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
71
71
|
args[_i] = arguments[_i];
|
|
72
72
|
}
|
|
73
|
-
return new ((_a = Intl.DateTimeFormat).bind.apply(_a,
|
|
73
|
+
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args)))();
|
|
74
74
|
}, {
|
|
75
75
|
cache: createFastMemoizeCache(cache.dateTime),
|
|
76
76
|
strategy: memoizeIntl.strategies.variadic,
|
|
@@ -81,7 +81,7 @@ function createDefaultFormatters(cache) {
|
|
|
81
81
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
82
82
|
args[_i] = arguments[_i];
|
|
83
83
|
}
|
|
84
|
-
return new ((_a = Intl.PluralRules).bind.apply(_a,
|
|
84
|
+
return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args)))();
|
|
85
85
|
}, {
|
|
86
86
|
cache: createFastMemoizeCache(cache.pluralRules),
|
|
87
87
|
strategy: memoizeIntl.strategies.variadic,
|
|
@@ -105,7 +105,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
105
105
|
}
|
|
106
106
|
var result = parts.reduce(function (all, part) {
|
|
107
107
|
if (!all.length ||
|
|
108
|
-
part.type !==
|
|
108
|
+
part.type !== PART_TYPE.literal ||
|
|
109
109
|
typeof all[all.length - 1] !== 'string') {
|
|
110
110
|
all.push(part.value);
|
|
111
111
|
}
|
package/lib/src/error.d.ts
CHANGED
package/lib/src/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl-messageformat/src/error.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl-messageformat/src/error.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IAEnB,aAAa,kBAAkB;IAE/B,aAAa,kBAAkB;IAE/B,gBAAgB,qBAAqB;CACtC;AAED,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,IAAI,EAAE,SAAS,CAAC;IAChC;;;;;;OAMG;IACH,SAAgB,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;gBACxC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,CAAC,EAAE,MAAM;IAK3D,QAAQ;CAGhB;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBAE9C,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,MAAM,EAAE,EACjB,eAAe,CAAC,EAAE,MAAM;CAU3B;AAED,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM;CAO/D;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,UAAU,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM;CAOzD"}
|
package/lib/src/error.js
CHANGED
|
@@ -25,7 +25,7 @@ export { FormatError };
|
|
|
25
25
|
var InvalidValueError = /** @class */ (function (_super) {
|
|
26
26
|
__extends(InvalidValueError, _super);
|
|
27
27
|
function InvalidValueError(variableId, value, options, originalMessage) {
|
|
28
|
-
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"",
|
|
28
|
+
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
29
29
|
}
|
|
30
30
|
return InvalidValueError;
|
|
31
31
|
}(FormatError));
|
|
@@ -33,7 +33,7 @@ export { InvalidValueError };
|
|
|
33
33
|
var InvalidValueTypeError = /** @class */ (function (_super) {
|
|
34
34
|
__extends(InvalidValueTypeError, _super);
|
|
35
35
|
function InvalidValueTypeError(value, type, originalMessage) {
|
|
36
|
-
return _super.call(this, "Value for \"" + value + "\" must be of type " + type,
|
|
36
|
+
return _super.call(this, "Value for \"" + value + "\" must be of type " + type, ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
37
37
|
}
|
|
38
38
|
return InvalidValueTypeError;
|
|
39
39
|
}(FormatError));
|
|
@@ -41,7 +41,7 @@ export { InvalidValueTypeError };
|
|
|
41
41
|
var MissingValueError = /** @class */ (function (_super) {
|
|
42
42
|
__extends(MissingValueError, _super);
|
|
43
43
|
function MissingValueError(variableId, originalMessage) {
|
|
44
|
-
return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"",
|
|
44
|
+
return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"", ErrorCode.MISSING_VALUE, originalMessage) || this;
|
|
45
45
|
}
|
|
46
46
|
return MissingValueError;
|
|
47
47
|
}(FormatError));
|
package/lib/src/formatters.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface Formatters {
|
|
|
14
14
|
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
|
|
15
15
|
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
|
|
16
16
|
}
|
|
17
|
-
export declare
|
|
17
|
+
export declare enum PART_TYPE {
|
|
18
18
|
literal = 0,
|
|
19
19
|
object = 1
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl-messageformat/src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,oBAAoB,EAGrB,MAAM,2BAA2B,CAAC;AASnC,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IAC9C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,CACb,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,IAAI,CAAC,YAAY,CAAC,GACvD,IAAI,CAAC,YAAY,CAAC;IACrB,iBAAiB,CACf,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,IAAI,CAAC,cAAc,CAAC,GACzD,IAAI,CAAC,cAAc,CAAC;IACvB,cAAc,CACZ,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,GACtD,IAAI,CAAC,WAAW,CAAC;CACrB;AAED,
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl-messageformat/src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,oBAAoB,EAGrB,MAAM,2BAA2B,CAAC;AASnC,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IAC9C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,CACb,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,IAAI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iBAAiB,CAAC,CAAC,CAAC,EAAE,CAgMxB;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,CAAC"}
|
package/lib/src/formatters.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isArgumentElement, isDateElement, isDateTimeSkeleton, isLiteralElement, isNumberElement, isNumberSkeleton, isPluralElement, isPoundElement, isSelectElement, isTimeElement, isTagElement, } from 'intl-messageformat-parser';
|
|
2
|
-
import { MissingValueError, InvalidValueError, FormatError, InvalidValueTypeError, } from './error';
|
|
2
|
+
import { MissingValueError, InvalidValueError, ErrorCode, FormatError, InvalidValueTypeError, } from './error';
|
|
3
3
|
export var PART_TYPE;
|
|
4
4
|
(function (PART_TYPE) {
|
|
5
5
|
PART_TYPE[PART_TYPE["literal"] = 0] = "literal";
|
|
@@ -12,8 +12,8 @@ function mergeLiteral(parts) {
|
|
|
12
12
|
return parts.reduce(function (all, part) {
|
|
13
13
|
var lastPart = all[all.length - 1];
|
|
14
14
|
if (!lastPart ||
|
|
15
|
-
lastPart.type !==
|
|
16
|
-
part.type !==
|
|
15
|
+
lastPart.type !== PART_TYPE.literal ||
|
|
16
|
+
part.type !== PART_TYPE.literal) {
|
|
17
17
|
all.push(part);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
@@ -33,7 +33,7 @@ originalMessage) {
|
|
|
33
33
|
if (els.length === 1 && isLiteralElement(els[0])) {
|
|
34
34
|
return [
|
|
35
35
|
{
|
|
36
|
-
type:
|
|
36
|
+
type: PART_TYPE.literal,
|
|
37
37
|
value: els[0].value,
|
|
38
38
|
},
|
|
39
39
|
];
|
|
@@ -44,7 +44,7 @@ originalMessage) {
|
|
|
44
44
|
// Exit early for string parts.
|
|
45
45
|
if (isLiteralElement(el)) {
|
|
46
46
|
result.push({
|
|
47
|
-
type:
|
|
47
|
+
type: PART_TYPE.literal,
|
|
48
48
|
value: el.value,
|
|
49
49
|
});
|
|
50
50
|
continue;
|
|
@@ -54,7 +54,7 @@ originalMessage) {
|
|
|
54
54
|
if (isPoundElement(el)) {
|
|
55
55
|
if (typeof currentPluralValue === 'number') {
|
|
56
56
|
result.push({
|
|
57
|
-
type:
|
|
57
|
+
type: PART_TYPE.literal,
|
|
58
58
|
value: formatters.getNumberFormat(locales).format(currentPluralValue),
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -74,7 +74,7 @@ originalMessage) {
|
|
|
74
74
|
: '';
|
|
75
75
|
}
|
|
76
76
|
result.push({
|
|
77
|
-
type: typeof value === 'string' ?
|
|
77
|
+
type: typeof value === 'string' ? PART_TYPE.literal : PART_TYPE.object,
|
|
78
78
|
value: value,
|
|
79
79
|
});
|
|
80
80
|
continue;
|
|
@@ -89,7 +89,7 @@ originalMessage) {
|
|
|
89
89
|
? el.style.parsedOptions
|
|
90
90
|
: undefined;
|
|
91
91
|
result.push({
|
|
92
|
-
type:
|
|
92
|
+
type: PART_TYPE.literal,
|
|
93
93
|
value: formatters
|
|
94
94
|
.getDateTimeFormat(locales, style)
|
|
95
95
|
.format(value),
|
|
@@ -103,7 +103,7 @@ originalMessage) {
|
|
|
103
103
|
? el.style.parsedOptions
|
|
104
104
|
: undefined;
|
|
105
105
|
result.push({
|
|
106
|
-
type:
|
|
106
|
+
type: PART_TYPE.literal,
|
|
107
107
|
value: formatters
|
|
108
108
|
.getDateTimeFormat(locales, style)
|
|
109
109
|
.format(value),
|
|
@@ -122,7 +122,7 @@ originalMessage) {
|
|
|
122
122
|
(style.scale || 1);
|
|
123
123
|
}
|
|
124
124
|
result.push({
|
|
125
|
-
type:
|
|
125
|
+
type: PART_TYPE.literal,
|
|
126
126
|
value: formatters
|
|
127
127
|
.getNumberFormat(locales, style)
|
|
128
128
|
.format(value),
|
|
@@ -142,7 +142,7 @@ originalMessage) {
|
|
|
142
142
|
}
|
|
143
143
|
result.push.apply(result, chunks.map(function (c) {
|
|
144
144
|
return {
|
|
145
|
-
type: typeof c === 'string' ?
|
|
145
|
+
type: typeof c === 'string' ? PART_TYPE.literal : PART_TYPE.object,
|
|
146
146
|
value: c,
|
|
147
147
|
};
|
|
148
148
|
}));
|
|
@@ -159,7 +159,7 @@ originalMessage) {
|
|
|
159
159
|
var opt = el.options["=" + value];
|
|
160
160
|
if (!opt) {
|
|
161
161
|
if (!Intl.PluralRules) {
|
|
162
|
-
throw new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n",
|
|
162
|
+
throw new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", ErrorCode.MISSING_INTL_API, originalMessage);
|
|
163
163
|
}
|
|
164
164
|
var rule = formatters
|
|
165
165
|
.getPluralRules(locales, { type: el.pluralType })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-messageformat",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.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",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"types": "index.d.ts",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"fast-memoize": "^2.5.2",
|
|
35
|
-
"intl-messageformat-parser": "6.
|
|
35
|
+
"intl-messageformat-parser": "6.4.0",
|
|
36
36
|
"tslib": "^2.0.1"
|
|
37
37
|
},
|
|
38
38
|
"sideEffects": false,
|
package/src/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse, MessageFormatElement } from 'intl-messageformat-parser';
|
|
2
|
-
import { Formatters, Formats, FormatXMLElementFn, MessageFormatPart } from './formatters';
|
|
2
|
+
import { Formatters, Formats, FormatXMLElementFn, PrimitiveType, MessageFormatPart } from './formatters';
|
|
3
3
|
export interface Options {
|
|
4
4
|
formatters?: Formatters;
|
|
5
5
|
/**
|
|
@@ -18,8 +18,8 @@ export declare class IntlMessageFormat {
|
|
|
18
18
|
private readonly message;
|
|
19
19
|
private readonly formatterCache;
|
|
20
20
|
constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
|
|
21
|
-
format: <T = void>(values?: Record<string,
|
|
22
|
-
formatToParts: <T>(values?: Record<string,
|
|
21
|
+
format: <T = void>(values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) => string | T | (string | T)[];
|
|
22
|
+
formatToParts: <T>(values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) => MessageFormatPart<T>[];
|
|
23
23
|
resolvedOptions: () => {
|
|
24
24
|
locale: string;
|
|
25
25
|
};
|
|
@@ -27,61 +27,6 @@ export declare class IntlMessageFormat {
|
|
|
27
27
|
private static memoizedDefaultLocale;
|
|
28
28
|
static get defaultLocale(): string;
|
|
29
29
|
static __parse: typeof parse | undefined;
|
|
30
|
-
static formats:
|
|
31
|
-
number: {
|
|
32
|
-
currency: {
|
|
33
|
-
style: string;
|
|
34
|
-
};
|
|
35
|
-
percent: {
|
|
36
|
-
style: string;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
date: {
|
|
40
|
-
short: {
|
|
41
|
-
month: string;
|
|
42
|
-
day: string;
|
|
43
|
-
year: string;
|
|
44
|
-
};
|
|
45
|
-
medium: {
|
|
46
|
-
month: string;
|
|
47
|
-
day: string;
|
|
48
|
-
year: string;
|
|
49
|
-
};
|
|
50
|
-
long: {
|
|
51
|
-
month: string;
|
|
52
|
-
day: string;
|
|
53
|
-
year: string;
|
|
54
|
-
};
|
|
55
|
-
full: {
|
|
56
|
-
weekday: string;
|
|
57
|
-
month: string;
|
|
58
|
-
day: string;
|
|
59
|
-
year: string;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
time: {
|
|
63
|
-
short: {
|
|
64
|
-
hour: string;
|
|
65
|
-
minute: string;
|
|
66
|
-
};
|
|
67
|
-
medium: {
|
|
68
|
-
hour: string;
|
|
69
|
-
minute: string;
|
|
70
|
-
second: string;
|
|
71
|
-
};
|
|
72
|
-
long: {
|
|
73
|
-
hour: string;
|
|
74
|
-
minute: string;
|
|
75
|
-
second: string;
|
|
76
|
-
timeZoneName: string;
|
|
77
|
-
};
|
|
78
|
-
full: {
|
|
79
|
-
hour: string;
|
|
80
|
-
minute: string;
|
|
81
|
-
second: string;
|
|
82
|
-
timeZoneName: string;
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
};
|
|
30
|
+
static formats: Formats;
|
|
86
31
|
}
|
|
87
32
|
//# sourceMappingURL=core.d.ts.map
|
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,2BAA2B,CAAC;AAGtE,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,
|
|
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,2BAA2B,CAAC;AAGtE,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EAElB,MAAM,cAAc,CAAC;AAsCtB,MAAM,WAAW,OAAO;IACtB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAkDD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAyB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAI7B;gBAEA,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;IAiChB,MAAM,yJAyBJ;IACF,aAAa,6IAWT;IACJ,eAAe;;MAEZ;IACH,MAAM,+BAAkB;IACxB,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAuB;IAE3D,MAAM,KAAK,aAAa,WAMvB;IACD,MAAM,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,SAAS,CAAS;IAIjD,MAAM,CAAC,OAAO,EAAE,OAAO,CAgErB;CACH"}
|
package/src/core.js
CHANGED
|
@@ -62,7 +62,7 @@ function createDefaultFormatters(cache) {
|
|
|
62
62
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
63
63
|
args[_i] = arguments[_i];
|
|
64
64
|
}
|
|
65
|
-
return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.
|
|
65
|
+
return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
|
|
66
66
|
}, {
|
|
67
67
|
cache: createFastMemoizeCache(cache.number),
|
|
68
68
|
strategy: memoizeIntl.strategies.variadic,
|
|
@@ -73,7 +73,7 @@ function createDefaultFormatters(cache) {
|
|
|
73
73
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
74
74
|
args[_i] = arguments[_i];
|
|
75
75
|
}
|
|
76
|
-
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.
|
|
76
|
+
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
|
|
77
77
|
}, {
|
|
78
78
|
cache: createFastMemoizeCache(cache.dateTime),
|
|
79
79
|
strategy: memoizeIntl.strategies.variadic,
|
|
@@ -84,7 +84,7 @@ function createDefaultFormatters(cache) {
|
|
|
84
84
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
85
85
|
args[_i] = arguments[_i];
|
|
86
86
|
}
|
|
87
|
-
return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.
|
|
87
|
+
return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
|
|
88
88
|
}, {
|
|
89
89
|
cache: createFastMemoizeCache(cache.pluralRules),
|
|
90
90
|
strategy: memoizeIntl.strategies.variadic,
|
|
@@ -108,7 +108,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
108
108
|
}
|
|
109
109
|
var result = parts.reduce(function (all, part) {
|
|
110
110
|
if (!all.length ||
|
|
111
|
-
part.type !==
|
|
111
|
+
part.type !== formatters_1.PART_TYPE.literal ||
|
|
112
112
|
typeof all[all.length - 1] !== 'string') {
|
|
113
113
|
all.push(part.value);
|
|
114
114
|
}
|
package/src/error.d.ts
CHANGED
package/src/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-messageformat/src/error.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-messageformat/src/error.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IAEnB,aAAa,kBAAkB;IAE/B,aAAa,kBAAkB;IAE/B,gBAAgB,qBAAqB;CACtC;AAED,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,IAAI,EAAE,SAAS,CAAC;IAChC;;;;;;OAMG;IACH,SAAgB,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;gBACxC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,CAAC,EAAE,MAAM;IAK3D,QAAQ;CAGhB;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBAE9C,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,MAAM,EAAE,EACjB,eAAe,CAAC,EAAE,MAAM;CAU3B;AAED,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM;CAO/D;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,UAAU,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM;CAOzD"}
|
package/src/error.js
CHANGED
|
@@ -28,7 +28,7 @@ exports.FormatError = FormatError;
|
|
|
28
28
|
var InvalidValueError = /** @class */ (function (_super) {
|
|
29
29
|
tslib_1.__extends(InvalidValueError, _super);
|
|
30
30
|
function InvalidValueError(variableId, value, options, originalMessage) {
|
|
31
|
-
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"",
|
|
31
|
+
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
32
32
|
}
|
|
33
33
|
return InvalidValueError;
|
|
34
34
|
}(FormatError));
|
|
@@ -36,7 +36,7 @@ exports.InvalidValueError = InvalidValueError;
|
|
|
36
36
|
var InvalidValueTypeError = /** @class */ (function (_super) {
|
|
37
37
|
tslib_1.__extends(InvalidValueTypeError, _super);
|
|
38
38
|
function InvalidValueTypeError(value, type, originalMessage) {
|
|
39
|
-
return _super.call(this, "Value for \"" + value + "\" must be of type " + type,
|
|
39
|
+
return _super.call(this, "Value for \"" + value + "\" must be of type " + type, ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
40
40
|
}
|
|
41
41
|
return InvalidValueTypeError;
|
|
42
42
|
}(FormatError));
|
|
@@ -44,7 +44,7 @@ exports.InvalidValueTypeError = InvalidValueTypeError;
|
|
|
44
44
|
var MissingValueError = /** @class */ (function (_super) {
|
|
45
45
|
tslib_1.__extends(MissingValueError, _super);
|
|
46
46
|
function MissingValueError(variableId, originalMessage) {
|
|
47
|
-
return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"",
|
|
47
|
+
return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"", ErrorCode.MISSING_VALUE, originalMessage) || this;
|
|
48
48
|
}
|
|
49
49
|
return MissingValueError;
|
|
50
50
|
}(FormatError));
|
package/src/formatters.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface Formatters {
|
|
|
14
14
|
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
|
|
15
15
|
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
|
|
16
16
|
}
|
|
17
|
-
export declare
|
|
17
|
+
export declare enum PART_TYPE {
|
|
18
18
|
literal = 0,
|
|
19
19
|
object = 1
|
|
20
20
|
}
|
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,EAWL,oBAAoB,EAGrB,MAAM,2BAA2B,CAAC;AASnC,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;CAClD;AAED,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GAAG,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAClE,kBAAkB,CAAC,EAAE,MAAM,EAE3B,eAAe,CAAC,EAAE,MAAM,GACvB,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAgMxB;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,CAAC"}
|
package/src/formatters.js
CHANGED
|
@@ -15,8 +15,8 @@ function mergeLiteral(parts) {
|
|
|
15
15
|
return parts.reduce(function (all, part) {
|
|
16
16
|
var lastPart = all[all.length - 1];
|
|
17
17
|
if (!lastPart ||
|
|
18
|
-
lastPart.type !==
|
|
19
|
-
part.type !==
|
|
18
|
+
lastPart.type !== PART_TYPE.literal ||
|
|
19
|
+
part.type !== PART_TYPE.literal) {
|
|
20
20
|
all.push(part);
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
@@ -37,7 +37,7 @@ originalMessage) {
|
|
|
37
37
|
if (els.length === 1 && intl_messageformat_parser_1.isLiteralElement(els[0])) {
|
|
38
38
|
return [
|
|
39
39
|
{
|
|
40
|
-
type:
|
|
40
|
+
type: PART_TYPE.literal,
|
|
41
41
|
value: els[0].value,
|
|
42
42
|
},
|
|
43
43
|
];
|
|
@@ -48,7 +48,7 @@ originalMessage) {
|
|
|
48
48
|
// Exit early for string parts.
|
|
49
49
|
if (intl_messageformat_parser_1.isLiteralElement(el)) {
|
|
50
50
|
result.push({
|
|
51
|
-
type:
|
|
51
|
+
type: PART_TYPE.literal,
|
|
52
52
|
value: el.value,
|
|
53
53
|
});
|
|
54
54
|
continue;
|
|
@@ -58,7 +58,7 @@ originalMessage) {
|
|
|
58
58
|
if (intl_messageformat_parser_1.isPoundElement(el)) {
|
|
59
59
|
if (typeof currentPluralValue === 'number') {
|
|
60
60
|
result.push({
|
|
61
|
-
type:
|
|
61
|
+
type: PART_TYPE.literal,
|
|
62
62
|
value: formatters.getNumberFormat(locales).format(currentPluralValue),
|
|
63
63
|
});
|
|
64
64
|
}
|
|
@@ -78,7 +78,7 @@ originalMessage) {
|
|
|
78
78
|
: '';
|
|
79
79
|
}
|
|
80
80
|
result.push({
|
|
81
|
-
type: typeof value === 'string' ?
|
|
81
|
+
type: typeof value === 'string' ? PART_TYPE.literal : PART_TYPE.object,
|
|
82
82
|
value: value,
|
|
83
83
|
});
|
|
84
84
|
continue;
|
|
@@ -93,7 +93,7 @@ originalMessage) {
|
|
|
93
93
|
? el.style.parsedOptions
|
|
94
94
|
: undefined;
|
|
95
95
|
result.push({
|
|
96
|
-
type:
|
|
96
|
+
type: PART_TYPE.literal,
|
|
97
97
|
value: formatters
|
|
98
98
|
.getDateTimeFormat(locales, style)
|
|
99
99
|
.format(value),
|
|
@@ -107,7 +107,7 @@ originalMessage) {
|
|
|
107
107
|
? el.style.parsedOptions
|
|
108
108
|
: undefined;
|
|
109
109
|
result.push({
|
|
110
|
-
type:
|
|
110
|
+
type: PART_TYPE.literal,
|
|
111
111
|
value: formatters
|
|
112
112
|
.getDateTimeFormat(locales, style)
|
|
113
113
|
.format(value),
|
|
@@ -126,7 +126,7 @@ originalMessage) {
|
|
|
126
126
|
(style.scale || 1);
|
|
127
127
|
}
|
|
128
128
|
result.push({
|
|
129
|
-
type:
|
|
129
|
+
type: PART_TYPE.literal,
|
|
130
130
|
value: formatters
|
|
131
131
|
.getNumberFormat(locales, style)
|
|
132
132
|
.format(value),
|
|
@@ -146,7 +146,7 @@ originalMessage) {
|
|
|
146
146
|
}
|
|
147
147
|
result.push.apply(result, chunks.map(function (c) {
|
|
148
148
|
return {
|
|
149
|
-
type: typeof c === 'string' ?
|
|
149
|
+
type: typeof c === 'string' ? PART_TYPE.literal : PART_TYPE.object,
|
|
150
150
|
value: c,
|
|
151
151
|
};
|
|
152
152
|
}));
|
|
@@ -163,7 +163,7 @@ originalMessage) {
|
|
|
163
163
|
var opt = el.options["=" + value];
|
|
164
164
|
if (!opt) {
|
|
165
165
|
if (!Intl.PluralRules) {
|
|
166
|
-
throw new error_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n",
|
|
166
|
+
throw new error_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", error_1.ErrorCode.MISSING_INTL_API, originalMessage);
|
|
167
167
|
}
|
|
168
168
|
var rule = formatters
|
|
169
169
|
.getPluralRules(locales, { type: el.pluralType })
|