@common.js/intl-messageformat 11.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1,697 @@
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
+ ErrorCode: function() {
13
+ return ErrorCode;
14
+ },
15
+ FormatError: function() {
16
+ return FormatError;
17
+ },
18
+ IntlMessageFormat: function() {
19
+ return IntlMessageFormat;
20
+ },
21
+ InvalidValueError: function() {
22
+ return InvalidValueError;
23
+ },
24
+ InvalidValueTypeError: function() {
25
+ return InvalidValueTypeError;
26
+ },
27
+ MissingValueError: function() {
28
+ return MissingValueError;
29
+ },
30
+ PART_TYPE: function() {
31
+ return PART_TYPE;
32
+ },
33
+ default: function() {
34
+ return intl_messageformat_default;
35
+ },
36
+ formatToParts: function() {
37
+ return formatToParts;
38
+ },
39
+ isFormatXMLElementFn: function() {
40
+ return isFormatXMLElementFn;
41
+ }
42
+ });
43
+ var _fastMemoize = require("@formatjs/fast-memoize");
44
+ var _icuMessageformatParser = require("@formatjs/icu-messageformat-parser");
45
+ function _arrayLikeToArray(arr, len) {
46
+ if (len == null || len > arr.length) len = arr.length;
47
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
48
+ return arr2;
49
+ }
50
+ function _arrayWithoutHoles(arr) {
51
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
52
+ }
53
+ function _assertThisInitialized(self) {
54
+ if (self === void 0) {
55
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
56
+ }
57
+ return self;
58
+ }
59
+ function _classCallCheck(instance, Constructor) {
60
+ if (!(instance instanceof Constructor)) {
61
+ throw new TypeError("Cannot call a class as a function");
62
+ }
63
+ }
64
+ function isNativeReflectConstruct() {
65
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
66
+ if (Reflect.construct.sham) return false;
67
+ if (typeof Proxy === "function") return true;
68
+ try {
69
+ Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
70
+ return true;
71
+ } catch (e) {
72
+ return false;
73
+ }
74
+ }
75
+ function _construct(Parent, args, Class) {
76
+ if (isNativeReflectConstruct()) {
77
+ _construct = Reflect.construct;
78
+ } else {
79
+ _construct = function _construct(Parent, args, Class) {
80
+ var a = [
81
+ null
82
+ ];
83
+ a.push.apply(a, args);
84
+ var Constructor = Function.bind.apply(Parent, a);
85
+ var instance = new Constructor();
86
+ if (Class) _setPrototypeOf(instance, Class.prototype);
87
+ return instance;
88
+ };
89
+ }
90
+ return _construct.apply(null, arguments);
91
+ }
92
+ function _defineProperties(target, props) {
93
+ for(var i = 0; i < props.length; i++){
94
+ var descriptor = props[i];
95
+ descriptor.enumerable = descriptor.enumerable || false;
96
+ descriptor.configurable = true;
97
+ if ("value" in descriptor) descriptor.writable = true;
98
+ Object.defineProperty(target, descriptor.key, descriptor);
99
+ }
100
+ }
101
+ function _createClass(Constructor, protoProps, staticProps) {
102
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
103
+ if (staticProps) _defineProperties(Constructor, staticProps);
104
+ return Constructor;
105
+ }
106
+ function _defineProperty(obj, key, value) {
107
+ if (key in obj) {
108
+ Object.defineProperty(obj, key, {
109
+ value: value,
110
+ enumerable: true,
111
+ configurable: true,
112
+ writable: true
113
+ });
114
+ } else {
115
+ obj[key] = value;
116
+ }
117
+ return obj;
118
+ }
119
+ function _extends() {
120
+ _extends = Object.assign || function(target) {
121
+ for(var i = 1; i < arguments.length; i++){
122
+ var source = arguments[i];
123
+ for(var key in source){
124
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
125
+ target[key] = source[key];
126
+ }
127
+ }
128
+ }
129
+ return target;
130
+ };
131
+ return _extends.apply(this, arguments);
132
+ }
133
+ function _getPrototypeOf(o) {
134
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
135
+ return o.__proto__ || Object.getPrototypeOf(o);
136
+ };
137
+ return _getPrototypeOf(o);
138
+ }
139
+ function _inherits(subClass, superClass) {
140
+ if (typeof superClass !== "function" && superClass !== null) {
141
+ throw new TypeError("Super expression must either be null or a function");
142
+ }
143
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
144
+ constructor: {
145
+ value: subClass,
146
+ writable: true,
147
+ configurable: true
148
+ }
149
+ });
150
+ if (superClass) _setPrototypeOf(subClass, superClass);
151
+ }
152
+ function _isNativeFunction(fn) {
153
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
154
+ }
155
+ function _iterableToArray(iter) {
156
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
157
+ }
158
+ function _nonIterableSpread() {
159
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
160
+ }
161
+ function _objectSpread(target) {
162
+ for(var i = 1; i < arguments.length; i++){
163
+ var source = arguments[i] != null ? arguments[i] : {};
164
+ var ownKeys = Object.keys(source);
165
+ if (typeof Object.getOwnPropertySymbols === "function") {
166
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
167
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
168
+ }));
169
+ }
170
+ ownKeys.forEach(function(key) {
171
+ _defineProperty(target, key, source[key]);
172
+ });
173
+ }
174
+ return target;
175
+ }
176
+ function ownKeys(object, enumerableOnly) {
177
+ var keys = Object.keys(object);
178
+ if (Object.getOwnPropertySymbols) {
179
+ var symbols = Object.getOwnPropertySymbols(object);
180
+ if (enumerableOnly) {
181
+ symbols = symbols.filter(function(sym) {
182
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
183
+ });
184
+ }
185
+ keys.push.apply(keys, symbols);
186
+ }
187
+ return keys;
188
+ }
189
+ function _objectSpreadProps(target, source) {
190
+ source = source != null ? source : {};
191
+ if (Object.getOwnPropertyDescriptors) {
192
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
193
+ } else {
194
+ ownKeys(Object(source)).forEach(function(key) {
195
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
196
+ });
197
+ }
198
+ return target;
199
+ }
200
+ function _possibleConstructorReturn(self, call) {
201
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
202
+ return call;
203
+ }
204
+ return _assertThisInitialized(self);
205
+ }
206
+ function _setPrototypeOf(o, p) {
207
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
208
+ o.__proto__ = p;
209
+ return o;
210
+ };
211
+ return _setPrototypeOf(o, p);
212
+ }
213
+ function _toConsumableArray(arr) {
214
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
215
+ }
216
+ var _typeof = function(obj) {
217
+ "@swc/helpers - typeof";
218
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
219
+ };
220
+ function _unsupportedIterableToArray(o, minLen) {
221
+ if (!o) return;
222
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
223
+ var n = Object.prototype.toString.call(o).slice(8, -1);
224
+ if (n === "Object" && o.constructor) n = o.constructor.name;
225
+ if (n === "Map" || n === "Set") return Array.from(n);
226
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
227
+ }
228
+ function _wrapNativeSuper(Class) {
229
+ var _cache = typeof Map === "function" ? new Map() : undefined;
230
+ _wrapNativeSuper = function _wrapNativeSuper(Class) {
231
+ if (Class === null || !_isNativeFunction(Class)) return Class;
232
+ if (typeof Class !== "function") {
233
+ throw new TypeError("Super expression must either be null or a function");
234
+ }
235
+ if (typeof _cache !== "undefined") {
236
+ if (_cache.has(Class)) return _cache.get(Class);
237
+ _cache.set(Class, Wrapper);
238
+ }
239
+ function Wrapper() {
240
+ return _construct(Class, arguments, _getPrototypeOf(this).constructor);
241
+ }
242
+ Wrapper.prototype = Object.create(Class.prototype, {
243
+ constructor: {
244
+ value: Wrapper,
245
+ enumerable: false,
246
+ writable: true,
247
+ configurable: true
248
+ }
249
+ });
250
+ return _setPrototypeOf(Wrapper, Class);
251
+ };
252
+ return _wrapNativeSuper(Class);
253
+ }
254
+ function _isNativeReflectConstruct() {
255
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
256
+ if (Reflect.construct.sham) return false;
257
+ if (typeof Proxy === "function") return true;
258
+ try {
259
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
260
+ return true;
261
+ } catch (e) {
262
+ return false;
263
+ }
264
+ }
265
+ function _createSuper(Derived) {
266
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
267
+ return function _createSuperInternal() {
268
+ var Super = _getPrototypeOf(Derived), result;
269
+ if (hasNativeReflectConstruct) {
270
+ var NewTarget = _getPrototypeOf(this).constructor;
271
+ result = Reflect.construct(Super, arguments, NewTarget);
272
+ } else {
273
+ result = Super.apply(this, arguments);
274
+ }
275
+ return _possibleConstructorReturn(this, result);
276
+ };
277
+ }
278
+ var _IntlMessageFormat, __, __1, __2, __3;
279
+ //#region packages/intl-messageformat/error.ts
280
+ var ErrorCode = /* @__PURE__ */ function(ErrorCode) {
281
+ ErrorCode["MISSING_VALUE"] = "MISSING_VALUE";
282
+ ErrorCode["INVALID_VALUE"] = "INVALID_VALUE";
283
+ ErrorCode["MISSING_INTL_API"] = "MISSING_INTL_API";
284
+ return ErrorCode;
285
+ }({});
286
+ var FormatError = /*#__PURE__*/ function(Error1) {
287
+ "use strict";
288
+ _inherits(FormatError, Error1);
289
+ var _super = _createSuper(FormatError);
290
+ function FormatError(msg, code, originalMessage) {
291
+ _classCallCheck(this, FormatError);
292
+ var _this;
293
+ _this = _super.call(this, msg);
294
+ _this.code = code;
295
+ _this.originalMessage = originalMessage;
296
+ return _this;
297
+ }
298
+ _createClass(FormatError, [
299
+ {
300
+ key: "toString",
301
+ value: function toString() {
302
+ return "[formatjs Error: ".concat(this.code, "] ").concat(this.message);
303
+ }
304
+ }
305
+ ]);
306
+ return FormatError;
307
+ }(_wrapNativeSuper(Error));
308
+ var InvalidValueError = /*#__PURE__*/ function(FormatError) {
309
+ "use strict";
310
+ _inherits(InvalidValueError, FormatError);
311
+ var _super = _createSuper(InvalidValueError);
312
+ function InvalidValueError(variableId, value, options, originalMessage) {
313
+ _classCallCheck(this, InvalidValueError);
314
+ return _super.call(this, 'Invalid values for "'.concat(variableId, '": "').concat(value, '". Options are "').concat(Object.keys(options).join('", "'), '"'), "INVALID_VALUE", originalMessage);
315
+ }
316
+ return InvalidValueError;
317
+ }(FormatError);
318
+ var InvalidValueTypeError = /*#__PURE__*/ function(FormatError) {
319
+ "use strict";
320
+ _inherits(InvalidValueTypeError, FormatError);
321
+ var _super = _createSuper(InvalidValueTypeError);
322
+ function InvalidValueTypeError(value, type, originalMessage) {
323
+ _classCallCheck(this, InvalidValueTypeError);
324
+ return _super.call(this, 'Value for "'.concat(value, '" must be of type ').concat(type), "INVALID_VALUE", originalMessage);
325
+ }
326
+ return InvalidValueTypeError;
327
+ }(FormatError);
328
+ var MissingValueError = /*#__PURE__*/ function(FormatError) {
329
+ "use strict";
330
+ _inherits(MissingValueError, FormatError);
331
+ var _super = _createSuper(MissingValueError);
332
+ function MissingValueError(variableId, originalMessage) {
333
+ _classCallCheck(this, MissingValueError);
334
+ return _super.call(this, 'The intl string context variable "'.concat(variableId, '" was not provided to the string "').concat(originalMessage, '"'), "MISSING_VALUE", originalMessage);
335
+ }
336
+ return MissingValueError;
337
+ }(FormatError);
338
+ //#endregion
339
+ //#region packages/intl-messageformat/formatters.ts
340
+ var PART_TYPE = /* @__PURE__ */ function(PART_TYPE) {
341
+ PART_TYPE[PART_TYPE["literal"] = 0] = "literal";
342
+ PART_TYPE[PART_TYPE["object"] = 1] = "object";
343
+ return PART_TYPE;
344
+ }({});
345
+ function mergeLiteral(parts) {
346
+ if (parts.length < 2) return parts;
347
+ return parts.reduce(function(all, part) {
348
+ var lastPart = all[all.length - 1];
349
+ if (!lastPart || lastPart.type !== 0 || part.type !== 0) all.push(part);
350
+ else lastPart.value += part.value;
351
+ return all;
352
+ }, []);
353
+ }
354
+ function isFormatXMLElementFn(el) {
355
+ return typeof el === "function";
356
+ }
357
+ function formatToParts(els, locales, formatters, formats, values, currentPluralValue, originalMessage) {
358
+ if (els.length === 1 && (0, _icuMessageformatParser.isLiteralElement)(els[0])) return [
359
+ {
360
+ type: 0,
361
+ value: els[0].value
362
+ }
363
+ ];
364
+ var result = [];
365
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
366
+ try {
367
+ for(var _iterator = els[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
368
+ var el = _step.value;
369
+ if ((0, _icuMessageformatParser.isLiteralElement)(el)) {
370
+ result.push({
371
+ type: 0,
372
+ value: el.value
373
+ });
374
+ continue;
375
+ }
376
+ if ((0, _icuMessageformatParser.isPoundElement)(el)) {
377
+ if (typeof currentPluralValue === "number") result.push({
378
+ type: 0,
379
+ value: formatters.getNumberFormat(locales).format(currentPluralValue)
380
+ });
381
+ continue;
382
+ }
383
+ var varName = el.value;
384
+ if (!(values && varName in values)) throw new MissingValueError(varName, originalMessage);
385
+ var value = values[varName];
386
+ if ((0, _icuMessageformatParser.isArgumentElement)(el)) {
387
+ if (!value || typeof value === "string" || typeof value === "number" || (typeof value === "undefined" ? "undefined" : _typeof(value)) === "bigint") value = typeof value === "string" || typeof value === "number" || (typeof value === "undefined" ? "undefined" : _typeof(value)) === "bigint" ? String(value) : "";
388
+ result.push({
389
+ type: typeof value === "string" ? 0 : 1,
390
+ value: value
391
+ });
392
+ continue;
393
+ }
394
+ if ((0, _icuMessageformatParser.isDateElement)(el)) {
395
+ var style = typeof el.style === "string" ? formats.date[el.style] : (0, _icuMessageformatParser.isDateTimeSkeleton)(el.style) ? el.style.parsedOptions : void 0;
396
+ result.push({
397
+ type: 0,
398
+ value: formatters.getDateTimeFormat(locales, style).format(value)
399
+ });
400
+ continue;
401
+ }
402
+ if ((0, _icuMessageformatParser.isTimeElement)(el)) {
403
+ var style1 = typeof el.style === "string" ? formats.time[el.style] : (0, _icuMessageformatParser.isDateTimeSkeleton)(el.style) ? el.style.parsedOptions : formats.time.medium;
404
+ result.push({
405
+ type: 0,
406
+ value: formatters.getDateTimeFormat(locales, style1).format(value)
407
+ });
408
+ continue;
409
+ }
410
+ if ((0, _icuMessageformatParser.isNumberElement)(el)) {
411
+ var style2 = typeof el.style === "string" ? formats.number[el.style] : (0, _icuMessageformatParser.isNumberSkeleton)(el.style) ? el.style.parsedOptions : void 0;
412
+ if (style2 && style2.scale) {
413
+ var scale = style2.scale || 1;
414
+ if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === "bigint") {
415
+ if (!Number.isInteger(scale)) throw new TypeError("Cannot apply fractional scale ".concat(scale, " to bigint value. Scale must be an integer when formatting bigint."));
416
+ value = value * BigInt(scale);
417
+ } else value = value * scale;
418
+ }
419
+ result.push({
420
+ type: 0,
421
+ value: formatters.getNumberFormat(locales, style2).format(value)
422
+ });
423
+ continue;
424
+ }
425
+ if ((0, _icuMessageformatParser.isTagElement)(el)) {
426
+ var _result;
427
+ var children = el.children, value1 = el.value;
428
+ var formatFn = values[value1];
429
+ if (!isFormatXMLElementFn(formatFn)) throw new InvalidValueTypeError(value1, "function", originalMessage);
430
+ var chunks = formatFn(formatToParts(children, locales, formatters, formats, values, currentPluralValue).map(function(p) {
431
+ return p.value;
432
+ }));
433
+ if (!Array.isArray(chunks)) chunks = [
434
+ chunks
435
+ ];
436
+ (_result = result).push.apply(_result, _toConsumableArray(chunks.map(function(c) {
437
+ return {
438
+ type: typeof c === "string" ? 0 : 1,
439
+ value: c
440
+ };
441
+ })));
442
+ }
443
+ if ((0, _icuMessageformatParser.isSelectElement)(el)) {
444
+ var _result1;
445
+ var key = value;
446
+ var opt = (Object.prototype.hasOwnProperty.call(el.options, key) ? el.options[key] : void 0) || el.options.other;
447
+ if (!opt) throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
448
+ (_result1 = result).push.apply(_result1, _toConsumableArray(formatToParts(opt.value, locales, formatters, formats, values)));
449
+ continue;
450
+ }
451
+ if ((0, _icuMessageformatParser.isPluralElement)(el)) {
452
+ var _result2;
453
+ var exactKey = "=".concat(value);
454
+ var opt1 = Object.prototype.hasOwnProperty.call(el.options, exactKey) ? el.options[exactKey] : void 0;
455
+ if (!opt1) {
456
+ if (!Intl.PluralRules) throw new FormatError('Intl.PluralRules is not available in this environment.\nTry polyfilling it using "@formatjs/intl-pluralrules"\n', "MISSING_INTL_API", originalMessage);
457
+ var numericValue = (typeof value === "undefined" ? "undefined" : _typeof(value)) === "bigint" ? Number(value) : value;
458
+ var rule = formatters.getPluralRules(locales, {
459
+ type: el.pluralType
460
+ }).select(numericValue - (el.offset || 0));
461
+ opt1 = (Object.prototype.hasOwnProperty.call(el.options, rule) ? el.options[rule] : void 0) || el.options.other;
462
+ }
463
+ if (!opt1) throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
464
+ var numericValue1 = (typeof value === "undefined" ? "undefined" : _typeof(value)) === "bigint" ? Number(value) : value;
465
+ (_result2 = result).push.apply(_result2, _toConsumableArray(formatToParts(opt1.value, locales, formatters, formats, values, numericValue1 - (el.offset || 0))));
466
+ continue;
467
+ }
468
+ }
469
+ } catch (err) {
470
+ _didIteratorError = true;
471
+ _iteratorError = err;
472
+ } finally{
473
+ try {
474
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
475
+ _iterator.return();
476
+ }
477
+ } finally{
478
+ if (_didIteratorError) {
479
+ throw _iteratorError;
480
+ }
481
+ }
482
+ }
483
+ return mergeLiteral(result);
484
+ }
485
+ //#endregion
486
+ //#region packages/intl-messageformat/core.ts
487
+ function mergeConfig(c1, c2) {
488
+ if (!c2) return c1;
489
+ return _objectSpread({}, c1, c2, Object.keys(c1).reduce(function(all, k) {
490
+ all[k] = _objectSpread({}, c1[k], c2[k]);
491
+ return all;
492
+ }, {}));
493
+ }
494
+ function mergeConfigs(defaultConfig, configs) {
495
+ if (!configs) return defaultConfig;
496
+ return Object.keys(defaultConfig).reduce(function(all, k) {
497
+ all[k] = mergeConfig(defaultConfig[k], configs[k]);
498
+ return all;
499
+ }, _objectSpread({}, defaultConfig));
500
+ }
501
+ function createFastMemoizeCache(store) {
502
+ return {
503
+ create: function create() {
504
+ return {
505
+ get: function get(key) {
506
+ return store[key];
507
+ },
508
+ set: function set(key, value) {
509
+ store[key] = value;
510
+ }
511
+ };
512
+ }
513
+ };
514
+ }
515
+ function createDefaultFormatters() {
516
+ var cache = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
517
+ number: {},
518
+ dateTime: {},
519
+ pluralRules: {}
520
+ };
521
+ return {
522
+ getNumberFormat: (0, _fastMemoize.memoize)(function() {
523
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
524
+ args[_key] = arguments[_key];
525
+ }
526
+ return _construct(Intl.NumberFormat, _toConsumableArray(args));
527
+ }, {
528
+ cache: createFastMemoizeCache(cache.number),
529
+ strategy: _fastMemoize.strategies.variadic
530
+ }),
531
+ getDateTimeFormat: (0, _fastMemoize.memoize)(function() {
532
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
533
+ args[_key] = arguments[_key];
534
+ }
535
+ return _construct(Intl.DateTimeFormat, _toConsumableArray(args));
536
+ }, {
537
+ cache: createFastMemoizeCache(cache.dateTime),
538
+ strategy: _fastMemoize.strategies.variadic
539
+ }),
540
+ getPluralRules: (0, _fastMemoize.memoize)(function() {
541
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
542
+ args[_key] = arguments[_key];
543
+ }
544
+ return _construct(Intl.PluralRules, _toConsumableArray(args));
545
+ }, {
546
+ cache: createFastMemoizeCache(cache.pluralRules),
547
+ strategy: _fastMemoize.strategies.variadic
548
+ })
549
+ };
550
+ }
551
+ var /*#__PURE__*/ _IntlMessageFormat1;
552
+ var IntlMessageFormat = ((_IntlMessageFormat1 = function() {
553
+ "use strict";
554
+ function IntlMessageFormat(message) {
555
+ var locales = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : IntlMessageFormat.defaultLocale, overrideFormats = arguments.length > 2 ? arguments[2] : void 0, opts = arguments.length > 3 ? arguments[3] : void 0;
556
+ var _this = this;
557
+ _classCallCheck(this, IntlMessageFormat);
558
+ this.formatterCache = {
559
+ number: {},
560
+ dateTime: {},
561
+ pluralRules: {}
562
+ };
563
+ this.format = function(values) {
564
+ var parts = _this.formatToParts(values);
565
+ if (parts.length === 1) return parts[0].value;
566
+ var result = parts.reduce(function(all, part) {
567
+ if (!all.length || part.type !== 0 || typeof all[all.length - 1] !== "string") all.push(part.value);
568
+ else all[all.length - 1] += part.value;
569
+ return all;
570
+ }, []);
571
+ if (result.length <= 1) return result[0] || "";
572
+ return result;
573
+ };
574
+ this.formatToParts = function(values) {
575
+ return formatToParts(_this.ast, _this.locales, _this.formatters, _this.formats, values, void 0, _this.message);
576
+ };
577
+ this.resolvedOptions = function() {
578
+ var ref;
579
+ return {
580
+ locale: ((ref = _this.resolvedLocale) === null || ref === void 0 ? void 0 : ref.toString()) || Intl.NumberFormat.supportedLocalesOf(_this.locales)[0]
581
+ };
582
+ };
583
+ this.getAst = function() {
584
+ return _this.ast;
585
+ };
586
+ this.locales = locales;
587
+ this.resolvedLocale = IntlMessageFormat.resolveLocale(locales);
588
+ if (typeof message === "string") {
589
+ this.message = message;
590
+ if (!IntlMessageFormat.__parse) throw new TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");
591
+ var parseOpts = _extends({}, opts || {});
592
+ this.ast = IntlMessageFormat.__parse(message, _objectSpreadProps(_objectSpread({}, parseOpts), {
593
+ locale: this.resolvedLocale
594
+ }));
595
+ } else this.ast = message;
596
+ if (!Array.isArray(this.ast)) throw new TypeError("A message must be provided as a String or AST.");
597
+ this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
598
+ this.formatters = opts && opts.formatters || createDefaultFormatters(this.formatterCache);
599
+ }
600
+ _createClass(IntlMessageFormat, null, [
601
+ {
602
+ key: "defaultLocale",
603
+ get: function get() {
604
+ if (!IntlMessageFormat.memoizedDefaultLocale) IntlMessageFormat.memoizedDefaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
605
+ return IntlMessageFormat.memoizedDefaultLocale;
606
+ }
607
+ }
608
+ ]);
609
+ return IntlMessageFormat;
610
+ }(), _IntlMessageFormat = _IntlMessageFormat1, _IntlMessageFormat1), __ = {
611
+ writable: true,
612
+ value: function() {
613
+ _IntlMessageFormat.memoizedDefaultLocale = null;
614
+ }()
615
+ }, __1 = {
616
+ writable: true,
617
+ value: function() {
618
+ _IntlMessageFormat.resolveLocale = function(locales) {
619
+ if (typeof Intl.Locale === "undefined") return;
620
+ var supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales);
621
+ if (supportedLocales.length > 0) return new Intl.Locale(supportedLocales[0]);
622
+ return new Intl.Locale(typeof locales === "string" ? locales : locales[0]);
623
+ };
624
+ }()
625
+ }, __2 = {
626
+ writable: true,
627
+ value: function() {
628
+ _IntlMessageFormat.__parse = _icuMessageformatParser.parse;
629
+ }()
630
+ }, __3 = {
631
+ writable: true,
632
+ value: function() {
633
+ _IntlMessageFormat.formats = {
634
+ number: {
635
+ integer: {
636
+ maximumFractionDigits: 0
637
+ },
638
+ currency: {
639
+ style: "currency"
640
+ },
641
+ percent: {
642
+ style: "percent"
643
+ }
644
+ },
645
+ date: {
646
+ short: {
647
+ month: "numeric",
648
+ day: "numeric",
649
+ year: "2-digit"
650
+ },
651
+ medium: {
652
+ month: "short",
653
+ day: "numeric",
654
+ year: "numeric"
655
+ },
656
+ long: {
657
+ month: "long",
658
+ day: "numeric",
659
+ year: "numeric"
660
+ },
661
+ full: {
662
+ weekday: "long",
663
+ month: "long",
664
+ day: "numeric",
665
+ year: "numeric"
666
+ }
667
+ },
668
+ time: {
669
+ short: {
670
+ hour: "numeric",
671
+ minute: "numeric"
672
+ },
673
+ medium: {
674
+ hour: "numeric",
675
+ minute: "numeric",
676
+ second: "numeric"
677
+ },
678
+ long: {
679
+ hour: "numeric",
680
+ minute: "numeric",
681
+ second: "numeric",
682
+ timeZoneName: "short"
683
+ },
684
+ full: {
685
+ hour: "numeric",
686
+ minute: "numeric",
687
+ second: "numeric",
688
+ timeZoneName: "short"
689
+ }
690
+ }
691
+ };
692
+ }()
693
+ }, _IntlMessageFormat);
694
+ //#endregion
695
+ //#region packages/intl-messageformat/index.ts
696
+ var intl_messageformat_default = IntlMessageFormat;
697
+ //# sourceMappingURL=index.js.map