@common.js/icu-minify 4.13.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jan Amann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @common.js/icu-minify
2
+
3
+ The [icu-minify](https://www.npmjs.com/package/icu-minify) package exported as CommonJS modules.
4
+
5
+ Exported from [icu-minify@4.13.1](https://www.npmjs.com/package/icu-minify/v/4.13.1) using https://github.com/etienne-martin/common.js.
package/compile.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Needed for projects with `moduleResolution: 'node'`
2
+ export {default} from './dist/types/compile.d.ts';
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return compile;
9
+ }
10
+ });
11
+ var _icuMessageformatParser = require("@formatjs/icu-messageformat-parser");
12
+ var _typesDl2AHteJs = require("./types-Dl2aHte_.js");
13
+ function _arrayLikeToArray(arr, len) {
14
+ if (len == null || len > arr.length) len = arr.length;
15
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
16
+ return arr2;
17
+ }
18
+ function _arrayWithHoles(arr) {
19
+ if (Array.isArray(arr)) return arr;
20
+ }
21
+ function _arrayWithoutHoles(arr) {
22
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
23
+ }
24
+ function _iterableToArray(iter) {
25
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
26
+ }
27
+ function _iterableToArrayLimit(arr, i) {
28
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
29
+ if (_i == null) return;
30
+ var _arr = [];
31
+ var _n = true;
32
+ var _d = false;
33
+ var _s, _e;
34
+ try {
35
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
36
+ _arr.push(_s.value);
37
+ if (i && _arr.length === i) break;
38
+ }
39
+ } catch (err) {
40
+ _d = true;
41
+ _e = err;
42
+ } finally{
43
+ try {
44
+ if (!_n && _i["return"] != null) _i["return"]();
45
+ } finally{
46
+ if (_d) throw _e;
47
+ }
48
+ }
49
+ return _arr;
50
+ }
51
+ function _nonIterableRest() {
52
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
53
+ }
54
+ function _nonIterableSpread() {
55
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _slicedToArray(arr, i) {
58
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
59
+ }
60
+ function _toConsumableArray(arr) {
61
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
62
+ }
63
+ function _unsupportedIterableToArray(o, minLen) {
64
+ if (!o) return;
65
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
66
+ var n = Object.prototype.toString.call(o).slice(8, -1);
67
+ if (n === "Object" && o.constructor) n = o.constructor.name;
68
+ if (n === "Map" || n === "Set") return Array.from(n);
69
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
70
+ }
71
+ function compile(message) {
72
+ var ast = (0, _icuMessageformatParser.parse)(message);
73
+ var compiled = compileNodes(ast);
74
+ if (compiled.length === 0) {
75
+ return "";
76
+ }
77
+ if (compiled.length === 1 && typeof compiled[0] === "string") {
78
+ return compiled[0];
79
+ }
80
+ return compiled;
81
+ }
82
+ function compileNodes(nodes) {
83
+ var result = [];
84
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
85
+ try {
86
+ for(var _iterator = nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
87
+ var node = _step.value;
88
+ var compiled = compileNode(node);
89
+ if (typeof compiled === "string" && result.length > 0 && typeof result[result.length - 1] === "string") {
90
+ result[result.length - 1] += compiled;
91
+ } else {
92
+ result.push(compiled);
93
+ }
94
+ }
95
+ } catch (err) {
96
+ _didIteratorError = true;
97
+ _iteratorError = err;
98
+ } finally{
99
+ try {
100
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
101
+ _iterator.return();
102
+ }
103
+ } finally{
104
+ if (_didIteratorError) {
105
+ throw _iteratorError;
106
+ }
107
+ }
108
+ }
109
+ return result;
110
+ }
111
+ function compileNodesToNode(nodes) {
112
+ var compiled = compileNodes(nodes);
113
+ if (compiled.length === 0) {
114
+ return "";
115
+ }
116
+ if (compiled.length === 1) {
117
+ var node = compiled[0];
118
+ // Only unwrap strings and pound signs, not array-based nodes (tags, typed nodes)
119
+ // This preserves structure for formatBranch to correctly identify single nodes vs arrays
120
+ if (typeof node === "string" || node === _typesDl2AHteJs.T) {
121
+ return node;
122
+ }
123
+ }
124
+ return compiled;
125
+ }
126
+ function compileNode(node) {
127
+ switch(node.type){
128
+ case _icuMessageformatParser.TYPE.literal:
129
+ return node.value;
130
+ case _icuMessageformatParser.TYPE.argument:
131
+ return [
132
+ node.value
133
+ ];
134
+ case _icuMessageformatParser.TYPE.number:
135
+ return compileNumber(node);
136
+ case _icuMessageformatParser.TYPE.date:
137
+ return compileDate(node);
138
+ case _icuMessageformatParser.TYPE.time:
139
+ return compileTime(node);
140
+ case _icuMessageformatParser.TYPE.select:
141
+ return compileSelect(node);
142
+ case _icuMessageformatParser.TYPE.plural:
143
+ return compilePlural(node);
144
+ case _icuMessageformatParser.TYPE.pound:
145
+ return _typesDl2AHteJs.T;
146
+ case _icuMessageformatParser.TYPE.tag:
147
+ return compileTag(node);
148
+ default:
149
+ throw new Error("Unknown AST node type: ".concat(node.type));
150
+ }
151
+ }
152
+ function compileNumber(node) {
153
+ var result = [
154
+ node.value,
155
+ _typesDl2AHteJs.a
156
+ ];
157
+ var style = compileNumberStyle(node.style);
158
+ if (style !== undefined) {
159
+ result.push(style);
160
+ }
161
+ return result;
162
+ }
163
+ function compileNumberStyle(style) {
164
+ if (!style) {
165
+ return undefined;
166
+ }
167
+ if (typeof style === "string") {
168
+ return style;
169
+ }
170
+ if ("parsedOptions" in style) {
171
+ var opts = style.parsedOptions;
172
+ return Object.keys(opts).length > 0 ? opts : undefined;
173
+ }
174
+ return undefined;
175
+ }
176
+ function compileDate(node) {
177
+ var result = [
178
+ node.value,
179
+ _typesDl2AHteJs.b
180
+ ];
181
+ var style = compileDateTimeStyle(node.style);
182
+ if (style !== undefined) {
183
+ result.push(style);
184
+ }
185
+ return result;
186
+ }
187
+ function compileTime(node) {
188
+ var result = [
189
+ node.value,
190
+ _typesDl2AHteJs.c
191
+ ];
192
+ var style = compileDateTimeStyle(node.style);
193
+ if (style !== undefined) {
194
+ result.push(style);
195
+ }
196
+ return result;
197
+ }
198
+ function compileDateTimeStyle(style) {
199
+ if (!style) {
200
+ return undefined;
201
+ }
202
+ if (typeof style === "string") {
203
+ return style;
204
+ }
205
+ if ("parsedOptions" in style) {
206
+ var opts = style.parsedOptions;
207
+ return Object.keys(opts).length > 0 ? opts : undefined;
208
+ }
209
+ return undefined;
210
+ }
211
+ function compileSelect(node) {
212
+ var options = Object.create(null);
213
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
214
+ try {
215
+ for(var _iterator = Object.entries(node.options)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
216
+ var _value = _slicedToArray(_step.value, 2), key = _value[0], option = _value[1];
217
+ options[key] = compileNodesToNode(option.value);
218
+ }
219
+ } catch (err) {
220
+ _didIteratorError = true;
221
+ _iteratorError = err;
222
+ } finally{
223
+ try {
224
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
225
+ _iterator.return();
226
+ }
227
+ } finally{
228
+ if (_didIteratorError) {
229
+ throw _iteratorError;
230
+ }
231
+ }
232
+ }
233
+ return [
234
+ node.value,
235
+ _typesDl2AHteJs.d,
236
+ options
237
+ ];
238
+ }
239
+ // Plural offset is not supported
240
+ function compilePlural(node) {
241
+ if (node.offset) {
242
+ throw new Error("Plural offsets are not supported");
243
+ }
244
+ var options = Object.create(null);
245
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
246
+ try {
247
+ for(var _iterator = Object.entries(node.options)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
248
+ var _value = _slicedToArray(_step.value, 2), key = _value[0], option = _value[1];
249
+ options[key] = compileNodesToNode(option.value);
250
+ }
251
+ } catch (err) {
252
+ _didIteratorError = true;
253
+ _iteratorError = err;
254
+ } finally{
255
+ try {
256
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
257
+ _iterator.return();
258
+ }
259
+ } finally{
260
+ if (_didIteratorError) {
261
+ throw _iteratorError;
262
+ }
263
+ }
264
+ }
265
+ return [
266
+ node.value,
267
+ node.pluralType === "ordinal" ? _typesDl2AHteJs.e : _typesDl2AHteJs.f,
268
+ options
269
+ ];
270
+ }
271
+ function compileTag(node) {
272
+ var children = compileNodes(node.children);
273
+ var result = [
274
+ node.value
275
+ ];
276
+ // Tags have no type number - detected at runtime by typeof node[1] !== 'number'
277
+ // Empty tags get an empty string child to distinguish from simple arguments
278
+ if (children.length === 0) {
279
+ result.push("");
280
+ } else {
281
+ var _result;
282
+ (_result = result).push.apply(_result, _toConsumableArray(children));
283
+ }
284
+ return result;
285
+ }
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return format;
9
+ }
10
+ });
11
+ var _typesDl2AHteJs = require("./types-Dl2aHte_.js");
12
+ function _arrayLikeToArray(arr, len) {
13
+ if (len == null || len > arr.length) len = arr.length;
14
+ for(var i1 = 0, arr2 = new Array(len); i1 < len; i1++)arr2[i1] = arr[i1];
15
+ return arr2;
16
+ }
17
+ function _arrayWithHoles(arr) {
18
+ if (Array.isArray(arr)) return arr;
19
+ }
20
+ function _arrayWithoutHoles(arr) {
21
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
22
+ }
23
+ function _defineProperty(obj, key, value) {
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value: value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else {
32
+ obj[key] = value;
33
+ }
34
+ return obj;
35
+ }
36
+ function _instanceof(left, right) {
37
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
38
+ return !!right[Symbol.hasInstance](left);
39
+ } else {
40
+ return left instanceof right;
41
+ }
42
+ }
43
+ function _iterableToArray(iter) {
44
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
45
+ }
46
+ function _nonIterableRest() {
47
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
48
+ }
49
+ function _nonIterableSpread() {
50
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
51
+ }
52
+ function _objectSpread(target) {
53
+ for(var i1 = 1; i1 < arguments.length; i1++){
54
+ var source = arguments[i1] != null ? arguments[i1] : {};
55
+ var ownKeys = Object.keys(source);
56
+ if (typeof Object.getOwnPropertySymbols === "function") {
57
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
58
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
59
+ }));
60
+ }
61
+ ownKeys.forEach(function(key) {
62
+ _defineProperty(target, key, source[key]);
63
+ });
64
+ }
65
+ return target;
66
+ }
67
+ function ownKeys(object, enumerableOnly) {
68
+ var keys = Object.keys(object);
69
+ if (Object.getOwnPropertySymbols) {
70
+ var symbols = Object.getOwnPropertySymbols(object);
71
+ if (enumerableOnly) {
72
+ symbols = symbols.filter(function(sym) {
73
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
74
+ });
75
+ }
76
+ keys.push.apply(keys, symbols);
77
+ }
78
+ return keys;
79
+ }
80
+ function _objectSpreadProps(target, source) {
81
+ source = source != null ? source : {};
82
+ if (Object.getOwnPropertyDescriptors) {
83
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
84
+ } else {
85
+ ownKeys(Object(source)).forEach(function(key) {
86
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
87
+ });
88
+ }
89
+ return target;
90
+ }
91
+ function _toArray(arr) {
92
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
93
+ }
94
+ function _toConsumableArray(arr) {
95
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
96
+ }
97
+ var _typeof = function(obj) {
98
+ "@swc/helpers - typeof";
99
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
100
+ };
101
+ function _unsupportedIterableToArray(o, minLen) {
102
+ if (!o) return;
103
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
104
+ var n = Object.prototype.toString.call(o).slice(8, -1);
105
+ if (n === "Object" && o.constructor) n = o.constructor.name;
106
+ if (n === "Map" || n === "Set") return Array.from(n);
107
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
108
+ }
109
+ // Re-export CompiledMessage type for consumers
110
+ // Could potentially share this with `use-intl` if we had a shared package for both
111
+ function format(message, locale) {
112
+ var values = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, options = arguments.length > 3 ? arguments[3] : void 0;
113
+ // Hot path for plain strings
114
+ if (typeof message === "string") {
115
+ return message;
116
+ }
117
+ var result = formatNodes(message, locale, values, options, undefined);
118
+ return optimizeResult(result);
119
+ }
120
+ function formatNodes(nodes, locale, values, options, pluralCtx) {
121
+ var result = [];
122
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
123
+ try {
124
+ for(var _iterator = nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
125
+ var node = _step.value;
126
+ var formatted = formatNode(node, locale, values, options, pluralCtx);
127
+ if (Array.isArray(formatted)) {
128
+ var _result;
129
+ (_result = result).push.apply(_result, _toConsumableArray(formatted));
130
+ } else {
131
+ result.push(formatted);
132
+ }
133
+ }
134
+ } catch (err) {
135
+ _didIteratorError = true;
136
+ _iteratorError = err;
137
+ } finally{
138
+ try {
139
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
140
+ _iterator.return();
141
+ }
142
+ } finally{
143
+ if (_didIteratorError) {
144
+ throw _iteratorError;
145
+ }
146
+ }
147
+ }
148
+ return result;
149
+ }
150
+ function formatNode(node, locale, values, options, rawPluralCtx) {
151
+ if (typeof node === "string") {
152
+ return node;
153
+ }
154
+ if (node === _typesDl2AHteJs.T) {
155
+ if (!rawPluralCtx) {
156
+ throw new Error("# used outside of plural context");
157
+ }
158
+ var pluralCtx = rawPluralCtx;
159
+ return options.formatters.getNumberFormat(pluralCtx.locale).format(pluralCtx.value);
160
+ }
161
+ var _node = _toArray(node), name = _node[0], type = _node[1], rest = _node.slice(2);
162
+ // Simple argument: ["name"]
163
+ if (type === undefined) {
164
+ var value = getValue(values, name);
165
+ {
166
+ if (typeof value === "boolean") {
167
+ throw new Error('Invalid value for argument "'.concat(name, '": Boolean values are not supported and should be converted to strings if needed.'));
168
+ }
169
+ if (_instanceof(value, Date)) {
170
+ throw new Error('Invalid value for argument "'.concat(name, '": Date values are not supported for plain parameters. Use date formatting instead (e.g. {').concat(name, ", date})."));
171
+ }
172
+ }
173
+ return String(value);
174
+ }
175
+ // Tag: ["tagName", child1, child2, ...] - detected by non-number or pound marker
176
+ if (typeof type !== "number" || type === _typesDl2AHteJs.T) {
177
+ return formatTag(name, [
178
+ type
179
+ ].concat(_toConsumableArray(rest)), locale, values, options, rawPluralCtx);
180
+ }
181
+ // Typed nodes: ["name", TYPE, ...]
182
+ switch(type){
183
+ case _typesDl2AHteJs.d:
184
+ return formatSelect(name, rest[0], locale, values, options, rawPluralCtx);
185
+ case _typesDl2AHteJs.f:
186
+ return formatPlural(name, rest[0], locale, values, options, "cardinal");
187
+ case _typesDl2AHteJs.e:
188
+ return formatPlural(name, rest[0], locale, values, options, "ordinal");
189
+ case _typesDl2AHteJs.a:
190
+ return formatNumberValue(name, rest[0], locale, values, options);
191
+ case _typesDl2AHteJs.b:
192
+ return formatDateTimeValue(name, rest[0], locale, values, options, "date");
193
+ case _typesDl2AHteJs.c:
194
+ return formatDateTimeValue(name, rest[0], locale, values, options, "time");
195
+ default:
196
+ {
197
+ throw new Error("Unknown compiled node type: ".concat(type));
198
+ }
199
+ }
200
+ }
201
+ function getValue(values, name) {
202
+ if (!(name in values)) {
203
+ throw new Error('Missing value for argument "'.concat(name, '"'));
204
+ }
205
+ return values[name];
206
+ }
207
+ function formatSelect(name, options, locale, values, formatOptions, pluralCtx) {
208
+ var value = String(getValue(values, name));
209
+ var _value;
210
+ var branch = (_value = options[value]) !== null && _value !== void 0 ? _value : options.other;
211
+ if (!branch) {
212
+ throw new Error('No matching branch for select "'.concat(name, '" with value "').concat(value, '"'));
213
+ }
214
+ return formatBranch(branch, locale, values, formatOptions, pluralCtx);
215
+ }
216
+ function formatPlural(name, options, locale, values, formatOptions, pluralType) {
217
+ var rawValue = getValue(values, name);
218
+ if (typeof rawValue !== "number") {
219
+ throw new Error('Expected number for plural argument "'.concat(name, '", got ').concat(typeof rawValue === "undefined" ? "undefined" : _typeof(rawValue)));
220
+ }
221
+ var value = rawValue;
222
+ var exactKey = "=".concat(value);
223
+ if (exactKey in options) {
224
+ return formatBranch(options[exactKey], locale, values, formatOptions, {
225
+ value: value,
226
+ locale: locale
227
+ });
228
+ }
229
+ var category = formatOptions.formatters.getPluralRules(locale, {
230
+ type: pluralType
231
+ }).select(value);
232
+ var _category;
233
+ var branch = (_category = options[category]) !== null && _category !== void 0 ? _category : options.other;
234
+ if (!branch) {
235
+ throw new Error('No matching branch for plural "'.concat(name, '" with category "').concat(category, '"'));
236
+ }
237
+ return formatBranch(branch, locale, values, formatOptions, {
238
+ value: value,
239
+ locale: locale
240
+ });
241
+ }
242
+ function formatBranch(branch, locale, values, formatOptions, pluralCtx) {
243
+ if (typeof branch === "string") {
244
+ return branch;
245
+ }
246
+ if (branch === _typesDl2AHteJs.T) {
247
+ return formatNode(branch, locale, values, formatOptions, pluralCtx);
248
+ }
249
+ // Branch is an array - either a single complex node wrapped in array, or multiple nodes
250
+ // formatNodes handles both correctly via formatNode's tag detection
251
+ return formatNodes(branch, locale, values, formatOptions, pluralCtx);
252
+ }
253
+ function formatNumberValue(name, style, locale, values, formatOptions) {
254
+ var rawValue = getValue(values, name);
255
+ if (typeof rawValue !== "number") {
256
+ throw new Error('Expected number for argument "'.concat(name, '", got ').concat(typeof rawValue === "undefined" ? "undefined" : _typeof(rawValue)));
257
+ }
258
+ var value = rawValue;
259
+ var opts = getNumberFormatOptions(style, formatOptions);
260
+ return formatOptions.formatters.getNumberFormat(locale, opts).format(value);
261
+ }
262
+ function formatDateTimeValue(name, style, locale, values, formatOptions, type) {
263
+ var rawValue = getValue(values, name);
264
+ if (!_instanceof(rawValue, Date)) {
265
+ throw new Error('Expected Date for argument "'.concat(name, '", got ').concat(typeof rawValue === "undefined" ? "undefined" : _typeof(rawValue)));
266
+ }
267
+ var date = rawValue;
268
+ var baseOpts = getDateTimeFormatOptions(style, type, formatOptions);
269
+ var ref;
270
+ // Global time zone is used as default, but format-specific one takes precedence
271
+ var opts = _objectSpreadProps(_objectSpread({}, baseOpts), {
272
+ timeZone: (ref = baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.timeZone) !== null && ref !== void 0 ? ref : formatOptions.timeZone
273
+ });
274
+ return formatOptions.formatters.getDateTimeFormat(locale, opts).format(date);
275
+ }
276
+ function getNumberFormatOptions(style, formatOptions) {
277
+ if (!style) return undefined;
278
+ if (typeof style === "string") {
279
+ var ref, ref1;
280
+ if ((ref = formatOptions.formats) === null || ref === void 0 ? void 0 : (ref1 = ref.number) === null || ref1 === void 0 ? void 0 : ref1[style]) {
281
+ return formatOptions.formats.number[style];
282
+ }
283
+ {
284
+ throw new Error('Missing number format "'.concat(style, '"'));
285
+ }
286
+ }
287
+ return style;
288
+ }
289
+ function getDateTimeFormatOptions(style, type, formatOptions) {
290
+ if (!style) return undefined;
291
+ if (typeof style === "string") {
292
+ var ref, ref1;
293
+ var resolved = (ref = formatOptions.formats) === null || ref === void 0 ? void 0 : (ref1 = ref.dateTime) === null || ref1 === void 0 ? void 0 : ref1[style];
294
+ if (!resolved) {
295
+ throw new Error("Missing ".concat(type, ' format "').concat(style, '"'));
296
+ }
297
+ return resolved;
298
+ }
299
+ return style;
300
+ }
301
+ function formatTag(name, children, locale, values, formatOptions, pluralCtx) {
302
+ var rawHandler = getValue(values, name);
303
+ if (typeof rawHandler !== "function") {
304
+ throw new Error('Expected function for tag handler "'.concat(name, '"'));
305
+ }
306
+ var handler = rawHandler;
307
+ var formattedChildren = formatNodes(children, locale, values, formatOptions, pluralCtx);
308
+ var optimized = optimizeResult(formattedChildren);
309
+ var childArray = Array.isArray(optimized) ? optimized : [
310
+ optimized
311
+ ];
312
+ return handler(childArray);
313
+ }
314
+ function optimizeResult(result) {
315
+ if (result.length === 0) {
316
+ return "";
317
+ }
318
+ var merged = [];
319
+ var currentString = "";
320
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
321
+ try {
322
+ for(var _iterator = result[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
323
+ var item = _step.value;
324
+ if (typeof item === "string") {
325
+ currentString += item;
326
+ } else {
327
+ if (currentString) {
328
+ merged.push(currentString);
329
+ currentString = "";
330
+ }
331
+ merged.push(item);
332
+ }
333
+ }
334
+ } catch (err) {
335
+ _didIteratorError = true;
336
+ _iteratorError = err;
337
+ } finally{
338
+ try {
339
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
340
+ _iterator.return();
341
+ }
342
+ } finally{
343
+ if (_didIteratorError) {
344
+ throw _iteratorError;
345
+ }
346
+ }
347
+ }
348
+ if (currentString) {
349
+ merged.push(currentString);
350
+ }
351
+ if (merged.length === 1) {
352
+ return merged[0];
353
+ }
354
+ return merged;
355
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ T: function() {
13
+ return TYPE_POUND;
14
+ },
15
+ a: function() {
16
+ return TYPE_NUMBER;
17
+ },
18
+ b: function() {
19
+ return TYPE_DATE;
20
+ },
21
+ c: function() {
22
+ return TYPE_TIME;
23
+ },
24
+ d: function() {
25
+ return TYPE_SELECT;
26
+ },
27
+ e: function() {
28
+ return TYPE_SELECTORDINAL;
29
+ },
30
+ f: function() {
31
+ return TYPE_PLURAL;
32
+ }
33
+ });
34
+ var TYPE_POUND = 0;
35
+ var TYPE_SELECT = 1;
36
+ var TYPE_PLURAL = 2;
37
+ var TYPE_SELECTORDINAL = 3;
38
+ var TYPE_NUMBER = 4;
39
+ var TYPE_DATE = 5;
40
+ var TYPE_TIME = 6;
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return a;
9
+ }
10
+ });
11
+ var _icuMessageformatParser = require("@formatjs/icu-messageformat-parser");
12
+ var _typesDqTLNw7XJs = require("./types-DqTLNw7x.js");
13
+ function _arrayLikeToArray(arr, len) {
14
+ if (len == null || len > arr.length) len = arr.length;
15
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
16
+ return arr2;
17
+ }
18
+ function _arrayWithHoles(arr) {
19
+ if (Array.isArray(arr)) return arr;
20
+ }
21
+ function _arrayWithoutHoles(arr) {
22
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
23
+ }
24
+ function _iterableToArray(iter) {
25
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
26
+ }
27
+ function _iterableToArrayLimit(arr, i) {
28
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
29
+ if (_i == null) return;
30
+ var _arr = [];
31
+ var _n = true;
32
+ var _d = false;
33
+ var _s, _e;
34
+ try {
35
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
36
+ _arr.push(_s.value);
37
+ if (i && _arr.length === i) break;
38
+ }
39
+ } catch (err) {
40
+ _d = true;
41
+ _e = err;
42
+ } finally{
43
+ try {
44
+ if (!_n && _i["return"] != null) _i["return"]();
45
+ } finally{
46
+ if (_d) throw _e;
47
+ }
48
+ }
49
+ return _arr;
50
+ }
51
+ function _nonIterableRest() {
52
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
53
+ }
54
+ function _nonIterableSpread() {
55
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _slicedToArray(arr, i) {
58
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
59
+ }
60
+ function _toConsumableArray(arr) {
61
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
62
+ }
63
+ function _unsupportedIterableToArray(o, minLen) {
64
+ if (!o) return;
65
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
66
+ var n = Object.prototype.toString.call(o).slice(8, -1);
67
+ if (n === "Object" && o.constructor) n = o.constructor.name;
68
+ if (n === "Map" || n === "Set") return Array.from(n);
69
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
70
+ }
71
+ function a(e) {
72
+ var n = f((0, _icuMessageformatParser.parse)(e));
73
+ return 0 === n.length ? "" : 1 === n.length && "string" == typeof n[0] ? n[0] : n;
74
+ }
75
+ function f(t) {
76
+ var e = [];
77
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
78
+ try {
79
+ for(var _iterator = t[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
80
+ var n = _step.value;
81
+ var _$t = p(n);
82
+ "string" == typeof _$t && e.length > 0 && "string" == typeof e[e.length - 1] ? e[e.length - 1] += _$t : e.push(_$t);
83
+ }
84
+ } catch (err) {
85
+ _didIteratorError = true;
86
+ _iteratorError = err;
87
+ } finally{
88
+ try {
89
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
90
+ _iterator.return();
91
+ }
92
+ } finally{
93
+ if (_didIteratorError) {
94
+ throw _iteratorError;
95
+ }
96
+ }
97
+ }
98
+ return e;
99
+ }
100
+ function l(t) {
101
+ var e = f(t);
102
+ if (0 === e.length) return "";
103
+ if (1 === e.length) {
104
+ var _$t = e[0];
105
+ if ("string" == typeof _$t || _$t === _typesDqTLNw7XJs.T) return _$t;
106
+ }
107
+ return e;
108
+ }
109
+ function p(t) {
110
+ switch(t.type){
111
+ case _icuMessageformatParser.TYPE.literal:
112
+ return t.value;
113
+ case _icuMessageformatParser.TYPE.argument:
114
+ return [
115
+ t.value
116
+ ];
117
+ case _icuMessageformatParser.TYPE.number:
118
+ return function(t) {
119
+ var _$e = [
120
+ t.value,
121
+ _typesDqTLNw7XJs.a
122
+ ], _$n = function(t) {
123
+ if (!t) return;
124
+ if ("string" == typeof t) return t;
125
+ if ("parsedOptions" in t) {
126
+ var _$e = t.parsedOptions;
127
+ return Object.keys(_$e).length > 0 ? _$e : void 0;
128
+ }
129
+ return;
130
+ }(t.style);
131
+ void 0 !== _$n && _$e.push(_$n);
132
+ return _$e;
133
+ }(t);
134
+ case _icuMessageformatParser.TYPE.date:
135
+ return function(t) {
136
+ var _$e = [
137
+ t.value,
138
+ _typesDqTLNw7XJs.b
139
+ ], _$n = g(t.style);
140
+ void 0 !== _$n && _$e.push(_$n);
141
+ return _$e;
142
+ }(t);
143
+ case _icuMessageformatParser.TYPE.time:
144
+ return function(t) {
145
+ var _$e = [
146
+ t.value,
147
+ _typesDqTLNw7XJs.c
148
+ ], _$n = g(t.style);
149
+ void 0 !== _$n && _$e.push(_$n);
150
+ return _$e;
151
+ }(t);
152
+ case _icuMessageformatParser.TYPE.select:
153
+ return function(t) {
154
+ var _$e = Object.create(null);
155
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
156
+ try {
157
+ for(var _iterator = Object.entries(t.options)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
158
+ var _value = _slicedToArray(_step.value, 2), _$n = _value[0], r = _value[1];
159
+ _$e[_$n] = l(r.value);
160
+ }
161
+ } catch (err) {
162
+ _didIteratorError = true;
163
+ _iteratorError = err;
164
+ } finally{
165
+ try {
166
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
167
+ _iterator.return();
168
+ }
169
+ } finally{
170
+ if (_didIteratorError) {
171
+ throw _iteratorError;
172
+ }
173
+ }
174
+ }
175
+ return [
176
+ t.value,
177
+ _typesDqTLNw7XJs.d,
178
+ _$e
179
+ ];
180
+ }(t);
181
+ case _icuMessageformatParser.TYPE.plural:
182
+ return function(t) {
183
+ var _$e = Object.create(null);
184
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
185
+ try {
186
+ for(var _iterator = Object.entries(t.options)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
187
+ var _value = _slicedToArray(_step.value, 2), _$n = _value[0], r = _value[1];
188
+ _$e[_$n] = l(r.value);
189
+ }
190
+ } catch (err) {
191
+ _didIteratorError = true;
192
+ _iteratorError = err;
193
+ } finally{
194
+ try {
195
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
196
+ _iterator.return();
197
+ }
198
+ } finally{
199
+ if (_didIteratorError) {
200
+ throw _iteratorError;
201
+ }
202
+ }
203
+ }
204
+ return [
205
+ t.value,
206
+ "ordinal" === t.pluralType ? _typesDqTLNw7XJs.e : _typesDqTLNw7XJs.f,
207
+ _$e
208
+ ];
209
+ }(t);
210
+ case _icuMessageformatParser.TYPE.pound:
211
+ return _typesDqTLNw7XJs.T;
212
+ case _icuMessageformatParser.TYPE.tag:
213
+ return function(t) {
214
+ var _n;
215
+ var _$e = f(t.children), _$n = [
216
+ t.value
217
+ ];
218
+ 0 === _$e.length ? _$n.push("") : (_n = _$n).push.apply(_n, _toConsumableArray(_$e));
219
+ return _$n;
220
+ }(t);
221
+ default:
222
+ throw new Error("Unknown AST node type: ".concat(t.type));
223
+ }
224
+ }
225
+ function g(t) {
226
+ if (t) {
227
+ if ("string" == typeof t) return t;
228
+ if ("parsedOptions" in t) {
229
+ var e = t.parsedOptions;
230
+ return Object.keys(e).length > 0 ? e : void 0;
231
+ }
232
+ }
233
+ }
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return f;
9
+ }
10
+ });
11
+ var _typesDqTLNw7XJs = require("./types-DqTLNw7x.js");
12
+ function _arrayLikeToArray(arr, len) {
13
+ if (len == null || len > arr.length) len = arr.length;
14
+ for(var i1 = 0, arr2 = new Array(len); i1 < len; i1++)arr2[i1] = arr[i1];
15
+ return arr2;
16
+ }
17
+ function _arrayWithHoles(arr) {
18
+ if (Array.isArray(arr)) return arr;
19
+ }
20
+ function _arrayWithoutHoles(arr) {
21
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
22
+ }
23
+ function _defineProperty(obj, key, value) {
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value: value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else {
32
+ obj[key] = value;
33
+ }
34
+ return obj;
35
+ }
36
+ function _iterableToArray(iter) {
37
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
38
+ }
39
+ function _nonIterableRest() {
40
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
41
+ }
42
+ function _nonIterableSpread() {
43
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
44
+ }
45
+ function _objectSpread(target) {
46
+ for(var i1 = 1; i1 < arguments.length; i1++){
47
+ var source = arguments[i1] != null ? arguments[i1] : {};
48
+ var ownKeys = Object.keys(source);
49
+ if (typeof Object.getOwnPropertySymbols === "function") {
50
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
51
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
52
+ }));
53
+ }
54
+ ownKeys.forEach(function(key) {
55
+ _defineProperty(target, key, source[key]);
56
+ });
57
+ }
58
+ return target;
59
+ }
60
+ function ownKeys(object, enumerableOnly) {
61
+ var keys = Object.keys(object);
62
+ if (Object.getOwnPropertySymbols) {
63
+ var symbols = Object.getOwnPropertySymbols(object);
64
+ if (enumerableOnly) {
65
+ symbols = symbols.filter(function(sym) {
66
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
67
+ });
68
+ }
69
+ keys.push.apply(keys, symbols);
70
+ }
71
+ return keys;
72
+ }
73
+ function _objectSpreadProps(target, source) {
74
+ source = source != null ? source : {};
75
+ if (Object.getOwnPropertyDescriptors) {
76
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
77
+ } else {
78
+ ownKeys(Object(source)).forEach(function(key) {
79
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
80
+ });
81
+ }
82
+ return target;
83
+ }
84
+ function _toArray(arr) {
85
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
86
+ }
87
+ function _toConsumableArray(arr) {
88
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
89
+ }
90
+ function _unsupportedIterableToArray(o, minLen) {
91
+ if (!o) return;
92
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
93
+ var n = Object.prototype.toString.call(o).slice(8, -1);
94
+ if (n === "Object" && o.constructor) n = o.constructor.name;
95
+ if (n === "Map" || n === "Set") return Array.from(n);
96
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
97
+ }
98
+ function f(t, r) {
99
+ var n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, e = arguments.length > 3 ? arguments[3] : void 0;
100
+ if ("string" == typeof t) return t;
101
+ return g(i1(t, r, n, e, void 0));
102
+ }
103
+ function i1(t, r, n, e, o) {
104
+ var u = [];
105
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
106
+ try {
107
+ for(var _iterator = t[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
108
+ var s = _step.value;
109
+ var _u;
110
+ var _$t = a(s, r, n, e, o);
111
+ Array.isArray(_$t) ? (_u = u).push.apply(_u, _toConsumableArray(_$t)) : u.push(_$t);
112
+ }
113
+ } catch (err) {
114
+ _didIteratorError = true;
115
+ _iteratorError = err;
116
+ } finally{
117
+ try {
118
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
119
+ _iterator.return();
120
+ }
121
+ } finally{
122
+ if (_didIteratorError) {
123
+ throw _iteratorError;
124
+ }
125
+ }
126
+ }
127
+ return u;
128
+ }
129
+ function a(f, a, y, d, h) {
130
+ if ("string" == typeof f) return f;
131
+ if (f === _typesDqTLNw7XJs.T) {
132
+ var _$t = h;
133
+ return d.formatters.getNumberFormat(_$t.locale).format(_$t.value);
134
+ }
135
+ var _f = _toArray(f), b = _f[0], v = _f[1], A = _f.slice(2);
136
+ if (void 0 === v) {
137
+ var _$t1 = c(y, b);
138
+ return String(_$t1);
139
+ }
140
+ if ("number" != typeof v || v === _typesDqTLNw7XJs.T) return function(t, r, n, e, o, u) {
141
+ var _$s = c(e, t), _$f = _$s, _$a = i1(r, n, e, o, u), _$m = g(_$a), l = Array.isArray(_$m) ? _$m : [
142
+ _$m
143
+ ];
144
+ return _$f(l);
145
+ }(b, [
146
+ v
147
+ ].concat(_toConsumableArray(A)), a, y, d, h);
148
+ switch(v){
149
+ case _typesDqTLNw7XJs.d:
150
+ return function(t, r, n, e, o, u) {
151
+ var _s;
152
+ var _$s = String(c(e, t)), _$f = (_s = r[_$s]) !== null && _s !== void 0 ? _s : r.other;
153
+ return l(_$f, n, e, o, u);
154
+ }(b, A[0], a, y, d, h);
155
+ case _typesDqTLNw7XJs.f:
156
+ return m(b, A[0], a, y, d, "cardinal");
157
+ case _typesDqTLNw7XJs.e:
158
+ return m(b, A[0], a, y, d, "ordinal");
159
+ case _typesDqTLNw7XJs.a:
160
+ return function(t, r, n, e, o) {
161
+ var _$u = c(e, t), _$s = _$u, _$f = function(t, r) {
162
+ var ref, ref1;
163
+ if (!t) return;
164
+ if ("string" == typeof t) return ((ref = r.formats) === null || ref === void 0 ? void 0 : (ref1 = ref.number) === null || ref1 === void 0 ? void 0 : ref1[t]) ? r.formats.number[t] : void 0;
165
+ return t;
166
+ }(r, o);
167
+ return o.formatters.getNumberFormat(n, _$f).format(_$s);
168
+ }(b, A[0], a, y, d);
169
+ case _typesDqTLNw7XJs.b:
170
+ return p(b, A[0], a, y, d, "date");
171
+ case _typesDqTLNw7XJs.c:
172
+ return p(b, A[0], a, y, d, "time");
173
+ default:
174
+ return "";
175
+ }
176
+ }
177
+ function c(t, r) {
178
+ return t[r];
179
+ }
180
+ function m(t, r, n, e, o, u) {
181
+ var s = c(e, t), f = "=".concat(s);
182
+ if (f in r) return l(r[f], n, e, o, {
183
+ value: s,
184
+ locale: n
185
+ });
186
+ var ref;
187
+ return l((ref = r[o.formatters.getPluralRules(n, {
188
+ type: u
189
+ }).select(s)]) !== null && ref !== void 0 ? ref : r.other, n, e, o, {
190
+ value: s,
191
+ locale: n
192
+ });
193
+ }
194
+ function l(r, n, e, o, u) {
195
+ return "string" == typeof r ? r : r === _typesDqTLNw7XJs.T ? a(r, n, e, o, u) : i1(r, n, e, o, u);
196
+ }
197
+ function p(t, r, n, e, o, u) {
198
+ var ref;
199
+ var s = c(e, t), f = function(t, r, n) {
200
+ if (!t) return;
201
+ if ("string" == typeof t) {
202
+ var ref, ref1;
203
+ var _$r = (ref = n.formats) === null || ref === void 0 ? void 0 : (ref1 = ref.dateTime) === null || ref1 === void 0 ? void 0 : ref1[t];
204
+ return _$r;
205
+ }
206
+ return t;
207
+ }(r, 0, o), i1 = _objectSpreadProps(_objectSpread({}, f), {
208
+ timeZone: (ref = f === null || f === void 0 ? void 0 : f.timeZone) !== null && ref !== void 0 ? ref : o.timeZone
209
+ });
210
+ return o.formatters.getDateTimeFormat(n, i1).format(s);
211
+ }
212
+ function g(t) {
213
+ if (0 === t.length) return "";
214
+ var r = [];
215
+ var n = "";
216
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
217
+ try {
218
+ for(var _iterator = t[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
219
+ var e = _step.value;
220
+ "string" == typeof e ? n += e : (n && (r.push(n), n = ""), r.push(e));
221
+ }
222
+ } catch (err) {
223
+ _didIteratorError = true;
224
+ _iteratorError = err;
225
+ } finally{
226
+ try {
227
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
228
+ _iterator.return();
229
+ }
230
+ } finally{
231
+ if (_didIteratorError) {
232
+ throw _iteratorError;
233
+ }
234
+ }
235
+ }
236
+ return n && r.push(n), 1 === r.length ? r[0] : r;
237
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ T: function() {
13
+ return a;
14
+ },
15
+ a: function() {
16
+ return o;
17
+ },
18
+ b: function() {
19
+ return t;
20
+ },
21
+ c: function() {
22
+ return b;
23
+ },
24
+ d: function() {
25
+ return s;
26
+ },
27
+ e: function() {
28
+ return e;
29
+ },
30
+ f: function() {
31
+ return c;
32
+ }
33
+ });
34
+ var a = 0, s = 1, c = 2, e = 3, o = 4, t = 5, b = 6;
@@ -0,0 +1,2 @@
1
+ import { type CompiledMessage } from './types.js';
2
+ export default function compile(message: string): CompiledMessage;
@@ -0,0 +1,17 @@
1
+ import { type CompiledMessage } from './types.js';
2
+ export type { CompiledMessage } from './types.js';
3
+ export type FormatValues<RichTextElement = unknown> = Record<string, string | number | boolean | Date | ((chunks: Array<string | RichTextElement>) => RichTextElement)>;
4
+ export type Formats = {
5
+ dateTime?: Record<string, Intl.DateTimeFormatOptions>;
6
+ number?: Record<string, Intl.NumberFormatOptions>;
7
+ };
8
+ export type FormatOptions = {
9
+ formats?: Formats;
10
+ formatters: {
11
+ getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
12
+ getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
13
+ getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
14
+ };
15
+ timeZone?: string;
16
+ };
17
+ export default function format<RichTextElement = string>(message: CompiledMessage, locale: string, values: FormatValues<RichTextElement> | undefined, options: FormatOptions): string | RichTextElement | Array<string | RichTextElement>;
@@ -0,0 +1,29 @@
1
+ export declare const TYPE_POUND = 0;
2
+ export declare const TYPE_SELECT = 1;
3
+ export declare const TYPE_PLURAL = 2;
4
+ export declare const TYPE_SELECTORDINAL = 3;
5
+ export declare const TYPE_NUMBER = 4;
6
+ export declare const TYPE_DATE = 5;
7
+ export declare const TYPE_TIME = 6;
8
+ export type NumberStyleOptions = Intl.NumberFormatOptions;
9
+ export type NumberStyle = string | NumberStyleOptions;
10
+ export type DateTimeStyleOptions = Intl.DateTimeFormatOptions;
11
+ export type DateTimeStyle = string | DateTimeStyleOptions;
12
+ export type PluralOptions = Record<string, CompiledNode>;
13
+ export type SelectOptions = Record<string, CompiledNode>;
14
+ export type CompiledPlainTextNode = string;
15
+ export type CompiledSimpleArgNode = [string];
16
+ export type CompiledPoundNode = typeof TYPE_POUND;
17
+ export type CompiledSelectNode = [string, typeof TYPE_SELECT, SelectOptions];
18
+ export type CompiledPluralNode = [string, typeof TYPE_PLURAL, PluralOptions];
19
+ export type CompiledSelectOrdinalNode = [
20
+ string,
21
+ typeof TYPE_SELECTORDINAL,
22
+ PluralOptions
23
+ ];
24
+ export type CompiledNumberNode = [string, typeof TYPE_NUMBER, NumberStyle?];
25
+ export type CompiledDateNode = [string, typeof TYPE_DATE, DateTimeStyle?];
26
+ export type CompiledTimeNode = [string, typeof TYPE_TIME, DateTimeStyle?];
27
+ export type CompiledTagNode = [string, unknown, ...Array<unknown>];
28
+ export type CompiledNode = CompiledPlainTextNode | CompiledSimpleArgNode | CompiledPoundNode | CompiledSelectNode | CompiledPluralNode | CompiledSelectOrdinalNode | CompiledNumberNode | CompiledDateNode | CompiledTimeNode | CompiledTagNode;
29
+ export type CompiledMessage = string | Array<CompiledNode>;
package/format.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Needed for projects with `moduleResolution: 'node'`
2
+ export {default} from './dist/types/format.d.ts';
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@common.js/icu-minify",
3
+ "version": "4.13.1",
4
+ "sideEffects": false,
5
+ "funding": [
6
+ {
7
+ "type": "individual",
8
+ "url": "https://github.com/sponsors/amannn"
9
+ }
10
+ ],
11
+ "description": "icu-minify package exported as CommonJS modules",
12
+ "license": "MIT",
13
+ "homepage": "https://github.com/etienne-martin/common.js#readme",
14
+ "repository": "etienne-martin/common.js",
15
+ "scripts": {
16
+ "build": "rm -rf dist && rollup -c",
17
+ "test": "TZ=Europe/Berlin vitest",
18
+ "lint": "pnpm run lint:source && pnpm run lint:package",
19
+ "lint:source": "eslint src test && tsc --noEmit && pnpm run lint:prettier",
20
+ "lint:package": "publint && attw --pack --ignore-rules=cjs-resolves-to-esm",
21
+ "lint:prettier": "prettier src --check",
22
+ "size": "size-limit"
23
+ },
24
+ "type": "commonjs",
25
+ "files": [
26
+ "dist",
27
+ "compile.d.ts",
28
+ "format.d.ts"
29
+ ],
30
+ "dependencies": {
31
+ "@common.js/formatjs__icu-messageformat-parser": "^3.4.0"
32
+ },
33
+ "gitHead": "976ca1f83a6e06b5646865b87c4fb461cbf84374"
34
+ }