intl-messageformat 9.9.3 → 9.9.4
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/index.js +3 -3
- package/intl-messageformat.esm.js +0 -3
- package/intl-messageformat.iife.js +3 -6
- package/lib/src/core.js +3 -3
- package/package.json +2 -2
- package/src/core.js +11 -11
- package/src/error.js +4 -4
- package/src/formatters.js +13 -13
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ See the accompanying LICENSE file for terms.
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
var tslib_1 = require("tslib");
|
|
9
9
|
var core_1 = require("./src/core");
|
|
10
|
-
tslib_1.__exportStar(require("./src/formatters"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./src/core"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./src/error"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./src/formatters"), exports);
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./src/core"), exports);
|
|
12
|
+
(0, tslib_1.__exportStar)(require("./src/error"), exports);
|
|
13
13
|
exports.default = core_1.IntlMessageFormat;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __require = typeof require !== "undefined" ? require : (x) => {
|
|
4
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
5
|
-
};
|
|
6
3
|
var __publicField = (obj, key, value) => {
|
|
7
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
5
|
return value;
|
|
@@ -3,9 +3,6 @@ var IntlMessageFormat = (function() {
|
|
|
3
3
|
var __markAsModule = function(target) {
|
|
4
4
|
return __defProp(target, "__esModule", { value: true });
|
|
5
5
|
};
|
|
6
|
-
var __require = typeof require !== "undefined" ? require : function(x) {
|
|
7
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
-
};
|
|
9
6
|
var __export = function(target, all) {
|
|
10
7
|
__markAsModule(target);
|
|
11
8
|
for (var name in all)
|
|
@@ -1642,7 +1639,7 @@ var IntlMessageFormat = (function() {
|
|
|
1642
1639
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1643
1640
|
args[_i] = arguments[_i];
|
|
1644
1641
|
}
|
|
1645
|
-
return new ((_a2 = Intl.NumberFormat).bind.apply(_a2, __spreadArray([void 0], args)))();
|
|
1642
|
+
return new ((_a2 = Intl.NumberFormat).bind.apply(_a2, __spreadArray([void 0], args, false)))();
|
|
1646
1643
|
}, {
|
|
1647
1644
|
cache: createFastMemoizeCache(cache.number),
|
|
1648
1645
|
strategy: strategies.variadic
|
|
@@ -1653,7 +1650,7 @@ var IntlMessageFormat = (function() {
|
|
|
1653
1650
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1654
1651
|
args[_i] = arguments[_i];
|
|
1655
1652
|
}
|
|
1656
|
-
return new ((_a2 = Intl.DateTimeFormat).bind.apply(_a2, __spreadArray([void 0], args)))();
|
|
1653
|
+
return new ((_a2 = Intl.DateTimeFormat).bind.apply(_a2, __spreadArray([void 0], args, false)))();
|
|
1657
1654
|
}, {
|
|
1658
1655
|
cache: createFastMemoizeCache(cache.dateTime),
|
|
1659
1656
|
strategy: strategies.variadic
|
|
@@ -1664,7 +1661,7 @@ var IntlMessageFormat = (function() {
|
|
|
1664
1661
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1665
1662
|
args[_i] = arguments[_i];
|
|
1666
1663
|
}
|
|
1667
|
-
return new ((_a2 = Intl.PluralRules).bind.apply(_a2, __spreadArray([void 0], args)))();
|
|
1664
|
+
return new ((_a2 = Intl.PluralRules).bind.apply(_a2, __spreadArray([void 0], args, false)))();
|
|
1668
1665
|
}, {
|
|
1669
1666
|
cache: createFastMemoizeCache(cache.pluralRules),
|
|
1670
1667
|
strategy: strategies.variadic
|
package/lib/src/core.js
CHANGED
|
@@ -53,7 +53,7 @@ function createDefaultFormatters(cache) {
|
|
|
53
53
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
54
54
|
args[_i] = arguments[_i];
|
|
55
55
|
}
|
|
56
|
-
return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args)))();
|
|
56
|
+
return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
57
57
|
}, {
|
|
58
58
|
cache: createFastMemoizeCache(cache.number),
|
|
59
59
|
strategy: strategies.variadic,
|
|
@@ -64,7 +64,7 @@ function createDefaultFormatters(cache) {
|
|
|
64
64
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
65
65
|
args[_i] = arguments[_i];
|
|
66
66
|
}
|
|
67
|
-
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args)))();
|
|
67
|
+
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
68
68
|
}, {
|
|
69
69
|
cache: createFastMemoizeCache(cache.dateTime),
|
|
70
70
|
strategy: strategies.variadic,
|
|
@@ -75,7 +75,7 @@ function createDefaultFormatters(cache) {
|
|
|
75
75
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
76
76
|
args[_i] = arguments[_i];
|
|
77
77
|
}
|
|
78
|
-
return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args)))();
|
|
78
|
+
return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
79
79
|
}, {
|
|
80
80
|
cache: createFastMemoizeCache(cache.pluralRules),
|
|
81
81
|
strategy: strategies.variadic,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-messageformat",
|
|
3
|
-
"version": "9.9.
|
|
3
|
+
"version": "9.9.4",
|
|
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
|
"@formatjs/fast-memoize": "1.2.0",
|
|
35
|
-
"@formatjs/icu-messageformat-parser": "2.0.
|
|
35
|
+
"@formatjs/icu-messageformat-parser": "2.0.14",
|
|
36
36
|
"tslib": "^2.1.0"
|
|
37
37
|
},
|
|
38
38
|
"sideEffects": false,
|
package/src/core.js
CHANGED
|
@@ -8,15 +8,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.IntlMessageFormat = void 0;
|
|
9
9
|
var tslib_1 = require("tslib");
|
|
10
10
|
var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
|
|
11
|
-
var fast_memoize_1 = tslib_1.__importStar(require("@formatjs/fast-memoize"));
|
|
11
|
+
var fast_memoize_1 = (0, tslib_1.__importStar)(require("@formatjs/fast-memoize"));
|
|
12
12
|
var formatters_1 = require("./formatters");
|
|
13
13
|
// -- MessageFormat --------------------------------------------------------
|
|
14
14
|
function mergeConfig(c1, c2) {
|
|
15
15
|
if (!c2) {
|
|
16
16
|
return c1;
|
|
17
17
|
}
|
|
18
|
-
return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, (c1 || {})), (c2 || {})), Object.keys(c1).reduce(function (all, k) {
|
|
19
|
-
all[k] = tslib_1.__assign(tslib_1.__assign({}, c1[k]), (c2[k] || {}));
|
|
18
|
+
return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, (c1 || {})), (c2 || {})), Object.keys(c1).reduce(function (all, k) {
|
|
19
|
+
all[k] = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, c1[k]), (c2[k] || {}));
|
|
20
20
|
return all;
|
|
21
21
|
}, {}));
|
|
22
22
|
}
|
|
@@ -27,7 +27,7 @@ function mergeConfigs(defaultConfig, configs) {
|
|
|
27
27
|
return Object.keys(defaultConfig).reduce(function (all, k) {
|
|
28
28
|
all[k] = mergeConfig(defaultConfig[k], configs[k]);
|
|
29
29
|
return all;
|
|
30
|
-
}, tslib_1.__assign({}, defaultConfig));
|
|
30
|
+
}, (0, tslib_1.__assign)({}, defaultConfig));
|
|
31
31
|
}
|
|
32
32
|
function createFastMemoizeCache(store) {
|
|
33
33
|
return {
|
|
@@ -50,35 +50,35 @@ function createDefaultFormatters(cache) {
|
|
|
50
50
|
pluralRules: {},
|
|
51
51
|
}; }
|
|
52
52
|
return {
|
|
53
|
-
getNumberFormat: fast_memoize_1.default(function () {
|
|
53
|
+
getNumberFormat: (0, fast_memoize_1.default)(function () {
|
|
54
54
|
var _a;
|
|
55
55
|
var args = [];
|
|
56
56
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
57
57
|
args[_i] = arguments[_i];
|
|
58
58
|
}
|
|
59
|
-
return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
|
|
59
|
+
return new ((_a = Intl.NumberFormat).bind.apply(_a, (0, tslib_1.__spreadArray)([void 0], args, false)))();
|
|
60
60
|
}, {
|
|
61
61
|
cache: createFastMemoizeCache(cache.number),
|
|
62
62
|
strategy: fast_memoize_1.strategies.variadic,
|
|
63
63
|
}),
|
|
64
|
-
getDateTimeFormat: fast_memoize_1.default(function () {
|
|
64
|
+
getDateTimeFormat: (0, fast_memoize_1.default)(function () {
|
|
65
65
|
var _a;
|
|
66
66
|
var args = [];
|
|
67
67
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
68
68
|
args[_i] = arguments[_i];
|
|
69
69
|
}
|
|
70
|
-
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
|
|
70
|
+
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, (0, tslib_1.__spreadArray)([void 0], args, false)))();
|
|
71
71
|
}, {
|
|
72
72
|
cache: createFastMemoizeCache(cache.dateTime),
|
|
73
73
|
strategy: fast_memoize_1.strategies.variadic,
|
|
74
74
|
}),
|
|
75
|
-
getPluralRules: fast_memoize_1.default(function () {
|
|
75
|
+
getPluralRules: (0, fast_memoize_1.default)(function () {
|
|
76
76
|
var _a;
|
|
77
77
|
var args = [];
|
|
78
78
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
79
79
|
args[_i] = arguments[_i];
|
|
80
80
|
}
|
|
81
|
-
return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArray([void 0], args)))();
|
|
81
|
+
return new ((_a = Intl.PluralRules).bind.apply(_a, (0, tslib_1.__spreadArray)([void 0], args, false)))();
|
|
82
82
|
}, {
|
|
83
83
|
cache: createFastMemoizeCache(cache.pluralRules),
|
|
84
84
|
strategy: fast_memoize_1.strategies.variadic,
|
|
@@ -117,7 +117,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
117
117
|
return result;
|
|
118
118
|
};
|
|
119
119
|
this.formatToParts = function (values) {
|
|
120
|
-
return formatters_1.formatToParts(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
|
|
120
|
+
return (0, formatters_1.formatToParts)(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
|
|
121
121
|
};
|
|
122
122
|
this.resolvedOptions = function () { return ({
|
|
123
123
|
locale: Intl.NumberFormat.supportedLocalesOf(_this.locales)[0],
|
package/src/error.js
CHANGED
|
@@ -12,7 +12,7 @@ var ErrorCode;
|
|
|
12
12
|
ErrorCode["MISSING_INTL_API"] = "MISSING_INTL_API";
|
|
13
13
|
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
|
|
14
14
|
var FormatError = /** @class */ (function (_super) {
|
|
15
|
-
tslib_1.__extends(FormatError, _super);
|
|
15
|
+
(0, tslib_1.__extends)(FormatError, _super);
|
|
16
16
|
function FormatError(msg, code, originalMessage) {
|
|
17
17
|
var _this = _super.call(this, msg) || this;
|
|
18
18
|
_this.code = code;
|
|
@@ -26,7 +26,7 @@ var FormatError = /** @class */ (function (_super) {
|
|
|
26
26
|
}(Error));
|
|
27
27
|
exports.FormatError = FormatError;
|
|
28
28
|
var InvalidValueError = /** @class */ (function (_super) {
|
|
29
|
-
tslib_1.__extends(InvalidValueError, _super);
|
|
29
|
+
(0, tslib_1.__extends)(InvalidValueError, _super);
|
|
30
30
|
function InvalidValueError(variableId, value, options, originalMessage) {
|
|
31
31
|
return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
32
32
|
}
|
|
@@ -34,7 +34,7 @@ var InvalidValueError = /** @class */ (function (_super) {
|
|
|
34
34
|
}(FormatError));
|
|
35
35
|
exports.InvalidValueError = InvalidValueError;
|
|
36
36
|
var InvalidValueTypeError = /** @class */ (function (_super) {
|
|
37
|
-
tslib_1.__extends(InvalidValueTypeError, _super);
|
|
37
|
+
(0, tslib_1.__extends)(InvalidValueTypeError, _super);
|
|
38
38
|
function InvalidValueTypeError(value, type, originalMessage) {
|
|
39
39
|
return _super.call(this, "Value for \"" + value + "\" must be of type " + type, ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
40
40
|
}
|
|
@@ -42,7 +42,7 @@ var InvalidValueTypeError = /** @class */ (function (_super) {
|
|
|
42
42
|
}(FormatError));
|
|
43
43
|
exports.InvalidValueTypeError = InvalidValueTypeError;
|
|
44
44
|
var MissingValueError = /** @class */ (function (_super) {
|
|
45
|
-
tslib_1.__extends(MissingValueError, _super);
|
|
45
|
+
(0, tslib_1.__extends)(MissingValueError, _super);
|
|
46
46
|
function MissingValueError(variableId, originalMessage) {
|
|
47
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
|
}
|
package/src/formatters.js
CHANGED
|
@@ -34,7 +34,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
34
34
|
// For debugging
|
|
35
35
|
originalMessage) {
|
|
36
36
|
// Hot path for straight simple msg translations
|
|
37
|
-
if (els.length === 1 && icu_messageformat_parser_1.isLiteralElement(els[0])) {
|
|
37
|
+
if (els.length === 1 && (0, icu_messageformat_parser_1.isLiteralElement)(els[0])) {
|
|
38
38
|
return [
|
|
39
39
|
{
|
|
40
40
|
type: PART_TYPE.literal,
|
|
@@ -46,7 +46,7 @@ originalMessage) {
|
|
|
46
46
|
for (var _i = 0, els_1 = els; _i < els_1.length; _i++) {
|
|
47
47
|
var el = els_1[_i];
|
|
48
48
|
// Exit early for string parts.
|
|
49
|
-
if (icu_messageformat_parser_1.isLiteralElement(el)) {
|
|
49
|
+
if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
|
|
50
50
|
result.push({
|
|
51
51
|
type: PART_TYPE.literal,
|
|
52
52
|
value: el.value,
|
|
@@ -55,7 +55,7 @@ originalMessage) {
|
|
|
55
55
|
}
|
|
56
56
|
// TODO: should this part be literal type?
|
|
57
57
|
// Replace `#` in plural rules with the actual numeric value.
|
|
58
|
-
if (icu_messageformat_parser_1.isPoundElement(el)) {
|
|
58
|
+
if ((0, icu_messageformat_parser_1.isPoundElement)(el)) {
|
|
59
59
|
if (typeof currentPluralValue === 'number') {
|
|
60
60
|
result.push({
|
|
61
61
|
type: PART_TYPE.literal,
|
|
@@ -70,7 +70,7 @@ originalMessage) {
|
|
|
70
70
|
throw new error_1.MissingValueError(varName, originalMessage);
|
|
71
71
|
}
|
|
72
72
|
var value = values[varName];
|
|
73
|
-
if (icu_messageformat_parser_1.isArgumentElement(el)) {
|
|
73
|
+
if ((0, icu_messageformat_parser_1.isArgumentElement)(el)) {
|
|
74
74
|
if (!value || typeof value === 'string' || typeof value === 'number') {
|
|
75
75
|
value =
|
|
76
76
|
typeof value === 'string' || typeof value === 'number'
|
|
@@ -86,10 +86,10 @@ originalMessage) {
|
|
|
86
86
|
// Recursively format plural and select parts' option — which can be a
|
|
87
87
|
// nested pattern structure. The choosing of the option to use is
|
|
88
88
|
// abstracted-by and delegated-to the part helper object.
|
|
89
|
-
if (icu_messageformat_parser_1.isDateElement(el)) {
|
|
89
|
+
if ((0, icu_messageformat_parser_1.isDateElement)(el)) {
|
|
90
90
|
var style = typeof el.style === 'string'
|
|
91
91
|
? formats.date[el.style]
|
|
92
|
-
: icu_messageformat_parser_1.isDateTimeSkeleton(el.style)
|
|
92
|
+
: (0, icu_messageformat_parser_1.isDateTimeSkeleton)(el.style)
|
|
93
93
|
? el.style.parsedOptions
|
|
94
94
|
: undefined;
|
|
95
95
|
result.push({
|
|
@@ -100,10 +100,10 @@ originalMessage) {
|
|
|
100
100
|
});
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
|
-
if (icu_messageformat_parser_1.isTimeElement(el)) {
|
|
103
|
+
if ((0, icu_messageformat_parser_1.isTimeElement)(el)) {
|
|
104
104
|
var style = typeof el.style === 'string'
|
|
105
105
|
? formats.time[el.style]
|
|
106
|
-
: icu_messageformat_parser_1.isDateTimeSkeleton(el.style)
|
|
106
|
+
: (0, icu_messageformat_parser_1.isDateTimeSkeleton)(el.style)
|
|
107
107
|
? el.style.parsedOptions
|
|
108
108
|
: undefined;
|
|
109
109
|
result.push({
|
|
@@ -114,10 +114,10 @@ originalMessage) {
|
|
|
114
114
|
});
|
|
115
115
|
continue;
|
|
116
116
|
}
|
|
117
|
-
if (icu_messageformat_parser_1.isNumberElement(el)) {
|
|
117
|
+
if ((0, icu_messageformat_parser_1.isNumberElement)(el)) {
|
|
118
118
|
var style = typeof el.style === 'string'
|
|
119
119
|
? formats.number[el.style]
|
|
120
|
-
: icu_messageformat_parser_1.isNumberSkeleton(el.style)
|
|
120
|
+
: (0, icu_messageformat_parser_1.isNumberSkeleton)(el.style)
|
|
121
121
|
? el.style.parsedOptions
|
|
122
122
|
: undefined;
|
|
123
123
|
if (style && style.scale) {
|
|
@@ -133,7 +133,7 @@ originalMessage) {
|
|
|
133
133
|
});
|
|
134
134
|
continue;
|
|
135
135
|
}
|
|
136
|
-
if (icu_messageformat_parser_1.isTagElement(el)) {
|
|
136
|
+
if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
|
|
137
137
|
var children = el.children, value_1 = el.value;
|
|
138
138
|
var formatFn = values[value_1];
|
|
139
139
|
if (!isFormatXMLElementFn(formatFn)) {
|
|
@@ -151,7 +151,7 @@ originalMessage) {
|
|
|
151
151
|
};
|
|
152
152
|
}));
|
|
153
153
|
}
|
|
154
|
-
if (icu_messageformat_parser_1.isSelectElement(el)) {
|
|
154
|
+
if ((0, icu_messageformat_parser_1.isSelectElement)(el)) {
|
|
155
155
|
var opt = el.options[value] || el.options.other;
|
|
156
156
|
if (!opt) {
|
|
157
157
|
throw new error_1.InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
@@ -159,7 +159,7 @@ originalMessage) {
|
|
|
159
159
|
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
|
-
if (icu_messageformat_parser_1.isPluralElement(el)) {
|
|
162
|
+
if ((0, icu_messageformat_parser_1.isPluralElement)(el)) {
|
|
163
163
|
var opt = el.options["=" + value];
|
|
164
164
|
if (!opt) {
|
|
165
165
|
if (!Intl.PluralRules) {
|