intl-messageformat 10.7.17 → 11.0.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/index.d.ts +4 -4
- package/index.js +6 -10
- package/intl-messageformat.esm.js +17 -17
- package/intl-messageformat.iife.js +16 -16
- package/package.json +8 -6
- package/src/core.d.ts +1 -1
- package/src/core.js +24 -25
- package/src/error.js +11 -14
- package/src/formatters.js +24 -29
- package/lib/index.d.ts +0 -6
- package/lib/index.js +0 -11
- package/lib/src/core.d.ts +0 -26
- package/lib/src/core.js +0 -238
- package/lib/src/error.d.ts +0 -27
- package/lib/src/error.js +0 -48
- package/lib/src/formatters.d.ts +0 -46
- package/lib/src/formatters.js +0 -177
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IntlMessageFormat } from './src/core';
|
|
2
|
-
export * from './src/core';
|
|
3
|
-
export * from './src/error';
|
|
4
|
-
export * from './src/formatters';
|
|
1
|
+
import { IntlMessageFormat } from './src/core.js';
|
|
2
|
+
export * from './src/core.js';
|
|
3
|
+
export * from './src/error.js';
|
|
4
|
+
export * from './src/formatters.js';
|
|
5
5
|
export { IntlMessageFormat };
|
|
6
6
|
export default IntlMessageFormat;
|
package/index.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
4
3
|
Copyrights licensed under the New BSD License.
|
|
5
4
|
See the accompanying LICENSE file for terms.
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
tslib_1.__exportStar(require("./src/error"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./src/formatters"), exports);
|
|
15
|
-
exports.default = core_1.IntlMessageFormat;
|
|
6
|
+
import { IntlMessageFormat } from './src/core.js';
|
|
7
|
+
export * from './src/core.js';
|
|
8
|
+
export * from './src/error.js';
|
|
9
|
+
export * from './src/formatters.js';
|
|
10
|
+
export { IntlMessageFormat };
|
|
11
|
+
export default IntlMessageFormat;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/
|
|
1
|
+
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
|
|
2
2
|
function memoize(fn, options) {
|
|
3
3
|
var cache = options && options.cache ? options.cache : cacheDefault;
|
|
4
4
|
var serializer = options && options.serializer ? options.serializer : serializerDefault;
|
|
@@ -85,7 +85,7 @@ var __assign = function() {
|
|
|
85
85
|
return __assign.apply(this, arguments);
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
88
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/error.js
|
|
89
89
|
var ErrorKind;
|
|
90
90
|
(function(ErrorKind2) {
|
|
91
91
|
ErrorKind2[ErrorKind2["EXPECT_ARGUMENT_CLOSING_BRACE"] = 1] = "EXPECT_ARGUMENT_CLOSING_BRACE";
|
|
@@ -116,7 +116,7 @@ var ErrorKind;
|
|
|
116
116
|
ErrorKind2[ErrorKind2["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG";
|
|
117
117
|
})(ErrorKind || (ErrorKind = {}));
|
|
118
118
|
|
|
119
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
119
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/types.js
|
|
120
120
|
var TYPE;
|
|
121
121
|
(function(TYPE2) {
|
|
122
122
|
TYPE2[TYPE2["literal"] = 0] = "literal";
|
|
@@ -168,10 +168,10 @@ function isDateTimeSkeleton(el) {
|
|
|
168
168
|
return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.dateTime);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
171
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/regex.generated.js
|
|
172
172
|
var SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
|
173
173
|
|
|
174
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/
|
|
174
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/date-time.js
|
|
175
175
|
var DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
|
|
176
176
|
function parseDateTimeSkeleton(skeleton) {
|
|
177
177
|
var result = {};
|
|
@@ -272,10 +272,10 @@ function parseDateTimeSkeleton(skeleton) {
|
|
|
272
272
|
return result;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/
|
|
275
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/regex.generated.js
|
|
276
276
|
var WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/i;
|
|
277
277
|
|
|
278
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/
|
|
278
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/number.js
|
|
279
279
|
function parseNumberSkeletonFromString(skeleton) {
|
|
280
280
|
if (skeleton.length === 0) {
|
|
281
281
|
throw new Error("Number skeleton cannot be empty");
|
|
@@ -562,7 +562,7 @@ function parseNumberSkeleton(tokens) {
|
|
|
562
562
|
return result;
|
|
563
563
|
}
|
|
564
564
|
|
|
565
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
565
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/time-data.generated.js
|
|
566
566
|
var timeData = {
|
|
567
567
|
"001": [
|
|
568
568
|
"H",
|
|
@@ -1979,7 +1979,7 @@ var timeData = {
|
|
|
1979
1979
|
]
|
|
1980
1980
|
};
|
|
1981
1981
|
|
|
1982
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
1982
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/date-time-pattern-generator.js
|
|
1983
1983
|
function getBestPattern(skeleton, locale) {
|
|
1984
1984
|
var skeletonCopy = "";
|
|
1985
1985
|
for (var patternPos = 0; patternPos < skeleton.length; patternPos++) {
|
|
@@ -2041,7 +2041,7 @@ function getDefaultHourSymbolFromLocale(locale) {
|
|
|
2041
2041
|
return hourCycles[0];
|
|
2042
2042
|
}
|
|
2043
2043
|
|
|
2044
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
2044
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/parser.js
|
|
2045
2045
|
var _a;
|
|
2046
2046
|
var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(SPACE_SEPARATOR_REGEX.source, "*"));
|
|
2047
2047
|
var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(SPACE_SEPARATOR_REGEX.source, "*$"));
|
|
@@ -2062,7 +2062,7 @@ var REGEX_SUPPORTS_U_AND_Y = true;
|
|
|
2062
2062
|
try {
|
|
2063
2063
|
re = RE("([^\\p{White_Space}\\p{Pattern_Syntax}]*)", "yu");
|
|
2064
2064
|
REGEX_SUPPORTS_U_AND_Y = ((_a = re.exec("a")) === null || _a === void 0 ? void 0 : _a[0]) === "a";
|
|
2065
|
-
} catch (
|
|
2065
|
+
} catch (_b) {
|
|
2066
2066
|
REGEX_SUPPORTS_U_AND_Y = false;
|
|
2067
2067
|
}
|
|
2068
2068
|
var re;
|
|
@@ -2626,7 +2626,7 @@ var Parser = (
|
|
|
2626
2626
|
var tokens = [];
|
|
2627
2627
|
try {
|
|
2628
2628
|
tokens = parseNumberSkeletonFromString(skeleton);
|
|
2629
|
-
} catch (
|
|
2629
|
+
} catch (_a2) {
|
|
2630
2630
|
return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location);
|
|
2631
2631
|
}
|
|
2632
2632
|
return {
|
|
@@ -2846,7 +2846,7 @@ function _isPatternSyntax(c) {
|
|
|
2846
2846
|
return c >= 33 && c <= 35 || c === 36 || c >= 37 && c <= 39 || c === 40 || c === 41 || c === 42 || c === 43 || c === 44 || c === 45 || c >= 46 && c <= 47 || c >= 58 && c <= 59 || c >= 60 && c <= 62 || c >= 63 && c <= 64 || c === 91 || c === 92 || c === 93 || c === 94 || c === 96 || c === 123 || c === 124 || c === 125 || c === 126 || c === 161 || c >= 162 && c <= 165 || c === 166 || c === 167 || c === 169 || c === 171 || c === 172 || c === 174 || c === 176 || c === 177 || c === 182 || c === 187 || c === 191 || c === 215 || c === 247 || c >= 8208 && c <= 8213 || c >= 8214 && c <= 8215 || c === 8216 || c === 8217 || c === 8218 || c >= 8219 && c <= 8220 || c === 8221 || c === 8222 || c === 8223 || c >= 8224 && c <= 8231 || c >= 8240 && c <= 8248 || c === 8249 || c === 8250 || c >= 8251 && c <= 8254 || c >= 8257 && c <= 8259 || c === 8260 || c === 8261 || c === 8262 || c >= 8263 && c <= 8273 || c === 8274 || c === 8275 || c >= 8277 && c <= 8286 || c >= 8592 && c <= 8596 || c >= 8597 && c <= 8601 || c >= 8602 && c <= 8603 || c >= 8604 && c <= 8607 || c === 8608 || c >= 8609 && c <= 8610 || c === 8611 || c >= 8612 && c <= 8613 || c === 8614 || c >= 8615 && c <= 8621 || c === 8622 || c >= 8623 && c <= 8653 || c >= 8654 && c <= 8655 || c >= 8656 && c <= 8657 || c === 8658 || c === 8659 || c === 8660 || c >= 8661 && c <= 8691 || c >= 8692 && c <= 8959 || c >= 8960 && c <= 8967 || c === 8968 || c === 8969 || c === 8970 || c === 8971 || c >= 8972 && c <= 8991 || c >= 8992 && c <= 8993 || c >= 8994 && c <= 9e3 || c === 9001 || c === 9002 || c >= 9003 && c <= 9083 || c === 9084 || c >= 9085 && c <= 9114 || c >= 9115 && c <= 9139 || c >= 9140 && c <= 9179 || c >= 9180 && c <= 9185 || c >= 9186 && c <= 9254 || c >= 9255 && c <= 9279 || c >= 9280 && c <= 9290 || c >= 9291 && c <= 9311 || c >= 9472 && c <= 9654 || c === 9655 || c >= 9656 && c <= 9664 || c === 9665 || c >= 9666 && c <= 9719 || c >= 9720 && c <= 9727 || c >= 9728 && c <= 9838 || c === 9839 || c >= 9840 && c <= 10087 || c === 10088 || c === 10089 || c === 10090 || c === 10091 || c === 10092 || c === 10093 || c === 10094 || c === 10095 || c === 10096 || c === 10097 || c === 10098 || c === 10099 || c === 10100 || c === 10101 || c >= 10132 && c <= 10175 || c >= 10176 && c <= 10180 || c === 10181 || c === 10182 || c >= 10183 && c <= 10213 || c === 10214 || c === 10215 || c === 10216 || c === 10217 || c === 10218 || c === 10219 || c === 10220 || c === 10221 || c === 10222 || c === 10223 || c >= 10224 && c <= 10239 || c >= 10240 && c <= 10495 || c >= 10496 && c <= 10626 || c === 10627 || c === 10628 || c === 10629 || c === 10630 || c === 10631 || c === 10632 || c === 10633 || c === 10634 || c === 10635 || c === 10636 || c === 10637 || c === 10638 || c === 10639 || c === 10640 || c === 10641 || c === 10642 || c === 10643 || c === 10644 || c === 10645 || c === 10646 || c === 10647 || c === 10648 || c >= 10649 && c <= 10711 || c === 10712 || c === 10713 || c === 10714 || c === 10715 || c >= 10716 && c <= 10747 || c === 10748 || c === 10749 || c >= 10750 && c <= 11007 || c >= 11008 && c <= 11055 || c >= 11056 && c <= 11076 || c >= 11077 && c <= 11078 || c >= 11079 && c <= 11084 || c >= 11085 && c <= 11123 || c >= 11124 && c <= 11125 || c >= 11126 && c <= 11157 || c === 11158 || c >= 11159 && c <= 11263 || c >= 11776 && c <= 11777 || c === 11778 || c === 11779 || c === 11780 || c === 11781 || c >= 11782 && c <= 11784 || c === 11785 || c === 11786 || c === 11787 || c === 11788 || c === 11789 || c >= 11790 && c <= 11798 || c === 11799 || c >= 11800 && c <= 11801 || c === 11802 || c === 11803 || c === 11804 || c === 11805 || c >= 11806 && c <= 11807 || c === 11808 || c === 11809 || c === 11810 || c === 11811 || c === 11812 || c === 11813 || c === 11814 || c === 11815 || c === 11816 || c === 11817 || c >= 11818 && c <= 11822 || c === 11823 || c >= 11824 && c <= 11833 || c >= 11834 && c <= 11835 || c >= 11836 && c <= 11839 || c === 11840 || c === 11841 || c === 11842 || c >= 11843 && c <= 11855 || c >= 11856 && c <= 11857 || c === 11858 || c >= 11859 && c <= 11903 || c >= 12289 && c <= 12291 || c === 12296 || c === 12297 || c === 12298 || c === 12299 || c === 12300 || c === 12301 || c === 12302 || c === 12303 || c === 12304 || c === 12305 || c >= 12306 && c <= 12307 || c === 12308 || c === 12309 || c === 12310 || c === 12311 || c === 12312 || c === 12313 || c === 12314 || c === 12315 || c === 12316 || c === 12317 || c >= 12318 && c <= 12319 || c === 12320 || c === 12336 || c === 64830 || c === 64831 || c >= 65093 && c <= 65094;
|
|
2847
2847
|
}
|
|
2848
2848
|
|
|
2849
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
2849
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/index.js
|
|
2850
2850
|
function pruneLocation(els) {
|
|
2851
2851
|
els.forEach(function(el) {
|
|
2852
2852
|
delete el.location;
|
|
@@ -3117,12 +3117,12 @@ function mergeConfig(c1, c2) {
|
|
|
3117
3117
|
return c1;
|
|
3118
3118
|
}
|
|
3119
3119
|
return {
|
|
3120
|
-
...c1
|
|
3121
|
-
...c2
|
|
3120
|
+
...c1,
|
|
3121
|
+
...c2,
|
|
3122
3122
|
...Object.keys(c1).reduce((all, k) => {
|
|
3123
3123
|
all[k] = {
|
|
3124
3124
|
...c1[k],
|
|
3125
|
-
...c2[k]
|
|
3125
|
+
...c2[k]
|
|
3126
3126
|
};
|
|
3127
3127
|
return all;
|
|
3128
3128
|
}, {})
|
|
@@ -3196,7 +3196,7 @@ var IntlMessageFormat = class _IntlMessageFormat {
|
|
|
3196
3196
|
"IntlMessageFormat.__parse must be set to process `message` of type `string`"
|
|
3197
3197
|
);
|
|
3198
3198
|
}
|
|
3199
|
-
const {
|
|
3199
|
+
const { ...parseOpts } = opts || {};
|
|
3200
3200
|
this.ast = _IntlMessageFormat.__parse(message, {
|
|
3201
3201
|
...parseOpts,
|
|
3202
3202
|
locale: this.resolvedLocale
|
|
@@ -65,7 +65,7 @@ var IntlMessageFormat = (() => {
|
|
|
65
65
|
isFormatXMLElementFn: () => isFormatXMLElementFn
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/
|
|
68
|
+
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
|
|
69
69
|
function memoize(fn, options) {
|
|
70
70
|
var cache = options && options.cache ? options.cache : cacheDefault;
|
|
71
71
|
var serializer = options && options.serializer ? options.serializer : serializerDefault;
|
|
@@ -152,7 +152,7 @@ var IntlMessageFormat = (() => {
|
|
|
152
152
|
return __assign.apply(this, arguments);
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
155
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/error.js
|
|
156
156
|
var ErrorKind;
|
|
157
157
|
(function(ErrorKind2) {
|
|
158
158
|
ErrorKind2[ErrorKind2["EXPECT_ARGUMENT_CLOSING_BRACE"] = 1] = "EXPECT_ARGUMENT_CLOSING_BRACE";
|
|
@@ -183,7 +183,7 @@ var IntlMessageFormat = (() => {
|
|
|
183
183
|
ErrorKind2[ErrorKind2["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG";
|
|
184
184
|
})(ErrorKind || (ErrorKind = {}));
|
|
185
185
|
|
|
186
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
186
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/types.js
|
|
187
187
|
var TYPE;
|
|
188
188
|
(function(TYPE2) {
|
|
189
189
|
TYPE2[TYPE2["literal"] = 0] = "literal";
|
|
@@ -235,10 +235,10 @@ var IntlMessageFormat = (() => {
|
|
|
235
235
|
return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.dateTime);
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
238
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/regex.generated.js
|
|
239
239
|
var SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
|
240
240
|
|
|
241
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/
|
|
241
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/date-time.js
|
|
242
242
|
var DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
|
|
243
243
|
function parseDateTimeSkeleton(skeleton) {
|
|
244
244
|
var result = {};
|
|
@@ -339,10 +339,10 @@ var IntlMessageFormat = (() => {
|
|
|
339
339
|
return result;
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/
|
|
342
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/regex.generated.js
|
|
343
343
|
var WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/i;
|
|
344
344
|
|
|
345
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/
|
|
345
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/number.js
|
|
346
346
|
function parseNumberSkeletonFromString(skeleton) {
|
|
347
347
|
if (skeleton.length === 0) {
|
|
348
348
|
throw new Error("Number skeleton cannot be empty");
|
|
@@ -629,7 +629,7 @@ var IntlMessageFormat = (() => {
|
|
|
629
629
|
return result;
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
632
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/time-data.generated.js
|
|
633
633
|
var timeData = {
|
|
634
634
|
"001": [
|
|
635
635
|
"H",
|
|
@@ -2046,7 +2046,7 @@ var IntlMessageFormat = (() => {
|
|
|
2046
2046
|
]
|
|
2047
2047
|
};
|
|
2048
2048
|
|
|
2049
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
2049
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/date-time-pattern-generator.js
|
|
2050
2050
|
function getBestPattern(skeleton, locale) {
|
|
2051
2051
|
var skeletonCopy = "";
|
|
2052
2052
|
for (var patternPos = 0; patternPos < skeleton.length; patternPos++) {
|
|
@@ -2108,7 +2108,7 @@ var IntlMessageFormat = (() => {
|
|
|
2108
2108
|
return hourCycles[0];
|
|
2109
2109
|
}
|
|
2110
2110
|
|
|
2111
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
2111
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/parser.js
|
|
2112
2112
|
var _a;
|
|
2113
2113
|
var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(SPACE_SEPARATOR_REGEX.source, "*"));
|
|
2114
2114
|
var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(SPACE_SEPARATOR_REGEX.source, "*$"));
|
|
@@ -2129,7 +2129,7 @@ var IntlMessageFormat = (() => {
|
|
|
2129
2129
|
try {
|
|
2130
2130
|
re = RE("([^\\p{White_Space}\\p{Pattern_Syntax}]*)", "yu");
|
|
2131
2131
|
REGEX_SUPPORTS_U_AND_Y = ((_a = re.exec("a")) === null || _a === void 0 ? void 0 : _a[0]) === "a";
|
|
2132
|
-
} catch (
|
|
2132
|
+
} catch (_b) {
|
|
2133
2133
|
REGEX_SUPPORTS_U_AND_Y = false;
|
|
2134
2134
|
}
|
|
2135
2135
|
var re;
|
|
@@ -2693,7 +2693,7 @@ var IntlMessageFormat = (() => {
|
|
|
2693
2693
|
var tokens = [];
|
|
2694
2694
|
try {
|
|
2695
2695
|
tokens = parseNumberSkeletonFromString(skeleton);
|
|
2696
|
-
} catch (
|
|
2696
|
+
} catch (_a2) {
|
|
2697
2697
|
return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location);
|
|
2698
2698
|
}
|
|
2699
2699
|
return {
|
|
@@ -2913,7 +2913,7 @@ var IntlMessageFormat = (() => {
|
|
|
2913
2913
|
return c >= 33 && c <= 35 || c === 36 || c >= 37 && c <= 39 || c === 40 || c === 41 || c === 42 || c === 43 || c === 44 || c === 45 || c >= 46 && c <= 47 || c >= 58 && c <= 59 || c >= 60 && c <= 62 || c >= 63 && c <= 64 || c === 91 || c === 92 || c === 93 || c === 94 || c === 96 || c === 123 || c === 124 || c === 125 || c === 126 || c === 161 || c >= 162 && c <= 165 || c === 166 || c === 167 || c === 169 || c === 171 || c === 172 || c === 174 || c === 176 || c === 177 || c === 182 || c === 187 || c === 191 || c === 215 || c === 247 || c >= 8208 && c <= 8213 || c >= 8214 && c <= 8215 || c === 8216 || c === 8217 || c === 8218 || c >= 8219 && c <= 8220 || c === 8221 || c === 8222 || c === 8223 || c >= 8224 && c <= 8231 || c >= 8240 && c <= 8248 || c === 8249 || c === 8250 || c >= 8251 && c <= 8254 || c >= 8257 && c <= 8259 || c === 8260 || c === 8261 || c === 8262 || c >= 8263 && c <= 8273 || c === 8274 || c === 8275 || c >= 8277 && c <= 8286 || c >= 8592 && c <= 8596 || c >= 8597 && c <= 8601 || c >= 8602 && c <= 8603 || c >= 8604 && c <= 8607 || c === 8608 || c >= 8609 && c <= 8610 || c === 8611 || c >= 8612 && c <= 8613 || c === 8614 || c >= 8615 && c <= 8621 || c === 8622 || c >= 8623 && c <= 8653 || c >= 8654 && c <= 8655 || c >= 8656 && c <= 8657 || c === 8658 || c === 8659 || c === 8660 || c >= 8661 && c <= 8691 || c >= 8692 && c <= 8959 || c >= 8960 && c <= 8967 || c === 8968 || c === 8969 || c === 8970 || c === 8971 || c >= 8972 && c <= 8991 || c >= 8992 && c <= 8993 || c >= 8994 && c <= 9e3 || c === 9001 || c === 9002 || c >= 9003 && c <= 9083 || c === 9084 || c >= 9085 && c <= 9114 || c >= 9115 && c <= 9139 || c >= 9140 && c <= 9179 || c >= 9180 && c <= 9185 || c >= 9186 && c <= 9254 || c >= 9255 && c <= 9279 || c >= 9280 && c <= 9290 || c >= 9291 && c <= 9311 || c >= 9472 && c <= 9654 || c === 9655 || c >= 9656 && c <= 9664 || c === 9665 || c >= 9666 && c <= 9719 || c >= 9720 && c <= 9727 || c >= 9728 && c <= 9838 || c === 9839 || c >= 9840 && c <= 10087 || c === 10088 || c === 10089 || c === 10090 || c === 10091 || c === 10092 || c === 10093 || c === 10094 || c === 10095 || c === 10096 || c === 10097 || c === 10098 || c === 10099 || c === 10100 || c === 10101 || c >= 10132 && c <= 10175 || c >= 10176 && c <= 10180 || c === 10181 || c === 10182 || c >= 10183 && c <= 10213 || c === 10214 || c === 10215 || c === 10216 || c === 10217 || c === 10218 || c === 10219 || c === 10220 || c === 10221 || c === 10222 || c === 10223 || c >= 10224 && c <= 10239 || c >= 10240 && c <= 10495 || c >= 10496 && c <= 10626 || c === 10627 || c === 10628 || c === 10629 || c === 10630 || c === 10631 || c === 10632 || c === 10633 || c === 10634 || c === 10635 || c === 10636 || c === 10637 || c === 10638 || c === 10639 || c === 10640 || c === 10641 || c === 10642 || c === 10643 || c === 10644 || c === 10645 || c === 10646 || c === 10647 || c === 10648 || c >= 10649 && c <= 10711 || c === 10712 || c === 10713 || c === 10714 || c === 10715 || c >= 10716 && c <= 10747 || c === 10748 || c === 10749 || c >= 10750 && c <= 11007 || c >= 11008 && c <= 11055 || c >= 11056 && c <= 11076 || c >= 11077 && c <= 11078 || c >= 11079 && c <= 11084 || c >= 11085 && c <= 11123 || c >= 11124 && c <= 11125 || c >= 11126 && c <= 11157 || c === 11158 || c >= 11159 && c <= 11263 || c >= 11776 && c <= 11777 || c === 11778 || c === 11779 || c === 11780 || c === 11781 || c >= 11782 && c <= 11784 || c === 11785 || c === 11786 || c === 11787 || c === 11788 || c === 11789 || c >= 11790 && c <= 11798 || c === 11799 || c >= 11800 && c <= 11801 || c === 11802 || c === 11803 || c === 11804 || c === 11805 || c >= 11806 && c <= 11807 || c === 11808 || c === 11809 || c === 11810 || c === 11811 || c === 11812 || c === 11813 || c === 11814 || c === 11815 || c === 11816 || c === 11817 || c >= 11818 && c <= 11822 || c === 11823 || c >= 11824 && c <= 11833 || c >= 11834 && c <= 11835 || c >= 11836 && c <= 11839 || c === 11840 || c === 11841 || c === 11842 || c >= 11843 && c <= 11855 || c >= 11856 && c <= 11857 || c === 11858 || c >= 11859 && c <= 11903 || c >= 12289 && c <= 12291 || c === 12296 || c === 12297 || c === 12298 || c === 12299 || c === 12300 || c === 12301 || c === 12302 || c === 12303 || c === 12304 || c === 12305 || c >= 12306 && c <= 12307 || c === 12308 || c === 12309 || c === 12310 || c === 12311 || c === 12312 || c === 12313 || c === 12314 || c === 12315 || c === 12316 || c === 12317 || c >= 12318 && c <= 12319 || c === 12320 || c === 12336 || c === 64830 || c === 64831 || c >= 65093 && c <= 65094;
|
|
2914
2914
|
}
|
|
2915
2915
|
|
|
2916
|
-
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/
|
|
2916
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/index.js
|
|
2917
2917
|
function pruneLocation(els) {
|
|
2918
2918
|
els.forEach(function(el) {
|
|
2919
2919
|
delete el.location;
|
|
@@ -3183,8 +3183,8 @@ Try polyfilling it using "@formatjs/intl-pluralrules"
|
|
|
3183
3183
|
if (!c2) {
|
|
3184
3184
|
return c1;
|
|
3185
3185
|
}
|
|
3186
|
-
return __spreadValues(__spreadValues(__spreadValues({}, c1
|
|
3187
|
-
all[k] = __spreadValues(__spreadValues({}, c1[k]), c2[k]
|
|
3186
|
+
return __spreadValues(__spreadValues(__spreadValues({}, c1), c2), Object.keys(c1).reduce((all, k) => {
|
|
3187
|
+
all[k] = __spreadValues(__spreadValues({}, c1[k]), c2[k]);
|
|
3188
3188
|
return all;
|
|
3189
3189
|
}, {}));
|
|
3190
3190
|
}
|
|
@@ -3293,7 +3293,7 @@ Try polyfilling it using "@formatjs/intl-pluralrules"
|
|
|
3293
3293
|
"IntlMessageFormat.__parse must be set to process `message` of type `string`"
|
|
3294
3294
|
);
|
|
3295
3295
|
}
|
|
3296
|
-
const
|
|
3296
|
+
const parseOpts = __objRest(opts || {}, []);
|
|
3297
3297
|
this.ast = _IntlMessageFormat.__parse(message, __spreadProps(__spreadValues({}, parseOpts), {
|
|
3298
3298
|
locale: this.resolvedLocale
|
|
3299
3299
|
}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-messageformat",
|
|
3
3
|
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "11.0.0",
|
|
5
5
|
"author": "Eric Ferraiuolo <eferraiuolo@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
7
7
|
"contributors": [
|
|
@@ -11,11 +11,14 @@
|
|
|
11
11
|
"Long Ho <holevietlong@gmail.com>"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@formatjs/ecma402-abstract": "
|
|
15
|
-
"@formatjs/fast-memoize": "
|
|
16
|
-
"@formatjs/icu-messageformat-parser": "
|
|
14
|
+
"@formatjs/ecma402-abstract": "3.0.0",
|
|
15
|
+
"@formatjs/fast-memoize": "3.0.0",
|
|
16
|
+
"@formatjs/icu-messageformat-parser": "3.0.0",
|
|
17
17
|
"tslib": "^2.8.0"
|
|
18
18
|
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./index.js"
|
|
21
|
+
},
|
|
19
22
|
"gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c",
|
|
20
23
|
"homepage": "https://github.com/formatjs/formatjs",
|
|
21
24
|
"keywords": [
|
|
@@ -30,9 +33,8 @@
|
|
|
30
33
|
"plural"
|
|
31
34
|
],
|
|
32
35
|
"license": "BSD-3-Clause",
|
|
33
|
-
"main": "index.js",
|
|
34
|
-
"module": "lib/index.js",
|
|
35
36
|
"repository": "git@github.com:formatjs/formatjs.git",
|
|
36
37
|
"sideEffects": false,
|
|
38
|
+
"type": "module",
|
|
37
39
|
"types": "index.d.ts"
|
|
38
40
|
}
|
package/src/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MessageFormatElement, parse, ParserOptions } from '@formatjs/icu-messageformat-parser';
|
|
2
|
-
import { Formats, Formatters, FormatXMLElementFn, MessageFormatPart, PrimitiveType } from './formatters';
|
|
2
|
+
import { Formats, Formatters, FormatXMLElementFn, MessageFormatPart, PrimitiveType } from './formatters.js';
|
|
3
3
|
export interface Options extends Omit<ParserOptions, 'locale'> {
|
|
4
4
|
formatters?: Formatters;
|
|
5
5
|
}
|
package/src/core.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
4
3
|
Copyrights licensed under the New BSD License.
|
|
5
4
|
See the accompanying LICENSE file for terms.
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
|
|
12
|
-
var formatters_1 = require("./formatters");
|
|
6
|
+
import { __assign, __rest, __spreadArray } from "tslib";
|
|
7
|
+
import { memoize, strategies } from '@formatjs/fast-memoize';
|
|
8
|
+
import { parse, } from '@formatjs/icu-messageformat-parser';
|
|
9
|
+
import { formatToParts, PART_TYPE, } from './formatters.js';
|
|
13
10
|
// -- MessageFormat --------------------------------------------------------
|
|
14
11
|
function mergeConfig(c1, c2) {
|
|
15
12
|
if (!c2) {
|
|
16
13
|
return c1;
|
|
17
14
|
}
|
|
18
|
-
return
|
|
19
|
-
all[k] =
|
|
15
|
+
return __assign(__assign(__assign({}, c1), c2), Object.keys(c1).reduce(function (all, k) {
|
|
16
|
+
all[k] = __assign(__assign({}, c1[k]), c2[k]);
|
|
20
17
|
return all;
|
|
21
18
|
}, {}));
|
|
22
19
|
}
|
|
@@ -27,7 +24,7 @@ function mergeConfigs(defaultConfig, configs) {
|
|
|
27
24
|
return Object.keys(defaultConfig).reduce(function (all, k) {
|
|
28
25
|
all[k] = mergeConfig(defaultConfig[k], configs[k]);
|
|
29
26
|
return all;
|
|
30
|
-
},
|
|
27
|
+
}, __assign({}, defaultConfig));
|
|
31
28
|
}
|
|
32
29
|
function createFastMemoizeCache(store) {
|
|
33
30
|
return {
|
|
@@ -50,38 +47,38 @@ function createDefaultFormatters(cache) {
|
|
|
50
47
|
pluralRules: {},
|
|
51
48
|
}; }
|
|
52
49
|
return {
|
|
53
|
-
getNumberFormat:
|
|
50
|
+
getNumberFormat: memoize(function () {
|
|
54
51
|
var _a;
|
|
55
52
|
var args = [];
|
|
56
53
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
57
54
|
args[_i] = arguments[_i];
|
|
58
55
|
}
|
|
59
|
-
return new ((_a = Intl.NumberFormat).bind.apply(_a,
|
|
56
|
+
return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
60
57
|
}, {
|
|
61
58
|
cache: createFastMemoizeCache(cache.number),
|
|
62
|
-
strategy:
|
|
59
|
+
strategy: strategies.variadic,
|
|
63
60
|
}),
|
|
64
|
-
getDateTimeFormat:
|
|
61
|
+
getDateTimeFormat: memoize(function () {
|
|
65
62
|
var _a;
|
|
66
63
|
var args = [];
|
|
67
64
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
68
65
|
args[_i] = arguments[_i];
|
|
69
66
|
}
|
|
70
|
-
return new ((_a = Intl.DateTimeFormat).bind.apply(_a,
|
|
67
|
+
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
71
68
|
}, {
|
|
72
69
|
cache: createFastMemoizeCache(cache.dateTime),
|
|
73
|
-
strategy:
|
|
70
|
+
strategy: strategies.variadic,
|
|
74
71
|
}),
|
|
75
|
-
getPluralRules:
|
|
72
|
+
getPluralRules: memoize(function () {
|
|
76
73
|
var _a;
|
|
77
74
|
var args = [];
|
|
78
75
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
79
76
|
args[_i] = arguments[_i];
|
|
80
77
|
}
|
|
81
|
-
return new ((_a = Intl.PluralRules).bind.apply(_a,
|
|
78
|
+
return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
82
79
|
}, {
|
|
83
80
|
cache: createFastMemoizeCache(cache.pluralRules),
|
|
84
|
-
strategy:
|
|
81
|
+
strategy: strategies.variadic,
|
|
85
82
|
}),
|
|
86
83
|
};
|
|
87
84
|
}
|
|
@@ -102,7 +99,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
102
99
|
}
|
|
103
100
|
var result = parts.reduce(function (all, part) {
|
|
104
101
|
if (!all.length ||
|
|
105
|
-
part.type !==
|
|
102
|
+
part.type !== PART_TYPE.literal ||
|
|
106
103
|
typeof all[all.length - 1] !== 'string') {
|
|
107
104
|
all.push(part.value);
|
|
108
105
|
}
|
|
@@ -117,7 +114,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
117
114
|
return result;
|
|
118
115
|
};
|
|
119
116
|
this.formatToParts = function (values) {
|
|
120
|
-
return
|
|
117
|
+
return formatToParts(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
|
|
121
118
|
};
|
|
122
119
|
this.resolvedOptions = function () {
|
|
123
120
|
var _a;
|
|
@@ -135,9 +132,11 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
135
132
|
if (!IntlMessageFormat.__parse) {
|
|
136
133
|
throw new TypeError('IntlMessageFormat.__parse must be set to process `message` of type `string`');
|
|
137
134
|
}
|
|
138
|
-
var
|
|
135
|
+
var parseOpts = __rest(opts || {}
|
|
139
136
|
// Parse string messages into an AST.
|
|
140
|
-
|
|
137
|
+
, []);
|
|
138
|
+
// Parse string messages into an AST.
|
|
139
|
+
this.ast = IntlMessageFormat.__parse(message, __assign(__assign({}, parseOpts), { locale: this.resolvedLocale }));
|
|
141
140
|
}
|
|
142
141
|
else {
|
|
143
142
|
this.ast = message;
|
|
@@ -173,7 +172,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
173
172
|
}
|
|
174
173
|
return new Intl.Locale(typeof locales === 'string' ? locales : locales[0]);
|
|
175
174
|
};
|
|
176
|
-
IntlMessageFormat.__parse =
|
|
175
|
+
IntlMessageFormat.__parse = parse;
|
|
177
176
|
// Default format options used as the prototype of the `formats` provided to the
|
|
178
177
|
// constructor. These are used when constructing the internal Intl.NumberFormat
|
|
179
178
|
// and Intl.DateTimeFormat instances.
|
|
@@ -238,4 +237,4 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
238
237
|
};
|
|
239
238
|
return IntlMessageFormat;
|
|
240
239
|
}());
|
|
241
|
-
|
|
240
|
+
export { IntlMessageFormat };
|
package/src/error.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MissingValueError = exports.InvalidValueTypeError = exports.InvalidValueError = exports.FormatError = exports.ErrorCode = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var ErrorCode;
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
export var ErrorCode;
|
|
6
3
|
(function (ErrorCode) {
|
|
7
4
|
// When we have a placeholder but no value to format
|
|
8
5
|
ErrorCode["MISSING_VALUE"] = "MISSING_VALUE";
|
|
@@ -10,9 +7,9 @@ var ErrorCode;
|
|
|
10
7
|
ErrorCode["INVALID_VALUE"] = "INVALID_VALUE";
|
|
11
8
|
// When we need specific Intl API but it's not available
|
|
12
9
|
ErrorCode["MISSING_INTL_API"] = "MISSING_INTL_API";
|
|
13
|
-
})(ErrorCode || (
|
|
10
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
14
11
|
var FormatError = /** @class */ (function (_super) {
|
|
15
|
-
|
|
12
|
+
__extends(FormatError, _super);
|
|
16
13
|
function FormatError(msg, code, originalMessage) {
|
|
17
14
|
var _this = _super.call(this, msg) || this;
|
|
18
15
|
_this.code = code;
|
|
@@ -24,28 +21,28 @@ var FormatError = /** @class */ (function (_super) {
|
|
|
24
21
|
};
|
|
25
22
|
return FormatError;
|
|
26
23
|
}(Error));
|
|
27
|
-
|
|
24
|
+
export { FormatError };
|
|
28
25
|
var InvalidValueError = /** @class */ (function (_super) {
|
|
29
|
-
|
|
26
|
+
__extends(InvalidValueError, _super);
|
|
30
27
|
function InvalidValueError(variableId, value, options, originalMessage) {
|
|
31
28
|
return _super.call(this, "Invalid values for \"".concat(variableId, "\": \"").concat(value, "\". Options are \"").concat(Object.keys(options).join('", "'), "\""), ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
32
29
|
}
|
|
33
30
|
return InvalidValueError;
|
|
34
31
|
}(FormatError));
|
|
35
|
-
|
|
32
|
+
export { InvalidValueError };
|
|
36
33
|
var InvalidValueTypeError = /** @class */ (function (_super) {
|
|
37
|
-
|
|
34
|
+
__extends(InvalidValueTypeError, _super);
|
|
38
35
|
function InvalidValueTypeError(value, type, originalMessage) {
|
|
39
36
|
return _super.call(this, "Value for \"".concat(value, "\" must be of type ").concat(type), ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
40
37
|
}
|
|
41
38
|
return InvalidValueTypeError;
|
|
42
39
|
}(FormatError));
|
|
43
|
-
|
|
40
|
+
export { InvalidValueTypeError };
|
|
44
41
|
var MissingValueError = /** @class */ (function (_super) {
|
|
45
|
-
|
|
42
|
+
__extends(MissingValueError, _super);
|
|
46
43
|
function MissingValueError(variableId, originalMessage) {
|
|
47
44
|
return _super.call(this, "The intl string context variable \"".concat(variableId, "\" was not provided to the string \"").concat(originalMessage, "\""), ErrorCode.MISSING_VALUE, originalMessage) || this;
|
|
48
45
|
}
|
|
49
46
|
return MissingValueError;
|
|
50
47
|
}(FormatError));
|
|
51
|
-
|
|
48
|
+
export { MissingValueError };
|
package/src/formatters.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.isFormatXMLElementFn = isFormatXMLElementFn;
|
|
5
|
-
exports.formatToParts = formatToParts;
|
|
6
|
-
var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
|
|
7
|
-
var error_1 = require("./error");
|
|
8
|
-
var PART_TYPE;
|
|
1
|
+
import { isArgumentElement, isDateElement, isDateTimeSkeleton, isLiteralElement, isNumberElement, isNumberSkeleton, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, } from '@formatjs/icu-messageformat-parser';
|
|
2
|
+
import { ErrorCode, FormatError, InvalidValueError, InvalidValueTypeError, MissingValueError, } from './error.js';
|
|
3
|
+
export var PART_TYPE;
|
|
9
4
|
(function (PART_TYPE) {
|
|
10
5
|
PART_TYPE[PART_TYPE["literal"] = 0] = "literal";
|
|
11
6
|
PART_TYPE[PART_TYPE["object"] = 1] = "object";
|
|
12
|
-
})(PART_TYPE || (
|
|
7
|
+
})(PART_TYPE || (PART_TYPE = {}));
|
|
13
8
|
function mergeLiteral(parts) {
|
|
14
9
|
if (parts.length < 2) {
|
|
15
10
|
return parts;
|
|
@@ -27,15 +22,15 @@ function mergeLiteral(parts) {
|
|
|
27
22
|
return all;
|
|
28
23
|
}, []);
|
|
29
24
|
}
|
|
30
|
-
function isFormatXMLElementFn(el) {
|
|
25
|
+
export function isFormatXMLElementFn(el) {
|
|
31
26
|
return typeof el === 'function';
|
|
32
27
|
}
|
|
33
28
|
// TODO(skeleton): add skeleton support
|
|
34
|
-
function formatToParts(els, locales, formatters, formats, values, currentPluralValue,
|
|
29
|
+
export function formatToParts(els, locales, formatters, formats, values, currentPluralValue,
|
|
35
30
|
// For debugging
|
|
36
31
|
originalMessage) {
|
|
37
32
|
// Hot path for straight simple msg translations
|
|
38
|
-
if (els.length === 1 &&
|
|
33
|
+
if (els.length === 1 && isLiteralElement(els[0])) {
|
|
39
34
|
return [
|
|
40
35
|
{
|
|
41
36
|
type: PART_TYPE.literal,
|
|
@@ -47,7 +42,7 @@ originalMessage) {
|
|
|
47
42
|
for (var _i = 0, els_1 = els; _i < els_1.length; _i++) {
|
|
48
43
|
var el = els_1[_i];
|
|
49
44
|
// Exit early for string parts.
|
|
50
|
-
if (
|
|
45
|
+
if (isLiteralElement(el)) {
|
|
51
46
|
result.push({
|
|
52
47
|
type: PART_TYPE.literal,
|
|
53
48
|
value: el.value,
|
|
@@ -56,7 +51,7 @@ originalMessage) {
|
|
|
56
51
|
}
|
|
57
52
|
// TODO: should this part be literal type?
|
|
58
53
|
// Replace `#` in plural rules with the actual numeric value.
|
|
59
|
-
if (
|
|
54
|
+
if (isPoundElement(el)) {
|
|
60
55
|
if (typeof currentPluralValue === 'number') {
|
|
61
56
|
result.push({
|
|
62
57
|
type: PART_TYPE.literal,
|
|
@@ -68,10 +63,10 @@ originalMessage) {
|
|
|
68
63
|
var varName = el.value;
|
|
69
64
|
// Enforce that all required values are provided by the caller.
|
|
70
65
|
if (!(values && varName in values)) {
|
|
71
|
-
throw new
|
|
66
|
+
throw new MissingValueError(varName, originalMessage);
|
|
72
67
|
}
|
|
73
68
|
var value = values[varName];
|
|
74
|
-
if (
|
|
69
|
+
if (isArgumentElement(el)) {
|
|
75
70
|
if (!value || typeof value === 'string' || typeof value === 'number') {
|
|
76
71
|
value =
|
|
77
72
|
typeof value === 'string' || typeof value === 'number'
|
|
@@ -87,10 +82,10 @@ originalMessage) {
|
|
|
87
82
|
// Recursively format plural and select parts' option — which can be a
|
|
88
83
|
// nested pattern structure. The choosing of the option to use is
|
|
89
84
|
// abstracted-by and delegated-to the part helper object.
|
|
90
|
-
if (
|
|
85
|
+
if (isDateElement(el)) {
|
|
91
86
|
var style = typeof el.style === 'string'
|
|
92
87
|
? formats.date[el.style]
|
|
93
|
-
:
|
|
88
|
+
: isDateTimeSkeleton(el.style)
|
|
94
89
|
? el.style.parsedOptions
|
|
95
90
|
: undefined;
|
|
96
91
|
result.push({
|
|
@@ -101,10 +96,10 @@ originalMessage) {
|
|
|
101
96
|
});
|
|
102
97
|
continue;
|
|
103
98
|
}
|
|
104
|
-
if (
|
|
99
|
+
if (isTimeElement(el)) {
|
|
105
100
|
var style = typeof el.style === 'string'
|
|
106
101
|
? formats.time[el.style]
|
|
107
|
-
:
|
|
102
|
+
: isDateTimeSkeleton(el.style)
|
|
108
103
|
? el.style.parsedOptions
|
|
109
104
|
: formats.time.medium;
|
|
110
105
|
result.push({
|
|
@@ -115,10 +110,10 @@ originalMessage) {
|
|
|
115
110
|
});
|
|
116
111
|
continue;
|
|
117
112
|
}
|
|
118
|
-
if (
|
|
113
|
+
if (isNumberElement(el)) {
|
|
119
114
|
var style = typeof el.style === 'string'
|
|
120
115
|
? formats.number[el.style]
|
|
121
|
-
:
|
|
116
|
+
: isNumberSkeleton(el.style)
|
|
122
117
|
? el.style.parsedOptions
|
|
123
118
|
: undefined;
|
|
124
119
|
if (style && style.scale) {
|
|
@@ -134,11 +129,11 @@ originalMessage) {
|
|
|
134
129
|
});
|
|
135
130
|
continue;
|
|
136
131
|
}
|
|
137
|
-
if (
|
|
132
|
+
if (isTagElement(el)) {
|
|
138
133
|
var children = el.children, value_1 = el.value;
|
|
139
134
|
var formatFn = values[value_1];
|
|
140
135
|
if (!isFormatXMLElementFn(formatFn)) {
|
|
141
|
-
throw new
|
|
136
|
+
throw new InvalidValueTypeError(value_1, 'function', originalMessage);
|
|
142
137
|
}
|
|
143
138
|
var parts = formatToParts(children, locales, formatters, formats, values, currentPluralValue);
|
|
144
139
|
var chunks = formatFn(parts.map(function (p) { return p.value; }));
|
|
@@ -152,19 +147,19 @@ originalMessage) {
|
|
|
152
147
|
};
|
|
153
148
|
}));
|
|
154
149
|
}
|
|
155
|
-
if (
|
|
150
|
+
if (isSelectElement(el)) {
|
|
156
151
|
var opt = el.options[value] || el.options.other;
|
|
157
152
|
if (!opt) {
|
|
158
|
-
throw new
|
|
153
|
+
throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
159
154
|
}
|
|
160
155
|
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
|
|
161
156
|
continue;
|
|
162
157
|
}
|
|
163
|
-
if (
|
|
158
|
+
if (isPluralElement(el)) {
|
|
164
159
|
var opt = el.options["=".concat(value)];
|
|
165
160
|
if (!opt) {
|
|
166
161
|
if (!Intl.PluralRules) {
|
|
167
|
-
throw new
|
|
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);
|
|
168
163
|
}
|
|
169
164
|
var rule = formatters
|
|
170
165
|
.getPluralRules(locales, { type: el.pluralType })
|
|
@@ -172,7 +167,7 @@ originalMessage) {
|
|
|
172
167
|
opt = el.options[rule] || el.options.other;
|
|
173
168
|
}
|
|
174
169
|
if (!opt) {
|
|
175
|
-
throw new
|
|
170
|
+
throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
176
171
|
}
|
|
177
172
|
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values, value - (el.offset || 0)));
|
|
178
173
|
continue;
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
3
|
-
Copyrights licensed under the New BSD License.
|
|
4
|
-
See the accompanying LICENSE file for terms.
|
|
5
|
-
*/
|
|
6
|
-
import { IntlMessageFormat } from './src/core';
|
|
7
|
-
export * from './src/core';
|
|
8
|
-
export * from './src/error';
|
|
9
|
-
export * from './src/formatters';
|
|
10
|
-
export { IntlMessageFormat };
|
|
11
|
-
export default IntlMessageFormat;
|
package/lib/src/core.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { MessageFormatElement, parse, ParserOptions } from '@formatjs/icu-messageformat-parser';
|
|
2
|
-
import { Formats, Formatters, FormatXMLElementFn, MessageFormatPart, PrimitiveType } from './formatters';
|
|
3
|
-
export interface Options extends Omit<ParserOptions, 'locale'> {
|
|
4
|
-
formatters?: Formatters;
|
|
5
|
-
}
|
|
6
|
-
export declare class IntlMessageFormat {
|
|
7
|
-
private readonly ast;
|
|
8
|
-
private readonly locales;
|
|
9
|
-
private readonly resolvedLocale?;
|
|
10
|
-
private readonly formatters;
|
|
11
|
-
private readonly formats;
|
|
12
|
-
private readonly message;
|
|
13
|
-
private readonly formatterCache;
|
|
14
|
-
constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
|
|
15
|
-
format: <T = void>(values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>) => string | T | (string | T)[];
|
|
16
|
-
formatToParts: <T>(values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>) => MessageFormatPart<T>[];
|
|
17
|
-
resolvedOptions: () => {
|
|
18
|
-
locale: string;
|
|
19
|
-
};
|
|
20
|
-
getAst: () => MessageFormatElement[];
|
|
21
|
-
private static memoizedDefaultLocale;
|
|
22
|
-
static get defaultLocale(): string;
|
|
23
|
-
static resolveLocale: (locales: string | string[]) => Intl.Locale | undefined;
|
|
24
|
-
static __parse: typeof parse | undefined;
|
|
25
|
-
static formats: Formats;
|
|
26
|
-
}
|
package/lib/src/core.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
3
|
-
Copyrights licensed under the New BSD License.
|
|
4
|
-
See the accompanying LICENSE file for terms.
|
|
5
|
-
*/
|
|
6
|
-
import { __assign, __rest, __spreadArray } from "tslib";
|
|
7
|
-
import { memoize, strategies } from '@formatjs/fast-memoize';
|
|
8
|
-
import { parse, } from '@formatjs/icu-messageformat-parser';
|
|
9
|
-
import { formatToParts, PART_TYPE, } from './formatters';
|
|
10
|
-
// -- MessageFormat --------------------------------------------------------
|
|
11
|
-
function mergeConfig(c1, c2) {
|
|
12
|
-
if (!c2) {
|
|
13
|
-
return c1;
|
|
14
|
-
}
|
|
15
|
-
return __assign(__assign(__assign({}, (c1 || {})), (c2 || {})), Object.keys(c1).reduce(function (all, k) {
|
|
16
|
-
all[k] = __assign(__assign({}, c1[k]), (c2[k] || {}));
|
|
17
|
-
return all;
|
|
18
|
-
}, {}));
|
|
19
|
-
}
|
|
20
|
-
function mergeConfigs(defaultConfig, configs) {
|
|
21
|
-
if (!configs) {
|
|
22
|
-
return defaultConfig;
|
|
23
|
-
}
|
|
24
|
-
return Object.keys(defaultConfig).reduce(function (all, k) {
|
|
25
|
-
all[k] = mergeConfig(defaultConfig[k], configs[k]);
|
|
26
|
-
return all;
|
|
27
|
-
}, __assign({}, defaultConfig));
|
|
28
|
-
}
|
|
29
|
-
function createFastMemoizeCache(store) {
|
|
30
|
-
return {
|
|
31
|
-
create: function () {
|
|
32
|
-
return {
|
|
33
|
-
get: function (key) {
|
|
34
|
-
return store[key];
|
|
35
|
-
},
|
|
36
|
-
set: function (key, value) {
|
|
37
|
-
store[key] = value;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function createDefaultFormatters(cache) {
|
|
44
|
-
if (cache === void 0) { cache = {
|
|
45
|
-
number: {},
|
|
46
|
-
dateTime: {},
|
|
47
|
-
pluralRules: {},
|
|
48
|
-
}; }
|
|
49
|
-
return {
|
|
50
|
-
getNumberFormat: memoize(function () {
|
|
51
|
-
var _a;
|
|
52
|
-
var args = [];
|
|
53
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
54
|
-
args[_i] = arguments[_i];
|
|
55
|
-
}
|
|
56
|
-
return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
57
|
-
}, {
|
|
58
|
-
cache: createFastMemoizeCache(cache.number),
|
|
59
|
-
strategy: strategies.variadic,
|
|
60
|
-
}),
|
|
61
|
-
getDateTimeFormat: memoize(function () {
|
|
62
|
-
var _a;
|
|
63
|
-
var args = [];
|
|
64
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
65
|
-
args[_i] = arguments[_i];
|
|
66
|
-
}
|
|
67
|
-
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
68
|
-
}, {
|
|
69
|
-
cache: createFastMemoizeCache(cache.dateTime),
|
|
70
|
-
strategy: strategies.variadic,
|
|
71
|
-
}),
|
|
72
|
-
getPluralRules: memoize(function () {
|
|
73
|
-
var _a;
|
|
74
|
-
var args = [];
|
|
75
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
76
|
-
args[_i] = arguments[_i];
|
|
77
|
-
}
|
|
78
|
-
return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
79
|
-
}, {
|
|
80
|
-
cache: createFastMemoizeCache(cache.pluralRules),
|
|
81
|
-
strategy: strategies.variadic,
|
|
82
|
-
}),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
var IntlMessageFormat = /** @class */ (function () {
|
|
86
|
-
function IntlMessageFormat(message, locales, overrideFormats, opts) {
|
|
87
|
-
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
|
|
88
|
-
var _this = this;
|
|
89
|
-
this.formatterCache = {
|
|
90
|
-
number: {},
|
|
91
|
-
dateTime: {},
|
|
92
|
-
pluralRules: {},
|
|
93
|
-
};
|
|
94
|
-
this.format = function (values) {
|
|
95
|
-
var parts = _this.formatToParts(values);
|
|
96
|
-
// Hot path for straight simple msg translations
|
|
97
|
-
if (parts.length === 1) {
|
|
98
|
-
return parts[0].value;
|
|
99
|
-
}
|
|
100
|
-
var result = parts.reduce(function (all, part) {
|
|
101
|
-
if (!all.length ||
|
|
102
|
-
part.type !== PART_TYPE.literal ||
|
|
103
|
-
typeof all[all.length - 1] !== 'string') {
|
|
104
|
-
all.push(part.value);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
all[all.length - 1] += part.value;
|
|
108
|
-
}
|
|
109
|
-
return all;
|
|
110
|
-
}, []);
|
|
111
|
-
if (result.length <= 1) {
|
|
112
|
-
return result[0] || '';
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
115
|
-
};
|
|
116
|
-
this.formatToParts = function (values) {
|
|
117
|
-
return formatToParts(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
|
|
118
|
-
};
|
|
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
|
-
};
|
|
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);
|
|
130
|
-
if (typeof message === 'string') {
|
|
131
|
-
this.message = message;
|
|
132
|
-
if (!IntlMessageFormat.__parse) {
|
|
133
|
-
throw new TypeError('IntlMessageFormat.__parse must be set to process `message` of type `string`');
|
|
134
|
-
}
|
|
135
|
-
var _a = opts || {}, formatters = _a.formatters, parseOpts = __rest(_a, ["formatters"]);
|
|
136
|
-
// Parse string messages into an AST.
|
|
137
|
-
this.ast = IntlMessageFormat.__parse(message, __assign(__assign({}, parseOpts), { locale: this.resolvedLocale }));
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
this.ast = message;
|
|
141
|
-
}
|
|
142
|
-
if (!Array.isArray(this.ast)) {
|
|
143
|
-
throw new TypeError('A message must be provided as a String or AST.');
|
|
144
|
-
}
|
|
145
|
-
// Creates a new object with the specified `formats` merged with the default
|
|
146
|
-
// formats.
|
|
147
|
-
this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
|
|
148
|
-
this.formatters =
|
|
149
|
-
(opts && opts.formatters) || createDefaultFormatters(this.formatterCache);
|
|
150
|
-
}
|
|
151
|
-
Object.defineProperty(IntlMessageFormat, "defaultLocale", {
|
|
152
|
-
get: function () {
|
|
153
|
-
if (!IntlMessageFormat.memoizedDefaultLocale) {
|
|
154
|
-
IntlMessageFormat.memoizedDefaultLocale =
|
|
155
|
-
new Intl.NumberFormat().resolvedOptions().locale;
|
|
156
|
-
}
|
|
157
|
-
return IntlMessageFormat.memoizedDefaultLocale;
|
|
158
|
-
},
|
|
159
|
-
enumerable: false,
|
|
160
|
-
configurable: true
|
|
161
|
-
});
|
|
162
|
-
IntlMessageFormat.memoizedDefaultLocale = null;
|
|
163
|
-
IntlMessageFormat.resolveLocale = function (locales) {
|
|
164
|
-
if (typeof Intl.Locale === 'undefined') {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
var supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales);
|
|
168
|
-
if (supportedLocales.length > 0) {
|
|
169
|
-
return new Intl.Locale(supportedLocales[0]);
|
|
170
|
-
}
|
|
171
|
-
return new Intl.Locale(typeof locales === 'string' ? locales : locales[0]);
|
|
172
|
-
};
|
|
173
|
-
IntlMessageFormat.__parse = parse;
|
|
174
|
-
// Default format options used as the prototype of the `formats` provided to the
|
|
175
|
-
// constructor. These are used when constructing the internal Intl.NumberFormat
|
|
176
|
-
// and Intl.DateTimeFormat instances.
|
|
177
|
-
IntlMessageFormat.formats = {
|
|
178
|
-
number: {
|
|
179
|
-
integer: {
|
|
180
|
-
maximumFractionDigits: 0,
|
|
181
|
-
},
|
|
182
|
-
currency: {
|
|
183
|
-
style: 'currency',
|
|
184
|
-
},
|
|
185
|
-
percent: {
|
|
186
|
-
style: 'percent',
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
date: {
|
|
190
|
-
short: {
|
|
191
|
-
month: 'numeric',
|
|
192
|
-
day: 'numeric',
|
|
193
|
-
year: '2-digit',
|
|
194
|
-
},
|
|
195
|
-
medium: {
|
|
196
|
-
month: 'short',
|
|
197
|
-
day: 'numeric',
|
|
198
|
-
year: 'numeric',
|
|
199
|
-
},
|
|
200
|
-
long: {
|
|
201
|
-
month: 'long',
|
|
202
|
-
day: 'numeric',
|
|
203
|
-
year: 'numeric',
|
|
204
|
-
},
|
|
205
|
-
full: {
|
|
206
|
-
weekday: 'long',
|
|
207
|
-
month: 'long',
|
|
208
|
-
day: 'numeric',
|
|
209
|
-
year: 'numeric',
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
time: {
|
|
213
|
-
short: {
|
|
214
|
-
hour: 'numeric',
|
|
215
|
-
minute: 'numeric',
|
|
216
|
-
},
|
|
217
|
-
medium: {
|
|
218
|
-
hour: 'numeric',
|
|
219
|
-
minute: 'numeric',
|
|
220
|
-
second: 'numeric',
|
|
221
|
-
},
|
|
222
|
-
long: {
|
|
223
|
-
hour: 'numeric',
|
|
224
|
-
minute: 'numeric',
|
|
225
|
-
second: 'numeric',
|
|
226
|
-
timeZoneName: 'short',
|
|
227
|
-
},
|
|
228
|
-
full: {
|
|
229
|
-
hour: 'numeric',
|
|
230
|
-
minute: 'numeric',
|
|
231
|
-
second: 'numeric',
|
|
232
|
-
timeZoneName: 'short',
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
return IntlMessageFormat;
|
|
237
|
-
}());
|
|
238
|
-
export { IntlMessageFormat };
|
package/lib/src/error.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export declare enum ErrorCode {
|
|
2
|
-
MISSING_VALUE = "MISSING_VALUE",
|
|
3
|
-
INVALID_VALUE = "INVALID_VALUE",
|
|
4
|
-
MISSING_INTL_API = "MISSING_INTL_API"
|
|
5
|
-
}
|
|
6
|
-
export declare class FormatError extends Error {
|
|
7
|
-
readonly code: ErrorCode;
|
|
8
|
-
/**
|
|
9
|
-
* Original message we're trying to format
|
|
10
|
-
* `undefined` if we're only dealing w/ AST
|
|
11
|
-
*
|
|
12
|
-
* @type {(string | undefined)}
|
|
13
|
-
* @memberof FormatError
|
|
14
|
-
*/
|
|
15
|
-
readonly originalMessage: string | undefined;
|
|
16
|
-
constructor(msg: string, code: ErrorCode, originalMessage?: string);
|
|
17
|
-
toString(): string;
|
|
18
|
-
}
|
|
19
|
-
export declare class InvalidValueError extends FormatError {
|
|
20
|
-
constructor(variableId: string, value: any, options: string[], originalMessage?: string);
|
|
21
|
-
}
|
|
22
|
-
export declare class InvalidValueTypeError extends FormatError {
|
|
23
|
-
constructor(value: any, type: string, originalMessage?: string);
|
|
24
|
-
}
|
|
25
|
-
export declare class MissingValueError extends FormatError {
|
|
26
|
-
constructor(variableId: string, originalMessage?: string);
|
|
27
|
-
}
|
package/lib/src/error.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
|
-
export var ErrorCode;
|
|
3
|
-
(function (ErrorCode) {
|
|
4
|
-
// When we have a placeholder but no value to format
|
|
5
|
-
ErrorCode["MISSING_VALUE"] = "MISSING_VALUE";
|
|
6
|
-
// When value supplied is invalid
|
|
7
|
-
ErrorCode["INVALID_VALUE"] = "INVALID_VALUE";
|
|
8
|
-
// When we need specific Intl API but it's not available
|
|
9
|
-
ErrorCode["MISSING_INTL_API"] = "MISSING_INTL_API";
|
|
10
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
11
|
-
var FormatError = /** @class */ (function (_super) {
|
|
12
|
-
__extends(FormatError, _super);
|
|
13
|
-
function FormatError(msg, code, originalMessage) {
|
|
14
|
-
var _this = _super.call(this, msg) || this;
|
|
15
|
-
_this.code = code;
|
|
16
|
-
_this.originalMessage = originalMessage;
|
|
17
|
-
return _this;
|
|
18
|
-
}
|
|
19
|
-
FormatError.prototype.toString = function () {
|
|
20
|
-
return "[formatjs Error: ".concat(this.code, "] ").concat(this.message);
|
|
21
|
-
};
|
|
22
|
-
return FormatError;
|
|
23
|
-
}(Error));
|
|
24
|
-
export { FormatError };
|
|
25
|
-
var InvalidValueError = /** @class */ (function (_super) {
|
|
26
|
-
__extends(InvalidValueError, _super);
|
|
27
|
-
function InvalidValueError(variableId, value, options, originalMessage) {
|
|
28
|
-
return _super.call(this, "Invalid values for \"".concat(variableId, "\": \"").concat(value, "\". Options are \"").concat(Object.keys(options).join('", "'), "\""), ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
29
|
-
}
|
|
30
|
-
return InvalidValueError;
|
|
31
|
-
}(FormatError));
|
|
32
|
-
export { InvalidValueError };
|
|
33
|
-
var InvalidValueTypeError = /** @class */ (function (_super) {
|
|
34
|
-
__extends(InvalidValueTypeError, _super);
|
|
35
|
-
function InvalidValueTypeError(value, type, originalMessage) {
|
|
36
|
-
return _super.call(this, "Value for \"".concat(value, "\" must be of type ").concat(type), ErrorCode.INVALID_VALUE, originalMessage) || this;
|
|
37
|
-
}
|
|
38
|
-
return InvalidValueTypeError;
|
|
39
|
-
}(FormatError));
|
|
40
|
-
export { InvalidValueTypeError };
|
|
41
|
-
var MissingValueError = /** @class */ (function (_super) {
|
|
42
|
-
__extends(MissingValueError, _super);
|
|
43
|
-
function MissingValueError(variableId, originalMessage) {
|
|
44
|
-
return _super.call(this, "The intl string context variable \"".concat(variableId, "\" was not provided to the string \"").concat(originalMessage, "\""), ErrorCode.MISSING_VALUE, originalMessage) || this;
|
|
45
|
-
}
|
|
46
|
-
return MissingValueError;
|
|
47
|
-
}(FormatError));
|
|
48
|
-
export { MissingValueError };
|
package/lib/src/formatters.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
|
|
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
|
-
type Format<Source = string> = Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
|
|
14
|
-
export interface Formats {
|
|
15
|
-
number: Record<Format<'number'>, NumberFormatOptions>;
|
|
16
|
-
date: Record<Format<'date'>, Intl.DateTimeFormatOptions>;
|
|
17
|
-
time: Record<Format<'time'>, Intl.DateTimeFormatOptions>;
|
|
18
|
-
}
|
|
19
|
-
export interface FormatterCache {
|
|
20
|
-
number: Record<string, NumberFormatOptions>;
|
|
21
|
-
dateTime: Record<string, Intl.DateTimeFormat>;
|
|
22
|
-
pluralRules: Record<string, Intl.PluralRules>;
|
|
23
|
-
}
|
|
24
|
-
export interface Formatters {
|
|
25
|
-
getNumberFormat(locals?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
|
|
26
|
-
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
|
|
27
|
-
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
|
|
28
|
-
}
|
|
29
|
-
export declare enum PART_TYPE {
|
|
30
|
-
literal = 0,
|
|
31
|
-
object = 1
|
|
32
|
-
}
|
|
33
|
-
export interface LiteralPart {
|
|
34
|
-
type: PART_TYPE.literal;
|
|
35
|
-
value: string;
|
|
36
|
-
}
|
|
37
|
-
export interface ObjectPart<T = any> {
|
|
38
|
-
type: PART_TYPE.object;
|
|
39
|
-
value: T;
|
|
40
|
-
}
|
|
41
|
-
export type MessageFormatPart<T> = LiteralPart | ObjectPart<T>;
|
|
42
|
-
export type PrimitiveType = string | number | boolean | null | undefined | Date;
|
|
43
|
-
export declare function isFormatXMLElementFn<T>(el: PrimitiveType | T | FormatXMLElementFn<T>): el is FormatXMLElementFn<T>;
|
|
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>[];
|
|
45
|
-
export type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (parts: Array<string | T>) => R;
|
|
46
|
-
export {};
|
package/lib/src/formatters.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { isArgumentElement, isDateElement, isDateTimeSkeleton, isLiteralElement, isNumberElement, isNumberSkeleton, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, } from '@formatjs/icu-messageformat-parser';
|
|
2
|
-
import { ErrorCode, FormatError, InvalidValueError, InvalidValueTypeError, MissingValueError, } from './error';
|
|
3
|
-
export var PART_TYPE;
|
|
4
|
-
(function (PART_TYPE) {
|
|
5
|
-
PART_TYPE[PART_TYPE["literal"] = 0] = "literal";
|
|
6
|
-
PART_TYPE[PART_TYPE["object"] = 1] = "object";
|
|
7
|
-
})(PART_TYPE || (PART_TYPE = {}));
|
|
8
|
-
function mergeLiteral(parts) {
|
|
9
|
-
if (parts.length < 2) {
|
|
10
|
-
return parts;
|
|
11
|
-
}
|
|
12
|
-
return parts.reduce(function (all, part) {
|
|
13
|
-
var lastPart = all[all.length - 1];
|
|
14
|
-
if (!lastPart ||
|
|
15
|
-
lastPart.type !== PART_TYPE.literal ||
|
|
16
|
-
part.type !== PART_TYPE.literal) {
|
|
17
|
-
all.push(part);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
lastPart.value += part.value;
|
|
21
|
-
}
|
|
22
|
-
return all;
|
|
23
|
-
}, []);
|
|
24
|
-
}
|
|
25
|
-
export function isFormatXMLElementFn(el) {
|
|
26
|
-
return typeof el === 'function';
|
|
27
|
-
}
|
|
28
|
-
// TODO(skeleton): add skeleton support
|
|
29
|
-
export function formatToParts(els, locales, formatters, formats, values, currentPluralValue,
|
|
30
|
-
// For debugging
|
|
31
|
-
originalMessage) {
|
|
32
|
-
// Hot path for straight simple msg translations
|
|
33
|
-
if (els.length === 1 && isLiteralElement(els[0])) {
|
|
34
|
-
return [
|
|
35
|
-
{
|
|
36
|
-
type: PART_TYPE.literal,
|
|
37
|
-
value: els[0].value,
|
|
38
|
-
},
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
var result = [];
|
|
42
|
-
for (var _i = 0, els_1 = els; _i < els_1.length; _i++) {
|
|
43
|
-
var el = els_1[_i];
|
|
44
|
-
// Exit early for string parts.
|
|
45
|
-
if (isLiteralElement(el)) {
|
|
46
|
-
result.push({
|
|
47
|
-
type: PART_TYPE.literal,
|
|
48
|
-
value: el.value,
|
|
49
|
-
});
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
// TODO: should this part be literal type?
|
|
53
|
-
// Replace `#` in plural rules with the actual numeric value.
|
|
54
|
-
if (isPoundElement(el)) {
|
|
55
|
-
if (typeof currentPluralValue === 'number') {
|
|
56
|
-
result.push({
|
|
57
|
-
type: PART_TYPE.literal,
|
|
58
|
-
value: formatters.getNumberFormat(locales).format(currentPluralValue),
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
var varName = el.value;
|
|
64
|
-
// Enforce that all required values are provided by the caller.
|
|
65
|
-
if (!(values && varName in values)) {
|
|
66
|
-
throw new MissingValueError(varName, originalMessage);
|
|
67
|
-
}
|
|
68
|
-
var value = values[varName];
|
|
69
|
-
if (isArgumentElement(el)) {
|
|
70
|
-
if (!value || typeof value === 'string' || typeof value === 'number') {
|
|
71
|
-
value =
|
|
72
|
-
typeof value === 'string' || typeof value === 'number'
|
|
73
|
-
? String(value)
|
|
74
|
-
: '';
|
|
75
|
-
}
|
|
76
|
-
result.push({
|
|
77
|
-
type: typeof value === 'string' ? PART_TYPE.literal : PART_TYPE.object,
|
|
78
|
-
value: value,
|
|
79
|
-
});
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
// Recursively format plural and select parts' option — which can be a
|
|
83
|
-
// nested pattern structure. The choosing of the option to use is
|
|
84
|
-
// abstracted-by and delegated-to the part helper object.
|
|
85
|
-
if (isDateElement(el)) {
|
|
86
|
-
var style = typeof el.style === 'string'
|
|
87
|
-
? formats.date[el.style]
|
|
88
|
-
: isDateTimeSkeleton(el.style)
|
|
89
|
-
? el.style.parsedOptions
|
|
90
|
-
: undefined;
|
|
91
|
-
result.push({
|
|
92
|
-
type: PART_TYPE.literal,
|
|
93
|
-
value: formatters
|
|
94
|
-
.getDateTimeFormat(locales, style)
|
|
95
|
-
.format(value),
|
|
96
|
-
});
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (isTimeElement(el)) {
|
|
100
|
-
var style = typeof el.style === 'string'
|
|
101
|
-
? formats.time[el.style]
|
|
102
|
-
: isDateTimeSkeleton(el.style)
|
|
103
|
-
? el.style.parsedOptions
|
|
104
|
-
: formats.time.medium;
|
|
105
|
-
result.push({
|
|
106
|
-
type: PART_TYPE.literal,
|
|
107
|
-
value: formatters
|
|
108
|
-
.getDateTimeFormat(locales, style)
|
|
109
|
-
.format(value),
|
|
110
|
-
});
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (isNumberElement(el)) {
|
|
114
|
-
var style = typeof el.style === 'string'
|
|
115
|
-
? formats.number[el.style]
|
|
116
|
-
: isNumberSkeleton(el.style)
|
|
117
|
-
? el.style.parsedOptions
|
|
118
|
-
: undefined;
|
|
119
|
-
if (style && style.scale) {
|
|
120
|
-
value =
|
|
121
|
-
value *
|
|
122
|
-
(style.scale || 1);
|
|
123
|
-
}
|
|
124
|
-
result.push({
|
|
125
|
-
type: PART_TYPE.literal,
|
|
126
|
-
value: formatters
|
|
127
|
-
.getNumberFormat(locales, style)
|
|
128
|
-
.format(value),
|
|
129
|
-
});
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (isTagElement(el)) {
|
|
133
|
-
var children = el.children, value_1 = el.value;
|
|
134
|
-
var formatFn = values[value_1];
|
|
135
|
-
if (!isFormatXMLElementFn(formatFn)) {
|
|
136
|
-
throw new InvalidValueTypeError(value_1, 'function', originalMessage);
|
|
137
|
-
}
|
|
138
|
-
var parts = formatToParts(children, locales, formatters, formats, values, currentPluralValue);
|
|
139
|
-
var chunks = formatFn(parts.map(function (p) { return p.value; }));
|
|
140
|
-
if (!Array.isArray(chunks)) {
|
|
141
|
-
chunks = [chunks];
|
|
142
|
-
}
|
|
143
|
-
result.push.apply(result, chunks.map(function (c) {
|
|
144
|
-
return {
|
|
145
|
-
type: typeof c === 'string' ? PART_TYPE.literal : PART_TYPE.object,
|
|
146
|
-
value: c,
|
|
147
|
-
};
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
if (isSelectElement(el)) {
|
|
151
|
-
var opt = el.options[value] || el.options.other;
|
|
152
|
-
if (!opt) {
|
|
153
|
-
throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
154
|
-
}
|
|
155
|
-
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
if (isPluralElement(el)) {
|
|
159
|
-
var opt = el.options["=".concat(value)];
|
|
160
|
-
if (!opt) {
|
|
161
|
-
if (!Intl.PluralRules) {
|
|
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
|
-
}
|
|
164
|
-
var rule = formatters
|
|
165
|
-
.getPluralRules(locales, { type: el.pluralType })
|
|
166
|
-
.select(value - (el.offset || 0));
|
|
167
|
-
opt = el.options[rule] || el.options.other;
|
|
168
|
-
}
|
|
169
|
-
if (!opt) {
|
|
170
|
-
throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
|
|
171
|
-
}
|
|
172
|
-
result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values, value - (el.offset || 0)));
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return mergeLiteral(result);
|
|
177
|
-
}
|