intl-messageformat 10.6.0 → 10.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/intl-messageformat.esm.js +197 -141
- package/intl-messageformat.iife.js +364 -350
- package/lib/src/core.d.ts +2 -2
- package/lib/src/core.js +1 -1
- package/package.json +5 -5
- package/src/core.d.ts +2 -2
- package/src/core.js +1 -1
- package/src/formatters.js +3 -3
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// ../../../../../../../../execroot/formatjs/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/lib/index.js
|
|
1
|
+
// node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/lib/index.js
|
|
9
2
|
function memoize(fn, options) {
|
|
10
3
|
var cache = options && options.cache ? options.cache : cacheDefault;
|
|
11
4
|
var serializer = options && options.serializer ? options.serializer : serializerDefault;
|
|
@@ -72,7 +65,7 @@ var strategies = {
|
|
|
72
65
|
monadic: strategyMonadic
|
|
73
66
|
};
|
|
74
67
|
|
|
75
|
-
//
|
|
68
|
+
// node_modules/.aspect_rules_js/tslib@2.7.0/node_modules/tslib/tslib.es6.mjs
|
|
76
69
|
var __assign = function() {
|
|
77
70
|
__assign = Object.assign || function __assign2(t) {
|
|
78
71
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -86,7 +79,7 @@ var __assign = function() {
|
|
|
86
79
|
return __assign.apply(this, arguments);
|
|
87
80
|
};
|
|
88
81
|
|
|
89
|
-
//
|
|
82
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/lib/error.js
|
|
90
83
|
var ErrorKind;
|
|
91
84
|
(function(ErrorKind2) {
|
|
92
85
|
ErrorKind2[ErrorKind2["EXPECT_ARGUMENT_CLOSING_BRACE"] = 1] = "EXPECT_ARGUMENT_CLOSING_BRACE";
|
|
@@ -117,7 +110,7 @@ var ErrorKind;
|
|
|
117
110
|
ErrorKind2[ErrorKind2["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG";
|
|
118
111
|
})(ErrorKind || (ErrorKind = {}));
|
|
119
112
|
|
|
120
|
-
//
|
|
113
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/lib/types.js
|
|
121
114
|
var TYPE;
|
|
122
115
|
(function(TYPE2) {
|
|
123
116
|
TYPE2[TYPE2["literal"] = 0] = "literal";
|
|
@@ -169,10 +162,10 @@ function isDateTimeSkeleton(el) {
|
|
|
169
162
|
return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.dateTime);
|
|
170
163
|
}
|
|
171
164
|
|
|
172
|
-
//
|
|
165
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/lib/regex.generated.js
|
|
173
166
|
var SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
|
174
167
|
|
|
175
|
-
//
|
|
168
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/lib/date-time.js
|
|
176
169
|
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;
|
|
177
170
|
function parseDateTimeSkeleton(skeleton) {
|
|
178
171
|
var result = {};
|
|
@@ -273,10 +266,10 @@ function parseDateTimeSkeleton(skeleton) {
|
|
|
273
266
|
return result;
|
|
274
267
|
}
|
|
275
268
|
|
|
276
|
-
//
|
|
269
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/lib/regex.generated.js
|
|
277
270
|
var WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/i;
|
|
278
271
|
|
|
279
|
-
//
|
|
272
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-skeleton-parser@0.0.0/node_modules/@formatjs/icu-skeleton-parser/lib/number.js
|
|
280
273
|
function parseNumberSkeletonFromString(skeleton) {
|
|
281
274
|
if (skeleton.length === 0) {
|
|
282
275
|
throw new Error("Number skeleton cannot be empty");
|
|
@@ -563,7 +556,7 @@ function parseNumberSkeleton(tokens) {
|
|
|
563
556
|
return result;
|
|
564
557
|
}
|
|
565
558
|
|
|
566
|
-
//
|
|
559
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/lib/time-data.generated.js
|
|
567
560
|
var timeData = {
|
|
568
561
|
"001": [
|
|
569
562
|
"H",
|
|
@@ -1974,7 +1967,7 @@ var timeData = {
|
|
|
1974
1967
|
]
|
|
1975
1968
|
};
|
|
1976
1969
|
|
|
1977
|
-
//
|
|
1970
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/lib/date-time-pattern-generator.js
|
|
1978
1971
|
function getBestPattern(skeleton, locale) {
|
|
1979
1972
|
var skeletonCopy = "";
|
|
1980
1973
|
for (var patternPos = 0; patternPos < skeleton.length; patternPos++) {
|
|
@@ -2036,7 +2029,7 @@ function getDefaultHourSymbolFromLocale(locale) {
|
|
|
2036
2029
|
return hourCycles[0];
|
|
2037
2030
|
}
|
|
2038
2031
|
|
|
2039
|
-
//
|
|
2032
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/lib/parser.js
|
|
2040
2033
|
var _a;
|
|
2041
2034
|
var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(SPACE_SEPARATOR_REGEX.source, "*"));
|
|
2042
2035
|
var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(SPACE_SEPARATOR_REGEX.source, "*$"));
|
|
@@ -2841,7 +2834,7 @@ function _isPatternSyntax(c) {
|
|
|
2841
2834
|
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;
|
|
2842
2835
|
}
|
|
2843
2836
|
|
|
2844
|
-
//
|
|
2837
|
+
// node_modules/.aspect_rules_js/@formatjs+icu-messageformat-parser@0.0.0/node_modules/@formatjs/icu-messageformat-parser/lib/index.js
|
|
2845
2838
|
function pruneLocation(els) {
|
|
2846
2839
|
els.forEach(function(el) {
|
|
2847
2840
|
delete el.location;
|
|
@@ -2877,13 +2870,13 @@ function parse(message, opts) {
|
|
|
2877
2870
|
return result.val;
|
|
2878
2871
|
}
|
|
2879
2872
|
|
|
2880
|
-
//
|
|
2881
|
-
var ErrorCode
|
|
2882
|
-
(function(ErrorCode2) {
|
|
2873
|
+
// packages/intl-messageformat/src/error.ts
|
|
2874
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
2883
2875
|
ErrorCode2["MISSING_VALUE"] = "MISSING_VALUE";
|
|
2884
2876
|
ErrorCode2["INVALID_VALUE"] = "INVALID_VALUE";
|
|
2885
2877
|
ErrorCode2["MISSING_INTL_API"] = "MISSING_INTL_API";
|
|
2886
|
-
|
|
2878
|
+
return ErrorCode2;
|
|
2879
|
+
})(ErrorCode || {});
|
|
2887
2880
|
var FormatError = class extends Error {
|
|
2888
2881
|
code;
|
|
2889
2882
|
/**
|
|
@@ -2905,33 +2898,47 @@ var FormatError = class extends Error {
|
|
|
2905
2898
|
};
|
|
2906
2899
|
var InvalidValueError = class extends FormatError {
|
|
2907
2900
|
constructor(variableId, value, options, originalMessage) {
|
|
2908
|
-
super(
|
|
2901
|
+
super(
|
|
2902
|
+
`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(
|
|
2903
|
+
options
|
|
2904
|
+
).join('", "')}"`,
|
|
2905
|
+
"INVALID_VALUE" /* INVALID_VALUE */,
|
|
2906
|
+
originalMessage
|
|
2907
|
+
);
|
|
2909
2908
|
}
|
|
2910
2909
|
};
|
|
2911
2910
|
var InvalidValueTypeError = class extends FormatError {
|
|
2912
2911
|
constructor(value, type, originalMessage) {
|
|
2913
|
-
super(
|
|
2912
|
+
super(
|
|
2913
|
+
`Value for "${value}" must be of type ${type}`,
|
|
2914
|
+
"INVALID_VALUE" /* INVALID_VALUE */,
|
|
2915
|
+
originalMessage
|
|
2916
|
+
);
|
|
2914
2917
|
}
|
|
2915
2918
|
};
|
|
2916
2919
|
var MissingValueError = class extends FormatError {
|
|
2917
2920
|
constructor(variableId, originalMessage) {
|
|
2918
|
-
super(
|
|
2921
|
+
super(
|
|
2922
|
+
`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`,
|
|
2923
|
+
"MISSING_VALUE" /* MISSING_VALUE */,
|
|
2924
|
+
originalMessage
|
|
2925
|
+
);
|
|
2919
2926
|
}
|
|
2920
2927
|
};
|
|
2921
2928
|
|
|
2922
|
-
//
|
|
2923
|
-
var PART_TYPE
|
|
2924
|
-
(function(PART_TYPE2) {
|
|
2929
|
+
// packages/intl-messageformat/src/formatters.ts
|
|
2930
|
+
var PART_TYPE = /* @__PURE__ */ ((PART_TYPE2) => {
|
|
2925
2931
|
PART_TYPE2[PART_TYPE2["literal"] = 0] = "literal";
|
|
2926
2932
|
PART_TYPE2[PART_TYPE2["object"] = 1] = "object";
|
|
2927
|
-
|
|
2933
|
+
return PART_TYPE2;
|
|
2934
|
+
})(PART_TYPE || {});
|
|
2928
2935
|
function mergeLiteral(parts) {
|
|
2929
2936
|
if (parts.length < 2) {
|
|
2930
2937
|
return parts;
|
|
2931
2938
|
}
|
|
2932
2939
|
return parts.reduce((all, part) => {
|
|
2933
2940
|
const lastPart = all[all.length - 1];
|
|
2934
|
-
if (!lastPart || lastPart.type !==
|
|
2941
|
+
if (!lastPart || lastPart.type !== 0 /* literal */ || part.type !== 0 /* literal */) {
|
|
2935
2942
|
all.push(part);
|
|
2936
2943
|
} else {
|
|
2937
2944
|
lastPart.value += part.value;
|
|
@@ -2946,7 +2953,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2946
2953
|
if (els.length === 1 && isLiteralElement(els[0])) {
|
|
2947
2954
|
return [
|
|
2948
2955
|
{
|
|
2949
|
-
type:
|
|
2956
|
+
type: 0 /* literal */,
|
|
2950
2957
|
value: els[0].value
|
|
2951
2958
|
}
|
|
2952
2959
|
];
|
|
@@ -2955,7 +2962,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2955
2962
|
for (const el of els) {
|
|
2956
2963
|
if (isLiteralElement(el)) {
|
|
2957
2964
|
result.push({
|
|
2958
|
-
type:
|
|
2965
|
+
type: 0 /* literal */,
|
|
2959
2966
|
value: el.value
|
|
2960
2967
|
});
|
|
2961
2968
|
continue;
|
|
@@ -2963,7 +2970,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2963
2970
|
if (isPoundElement(el)) {
|
|
2964
2971
|
if (typeof currentPluralValue === "number") {
|
|
2965
2972
|
result.push({
|
|
2966
|
-
type:
|
|
2973
|
+
type: 0 /* literal */,
|
|
2967
2974
|
value: formatters.getNumberFormat(locales).format(currentPluralValue)
|
|
2968
2975
|
});
|
|
2969
2976
|
}
|
|
@@ -2979,7 +2986,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2979
2986
|
value = typeof value === "string" || typeof value === "number" ? String(value) : "";
|
|
2980
2987
|
}
|
|
2981
2988
|
result.push({
|
|
2982
|
-
type: typeof value === "string" ?
|
|
2989
|
+
type: typeof value === "string" ? 0 /* literal */ : 1 /* object */,
|
|
2983
2990
|
value
|
|
2984
2991
|
});
|
|
2985
2992
|
continue;
|
|
@@ -2987,7 +2994,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2987
2994
|
if (isDateElement(el)) {
|
|
2988
2995
|
const style = typeof el.style === "string" ? formats.date[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : void 0;
|
|
2989
2996
|
result.push({
|
|
2990
|
-
type:
|
|
2997
|
+
type: 0 /* literal */,
|
|
2991
2998
|
value: formatters.getDateTimeFormat(locales, style).format(value)
|
|
2992
2999
|
});
|
|
2993
3000
|
continue;
|
|
@@ -2995,7 +3002,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
2995
3002
|
if (isTimeElement(el)) {
|
|
2996
3003
|
const style = typeof el.style === "string" ? formats.time[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : formats.time.medium;
|
|
2997
3004
|
result.push({
|
|
2998
|
-
type:
|
|
3005
|
+
type: 0 /* literal */,
|
|
2999
3006
|
value: formatters.getDateTimeFormat(locales, style).format(value)
|
|
3000
3007
|
});
|
|
3001
3008
|
continue;
|
|
@@ -3006,7 +3013,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
3006
3013
|
value = value * (style.scale || 1);
|
|
3007
3014
|
}
|
|
3008
3015
|
result.push({
|
|
3009
|
-
type:
|
|
3016
|
+
type: 0 /* literal */,
|
|
3010
3017
|
value: formatters.getNumberFormat(locales, style).format(value)
|
|
3011
3018
|
});
|
|
3012
3019
|
continue;
|
|
@@ -3017,48 +3024,82 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
|
|
|
3017
3024
|
if (!isFormatXMLElementFn(formatFn)) {
|
|
3018
3025
|
throw new InvalidValueTypeError(value2, "function", originalMessage);
|
|
3019
3026
|
}
|
|
3020
|
-
const parts = formatToParts(
|
|
3027
|
+
const parts = formatToParts(
|
|
3028
|
+
children,
|
|
3029
|
+
locales,
|
|
3030
|
+
formatters,
|
|
3031
|
+
formats,
|
|
3032
|
+
values,
|
|
3033
|
+
currentPluralValue
|
|
3034
|
+
);
|
|
3021
3035
|
let chunks = formatFn(parts.map((p) => p.value));
|
|
3022
3036
|
if (!Array.isArray(chunks)) {
|
|
3023
3037
|
chunks = [chunks];
|
|
3024
3038
|
}
|
|
3025
|
-
result.push(
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3039
|
+
result.push(
|
|
3040
|
+
...chunks.map((c) => {
|
|
3041
|
+
return {
|
|
3042
|
+
type: typeof c === "string" ? 0 /* literal */ : 1 /* object */,
|
|
3043
|
+
value: c
|
|
3044
|
+
};
|
|
3045
|
+
})
|
|
3046
|
+
);
|
|
3031
3047
|
}
|
|
3032
3048
|
if (isSelectElement(el)) {
|
|
3033
3049
|
const opt = el.options[value] || el.options.other;
|
|
3034
3050
|
if (!opt) {
|
|
3035
|
-
throw new InvalidValueError(
|
|
3051
|
+
throw new InvalidValueError(
|
|
3052
|
+
el.value,
|
|
3053
|
+
value,
|
|
3054
|
+
Object.keys(el.options),
|
|
3055
|
+
originalMessage
|
|
3056
|
+
);
|
|
3036
3057
|
}
|
|
3037
|
-
result.push(
|
|
3058
|
+
result.push(
|
|
3059
|
+
...formatToParts(opt.value, locales, formatters, formats, values)
|
|
3060
|
+
);
|
|
3038
3061
|
continue;
|
|
3039
3062
|
}
|
|
3040
3063
|
if (isPluralElement(el)) {
|
|
3041
3064
|
let opt = el.options[`=${value}`];
|
|
3042
3065
|
if (!opt) {
|
|
3043
3066
|
if (!Intl.PluralRules) {
|
|
3044
|
-
throw new FormatError(
|
|
3067
|
+
throw new FormatError(
|
|
3068
|
+
`Intl.PluralRules is not available in this environment.
|
|
3045
3069
|
Try polyfilling it using "@formatjs/intl-pluralrules"
|
|
3046
|
-
`,
|
|
3070
|
+
`,
|
|
3071
|
+
"MISSING_INTL_API" /* MISSING_INTL_API */,
|
|
3072
|
+
originalMessage
|
|
3073
|
+
);
|
|
3047
3074
|
}
|
|
3048
3075
|
const rule = formatters.getPluralRules(locales, { type: el.pluralType }).select(value - (el.offset || 0));
|
|
3049
3076
|
opt = el.options[rule] || el.options.other;
|
|
3050
3077
|
}
|
|
3051
3078
|
if (!opt) {
|
|
3052
|
-
throw new InvalidValueError(
|
|
3079
|
+
throw new InvalidValueError(
|
|
3080
|
+
el.value,
|
|
3081
|
+
value,
|
|
3082
|
+
Object.keys(el.options),
|
|
3083
|
+
originalMessage
|
|
3084
|
+
);
|
|
3053
3085
|
}
|
|
3054
|
-
result.push(
|
|
3086
|
+
result.push(
|
|
3087
|
+
...formatToParts(
|
|
3088
|
+
opt.value,
|
|
3089
|
+
locales,
|
|
3090
|
+
formatters,
|
|
3091
|
+
formats,
|
|
3092
|
+
values,
|
|
3093
|
+
value - (el.offset || 0)
|
|
3094
|
+
)
|
|
3095
|
+
);
|
|
3055
3096
|
continue;
|
|
3056
3097
|
}
|
|
3057
3098
|
}
|
|
3058
3099
|
return mergeLiteral(result);
|
|
3059
3100
|
}
|
|
3060
3101
|
|
|
3061
|
-
//
|
|
3102
|
+
// packages/intl-messageformat/src/core.ts
|
|
3062
3103
|
function mergeConfig(c1, c2) {
|
|
3063
3104
|
if (!c2) {
|
|
3064
3105
|
return c1;
|
|
@@ -3079,10 +3120,13 @@ function mergeConfigs(defaultConfig, configs) {
|
|
|
3079
3120
|
if (!configs) {
|
|
3080
3121
|
return defaultConfig;
|
|
3081
3122
|
}
|
|
3082
|
-
return Object.keys(defaultConfig).reduce(
|
|
3083
|
-
all
|
|
3084
|
-
|
|
3085
|
-
|
|
3123
|
+
return Object.keys(defaultConfig).reduce(
|
|
3124
|
+
(all, k) => {
|
|
3125
|
+
all[k] = mergeConfig(defaultConfig[k], configs[k]);
|
|
3126
|
+
return all;
|
|
3127
|
+
},
|
|
3128
|
+
{ ...defaultConfig }
|
|
3129
|
+
);
|
|
3086
3130
|
}
|
|
3087
3131
|
function createFastMemoizeCache(store) {
|
|
3088
3132
|
return {
|
|
@@ -3118,7 +3162,7 @@ function createDefaultFormatters(cache = {
|
|
|
3118
3162
|
})
|
|
3119
3163
|
};
|
|
3120
3164
|
}
|
|
3121
|
-
var
|
|
3165
|
+
var IntlMessageFormat = class _IntlMessageFormat {
|
|
3122
3166
|
ast;
|
|
3123
3167
|
locales;
|
|
3124
3168
|
resolvedLocale;
|
|
@@ -3136,7 +3180,9 @@ var _IntlMessageFormat = class {
|
|
|
3136
3180
|
if (typeof message === "string") {
|
|
3137
3181
|
this.message = message;
|
|
3138
3182
|
if (!_IntlMessageFormat.__parse) {
|
|
3139
|
-
throw new TypeError(
|
|
3183
|
+
throw new TypeError(
|
|
3184
|
+
"IntlMessageFormat.__parse must be set to process `message` of type `string`"
|
|
3185
|
+
);
|
|
3140
3186
|
}
|
|
3141
3187
|
const { formatters, ...parseOpts } = opts || {};
|
|
3142
3188
|
this.ast = _IntlMessageFormat.__parse(message, {
|
|
@@ -3157,109 +3203,119 @@ var _IntlMessageFormat = class {
|
|
|
3157
3203
|
if (parts.length === 1) {
|
|
3158
3204
|
return parts[0].value;
|
|
3159
3205
|
}
|
|
3160
|
-
const result = parts.reduce(
|
|
3161
|
-
|
|
3162
|
-
all.
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3206
|
+
const result = parts.reduce(
|
|
3207
|
+
(all, part) => {
|
|
3208
|
+
if (!all.length || part.type !== 0 /* literal */ || typeof all[all.length - 1] !== "string") {
|
|
3209
|
+
all.push(part.value);
|
|
3210
|
+
} else {
|
|
3211
|
+
all[all.length - 1] += part.value;
|
|
3212
|
+
}
|
|
3213
|
+
return all;
|
|
3214
|
+
},
|
|
3215
|
+
[]
|
|
3216
|
+
);
|
|
3168
3217
|
if (result.length <= 1) {
|
|
3169
3218
|
return result[0] || "";
|
|
3170
3219
|
}
|
|
3171
3220
|
return result;
|
|
3172
3221
|
};
|
|
3173
|
-
formatToParts = (values) => formatToParts(
|
|
3222
|
+
formatToParts = (values) => formatToParts(
|
|
3223
|
+
this.ast,
|
|
3224
|
+
this.locales,
|
|
3225
|
+
this.formatters,
|
|
3226
|
+
this.formats,
|
|
3227
|
+
values,
|
|
3228
|
+
void 0,
|
|
3229
|
+
this.message
|
|
3230
|
+
);
|
|
3174
3231
|
resolvedOptions = () => ({
|
|
3175
3232
|
locale: this.resolvedLocale?.toString() || Intl.NumberFormat.supportedLocalesOf(this.locales)[0]
|
|
3176
3233
|
});
|
|
3177
3234
|
getAst = () => this.ast;
|
|
3235
|
+
static memoizedDefaultLocale = null;
|
|
3178
3236
|
static get defaultLocale() {
|
|
3179
3237
|
if (!_IntlMessageFormat.memoizedDefaultLocale) {
|
|
3180
3238
|
_IntlMessageFormat.memoizedDefaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
|
|
3181
3239
|
}
|
|
3182
3240
|
return _IntlMessageFormat.memoizedDefaultLocale;
|
|
3183
3241
|
}
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
__publicField(IntlMessageFormat, "resolveLocale", (locales) => {
|
|
3188
|
-
if (typeof Intl.Locale === "undefined") {
|
|
3189
|
-
return;
|
|
3190
|
-
}
|
|
3191
|
-
const supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales);
|
|
3192
|
-
if (supportedLocales.length > 0) {
|
|
3193
|
-
return new Intl.Locale(supportedLocales[0]);
|
|
3194
|
-
}
|
|
3195
|
-
return new Intl.Locale(typeof locales === "string" ? locales : locales[0]);
|
|
3196
|
-
});
|
|
3197
|
-
__publicField(IntlMessageFormat, "__parse", parse);
|
|
3198
|
-
// Default format options used as the prototype of the `formats` provided to the
|
|
3199
|
-
// constructor. These are used when constructing the internal Intl.NumberFormat
|
|
3200
|
-
// and Intl.DateTimeFormat instances.
|
|
3201
|
-
__publicField(IntlMessageFormat, "formats", {
|
|
3202
|
-
number: {
|
|
3203
|
-
integer: {
|
|
3204
|
-
maximumFractionDigits: 0
|
|
3205
|
-
},
|
|
3206
|
-
currency: {
|
|
3207
|
-
style: "currency"
|
|
3208
|
-
},
|
|
3209
|
-
percent: {
|
|
3210
|
-
style: "percent"
|
|
3242
|
+
static resolveLocale = (locales) => {
|
|
3243
|
+
if (typeof Intl.Locale === "undefined") {
|
|
3244
|
+
return;
|
|
3211
3245
|
}
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
month: "numeric",
|
|
3216
|
-
day: "numeric",
|
|
3217
|
-
year: "2-digit"
|
|
3218
|
-
},
|
|
3219
|
-
medium: {
|
|
3220
|
-
month: "short",
|
|
3221
|
-
day: "numeric",
|
|
3222
|
-
year: "numeric"
|
|
3223
|
-
},
|
|
3224
|
-
long: {
|
|
3225
|
-
month: "long",
|
|
3226
|
-
day: "numeric",
|
|
3227
|
-
year: "numeric"
|
|
3228
|
-
},
|
|
3229
|
-
full: {
|
|
3230
|
-
weekday: "long",
|
|
3231
|
-
month: "long",
|
|
3232
|
-
day: "numeric",
|
|
3233
|
-
year: "numeric"
|
|
3246
|
+
const supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales);
|
|
3247
|
+
if (supportedLocales.length > 0) {
|
|
3248
|
+
return new Intl.Locale(supportedLocales[0]);
|
|
3234
3249
|
}
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3250
|
+
return new Intl.Locale(typeof locales === "string" ? locales : locales[0]);
|
|
3251
|
+
};
|
|
3252
|
+
static __parse = parse;
|
|
3253
|
+
// Default format options used as the prototype of the `formats` provided to the
|
|
3254
|
+
// constructor. These are used when constructing the internal Intl.NumberFormat
|
|
3255
|
+
// and Intl.DateTimeFormat instances.
|
|
3256
|
+
static formats = {
|
|
3257
|
+
number: {
|
|
3258
|
+
integer: {
|
|
3259
|
+
maximumFractionDigits: 0
|
|
3260
|
+
},
|
|
3261
|
+
currency: {
|
|
3262
|
+
style: "currency"
|
|
3263
|
+
},
|
|
3264
|
+
percent: {
|
|
3265
|
+
style: "percent"
|
|
3266
|
+
}
|
|
3245
3267
|
},
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3268
|
+
date: {
|
|
3269
|
+
short: {
|
|
3270
|
+
month: "numeric",
|
|
3271
|
+
day: "numeric",
|
|
3272
|
+
year: "2-digit"
|
|
3273
|
+
},
|
|
3274
|
+
medium: {
|
|
3275
|
+
month: "short",
|
|
3276
|
+
day: "numeric",
|
|
3277
|
+
year: "numeric"
|
|
3278
|
+
},
|
|
3279
|
+
long: {
|
|
3280
|
+
month: "long",
|
|
3281
|
+
day: "numeric",
|
|
3282
|
+
year: "numeric"
|
|
3283
|
+
},
|
|
3284
|
+
full: {
|
|
3285
|
+
weekday: "long",
|
|
3286
|
+
month: "long",
|
|
3287
|
+
day: "numeric",
|
|
3288
|
+
year: "numeric"
|
|
3289
|
+
}
|
|
3251
3290
|
},
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3291
|
+
time: {
|
|
3292
|
+
short: {
|
|
3293
|
+
hour: "numeric",
|
|
3294
|
+
minute: "numeric"
|
|
3295
|
+
},
|
|
3296
|
+
medium: {
|
|
3297
|
+
hour: "numeric",
|
|
3298
|
+
minute: "numeric",
|
|
3299
|
+
second: "numeric"
|
|
3300
|
+
},
|
|
3301
|
+
long: {
|
|
3302
|
+
hour: "numeric",
|
|
3303
|
+
minute: "numeric",
|
|
3304
|
+
second: "numeric",
|
|
3305
|
+
timeZoneName: "short"
|
|
3306
|
+
},
|
|
3307
|
+
full: {
|
|
3308
|
+
hour: "numeric",
|
|
3309
|
+
minute: "numeric",
|
|
3310
|
+
second: "numeric",
|
|
3311
|
+
timeZoneName: "short"
|
|
3312
|
+
}
|
|
3257
3313
|
}
|
|
3258
|
-
}
|
|
3259
|
-
}
|
|
3314
|
+
};
|
|
3315
|
+
};
|
|
3260
3316
|
|
|
3261
|
-
//
|
|
3262
|
-
var
|
|
3317
|
+
// packages/intl-messageformat/index.ts
|
|
3318
|
+
var intl_messageformat_default = IntlMessageFormat;
|
|
3263
3319
|
export {
|
|
3264
3320
|
ErrorCode,
|
|
3265
3321
|
FormatError,
|
|
@@ -3268,7 +3324,7 @@ export {
|
|
|
3268
3324
|
InvalidValueTypeError,
|
|
3269
3325
|
MissingValueError,
|
|
3270
3326
|
PART_TYPE,
|
|
3271
|
-
|
|
3327
|
+
intl_messageformat_default as default,
|
|
3272
3328
|
formatToParts,
|
|
3273
3329
|
isFormatXMLElementFn
|
|
3274
3330
|
};
|