@formatjs/intl 2.9.5 → 2.9.7

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/lib/index.js CHANGED
@@ -1,17 +1,40 @@
1
- export * from './src/types';
2
- export function defineMessages(msgs) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIntl = exports.formatNumberToParts = exports.formatNumber = exports.formatRelativeTime = exports.formatPlural = exports.formatList = exports.formatDisplayName = exports.formatTimeToParts = exports.formatTime = exports.formatDateToParts = exports.formatDate = exports.formatMessage = exports.getNamedFormat = exports.createFormatters = exports.DEFAULT_INTL_CONFIG = exports.filterProps = exports.createIntlCache = exports.defineMessage = exports.defineMessages = void 0;
4
+ var tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./src/types"), exports);
6
+ function defineMessages(msgs) {
3
7
  return msgs;
4
8
  }
5
- export function defineMessage(msg) {
9
+ exports.defineMessages = defineMessages;
10
+ function defineMessage(msg) {
6
11
  return msg;
7
12
  }
8
- export { createIntlCache, filterProps, DEFAULT_INTL_CONFIG, createFormatters, getNamedFormat, } from './src/utils';
9
- export * from './src/error';
10
- export { formatMessage } from './src/message';
11
- export { formatDate, formatDateToParts, formatTime, formatTimeToParts, } from './src/dateTime';
12
- export { formatDisplayName } from './src/displayName';
13
- export { formatList } from './src/list';
14
- export { formatPlural } from './src/plural';
15
- export { formatRelativeTime } from './src/relativeTime';
16
- export { formatNumber, formatNumberToParts } from './src/number';
17
- export { createIntl } from './src/create-intl';
13
+ exports.defineMessage = defineMessage;
14
+ var utils_1 = require("./src/utils");
15
+ Object.defineProperty(exports, "createIntlCache", { enumerable: true, get: function () { return utils_1.createIntlCache; } });
16
+ Object.defineProperty(exports, "filterProps", { enumerable: true, get: function () { return utils_1.filterProps; } });
17
+ Object.defineProperty(exports, "DEFAULT_INTL_CONFIG", { enumerable: true, get: function () { return utils_1.DEFAULT_INTL_CONFIG; } });
18
+ Object.defineProperty(exports, "createFormatters", { enumerable: true, get: function () { return utils_1.createFormatters; } });
19
+ Object.defineProperty(exports, "getNamedFormat", { enumerable: true, get: function () { return utils_1.getNamedFormat; } });
20
+ tslib_1.__exportStar(require("./src/error"), exports);
21
+ var message_1 = require("./src/message");
22
+ Object.defineProperty(exports, "formatMessage", { enumerable: true, get: function () { return message_1.formatMessage; } });
23
+ var dateTime_1 = require("./src/dateTime");
24
+ Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return dateTime_1.formatDate; } });
25
+ Object.defineProperty(exports, "formatDateToParts", { enumerable: true, get: function () { return dateTime_1.formatDateToParts; } });
26
+ Object.defineProperty(exports, "formatTime", { enumerable: true, get: function () { return dateTime_1.formatTime; } });
27
+ Object.defineProperty(exports, "formatTimeToParts", { enumerable: true, get: function () { return dateTime_1.formatTimeToParts; } });
28
+ var displayName_1 = require("./src/displayName");
29
+ Object.defineProperty(exports, "formatDisplayName", { enumerable: true, get: function () { return displayName_1.formatDisplayName; } });
30
+ var list_1 = require("./src/list");
31
+ Object.defineProperty(exports, "formatList", { enumerable: true, get: function () { return list_1.formatList; } });
32
+ var plural_1 = require("./src/plural");
33
+ Object.defineProperty(exports, "formatPlural", { enumerable: true, get: function () { return plural_1.formatPlural; } });
34
+ var relativeTime_1 = require("./src/relativeTime");
35
+ Object.defineProperty(exports, "formatRelativeTime", { enumerable: true, get: function () { return relativeTime_1.formatRelativeTime; } });
36
+ var number_1 = require("./src/number");
37
+ Object.defineProperty(exports, "formatNumber", { enumerable: true, get: function () { return number_1.formatNumber; } });
38
+ Object.defineProperty(exports, "formatNumberToParts", { enumerable: true, get: function () { return number_1.formatNumberToParts; } });
39
+ var create_intl_1 = require("./src/create-intl");
40
+ Object.defineProperty(exports, "createIntl", { enumerable: true, get: function () { return create_intl_1.createIntl; } });
@@ -1,13 +1,16 @@
1
- import { __assign } from "tslib";
2
- import { createFormatters, DEFAULT_INTL_CONFIG } from './utils';
3
- import { InvalidConfigError, MissingDataError } from './error';
4
- import { formatNumber, formatNumberToParts } from './number';
5
- import { formatRelativeTime } from './relativeTime';
6
- import { formatDate, formatDateToParts, formatTime, formatTimeToParts, formatDateTimeRange, } from './dateTime';
7
- import { formatPlural } from './plural';
8
- import { formatMessage } from './message';
9
- import { formatList, formatListToParts } from './list';
10
- import { formatDisplayName } from './displayName';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIntl = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var utils_1 = require("./utils");
6
+ var error_1 = require("./error");
7
+ var number_1 = require("./number");
8
+ var relativeTime_1 = require("./relativeTime");
9
+ var dateTime_1 = require("./dateTime");
10
+ var plural_1 = require("./plural");
11
+ var message_1 = require("./message");
12
+ var list_1 = require("./list");
13
+ var displayName_1 = require("./displayName");
11
14
  function messagesContainString(messages) {
12
15
  var firstMessage = messages ? messages[Object.keys(messages)[0]] : undefined;
13
16
  return typeof firstMessage === 'string';
@@ -24,13 +27,13 @@ function verifyConfigMessages(config) {
24
27
  * @param config intl config
25
28
  * @param cache cache for formatter instances to prevent memory leak
26
29
  */
27
- export function createIntl(config, cache) {
28
- var formatters = createFormatters(cache);
29
- var resolvedConfig = __assign(__assign({}, DEFAULT_INTL_CONFIG), config);
30
+ function createIntl(config, cache) {
31
+ var formatters = (0, utils_1.createFormatters)(cache);
32
+ var resolvedConfig = tslib_1.__assign(tslib_1.__assign({}, utils_1.DEFAULT_INTL_CONFIG), config);
30
33
  var locale = resolvedConfig.locale, defaultLocale = resolvedConfig.defaultLocale, onError = resolvedConfig.onError;
31
34
  if (!locale) {
32
35
  if (onError) {
33
- onError(new InvalidConfigError("\"locale\" was not configured, using \"".concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl/api#intlshape for more details")));
36
+ onError(new error_1.InvalidConfigError("\"locale\" was not configured, using \"".concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl/api#intlshape for more details")));
34
37
  }
35
38
  // Since there's no registered locale data for `locale`, this will
36
39
  // fallback to the `defaultLocale` to make sure things can render.
@@ -40,16 +43,17 @@ export function createIntl(config, cache) {
40
43
  resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
41
44
  }
42
45
  else if (!Intl.NumberFormat.supportedLocalesOf(locale).length && onError) {
43
- onError(new MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.NumberFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details")));
46
+ onError(new error_1.MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.NumberFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details")));
44
47
  }
45
48
  else if (!Intl.DateTimeFormat.supportedLocalesOf(locale).length &&
46
49
  onError) {
47
- onError(new MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.DateTimeFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details")));
50
+ onError(new error_1.MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.DateTimeFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details")));
48
51
  }
49
52
  verifyConfigMessages(resolvedConfig);
50
- return __assign(__assign({}, resolvedConfig), { formatters: formatters, formatNumber: formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: formatPlural.bind(null, resolvedConfig, formatters.getPluralRules),
53
+ return tslib_1.__assign(tslib_1.__assign({}, resolvedConfig), { formatters: formatters, formatNumber: number_1.formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: number_1.formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: relativeTime_1.formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: dateTime_1.formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: dateTime_1.formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: dateTime_1.formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: dateTime_1.formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: dateTime_1.formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: plural_1.formatPlural.bind(null, resolvedConfig, formatters.getPluralRules),
51
54
  // @ts-expect-error TODO: will get to this later
52
- formatMessage: formatMessage.bind(null, resolvedConfig, formatters),
55
+ formatMessage: message_1.formatMessage.bind(null, resolvedConfig, formatters),
53
56
  // @ts-expect-error TODO: will get to this later
54
- $t: formatMessage.bind(null, resolvedConfig, formatters), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatListToParts: formatListToParts.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
57
+ $t: message_1.formatMessage.bind(null, resolvedConfig, formatters), formatList: list_1.formatList.bind(null, resolvedConfig, formatters.getListFormat), formatListToParts: list_1.formatListToParts.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: displayName_1.formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
55
58
  }
59
+ exports.createIntl = createIntl;
@@ -1,6 +1,9 @@
1
- import { __assign } from "tslib";
2
- import { filterProps, getNamedFormat } from './utils';
3
- import { IntlFormatError } from './error';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatTimeToParts = exports.formatDateToParts = exports.formatDateTimeRange = exports.formatTime = exports.formatDate = exports.getFormatter = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var utils_1 = require("./utils");
6
+ var error_1 = require("./error");
4
7
  var DATE_TIME_FORMAT_OPTIONS = [
5
8
  'formatMatcher',
6
9
  'timeZone',
@@ -22,12 +25,12 @@ var DATE_TIME_FORMAT_OPTIONS = [
22
25
  'numberingSystem',
23
26
  'fractionalSecondDigits',
24
27
  ];
25
- export function getFormatter(_a, type, getDateTimeFormat, options) {
28
+ function getFormatter(_a, type, getDateTimeFormat, options) {
26
29
  var locale = _a.locale, formats = _a.formats, onError = _a.onError, timeZone = _a.timeZone;
27
30
  if (options === void 0) { options = {}; }
28
31
  var format = options.format;
29
- var defaults = __assign(__assign({}, (timeZone && { timeZone: timeZone })), (format && getNamedFormat(formats, type, format, onError)));
30
- var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults);
32
+ var defaults = tslib_1.__assign(tslib_1.__assign({}, (timeZone && { timeZone: timeZone })), (format && (0, utils_1.getNamedFormat)(formats, type, format, onError)));
33
+ var filteredOptions = (0, utils_1.filterProps)(options, DATE_TIME_FORMAT_OPTIONS, defaults);
31
34
  if (type === 'time' &&
32
35
  !filteredOptions.hour &&
33
36
  !filteredOptions.minute &&
@@ -35,11 +38,12 @@ export function getFormatter(_a, type, getDateTimeFormat, options) {
35
38
  !filteredOptions.timeStyle &&
36
39
  !filteredOptions.dateStyle) {
37
40
  // Add default formatting options if hour, minute, or second isn't defined.
38
- filteredOptions = __assign(__assign({}, filteredOptions), { hour: 'numeric', minute: 'numeric' });
41
+ filteredOptions = tslib_1.__assign(tslib_1.__assign({}, filteredOptions), { hour: 'numeric', minute: 'numeric' });
39
42
  }
40
43
  return getDateTimeFormat(locale, filteredOptions);
41
44
  }
42
- export function formatDate(config, getDateTimeFormat) {
45
+ exports.getFormatter = getFormatter;
46
+ function formatDate(config, getDateTimeFormat) {
43
47
  var _a = [];
44
48
  for (var _i = 2; _i < arguments.length; _i++) {
45
49
  _a[_i - 2] = arguments[_i];
@@ -50,11 +54,12 @@ export function formatDate(config, getDateTimeFormat) {
50
54
  return getFormatter(config, 'date', getDateTimeFormat, options).format(date);
51
55
  }
52
56
  catch (e) {
53
- config.onError(new IntlFormatError('Error formatting date.', config.locale, e));
57
+ config.onError(new error_1.IntlFormatError('Error formatting date.', config.locale, e));
54
58
  }
55
59
  return String(date);
56
60
  }
57
- export function formatTime(config, getDateTimeFormat) {
61
+ exports.formatDate = formatDate;
62
+ function formatTime(config, getDateTimeFormat) {
58
63
  var _a = [];
59
64
  for (var _i = 2; _i < arguments.length; _i++) {
60
65
  _a[_i - 2] = arguments[_i];
@@ -65,27 +70,29 @@ export function formatTime(config, getDateTimeFormat) {
65
70
  return getFormatter(config, 'time', getDateTimeFormat, options).format(date);
66
71
  }
67
72
  catch (e) {
68
- config.onError(new IntlFormatError('Error formatting time.', config.locale, e));
73
+ config.onError(new error_1.IntlFormatError('Error formatting time.', config.locale, e));
69
74
  }
70
75
  return String(date);
71
76
  }
72
- export function formatDateTimeRange(config, getDateTimeFormat) {
77
+ exports.formatTime = formatTime;
78
+ function formatDateTimeRange(config, getDateTimeFormat) {
73
79
  var _a = [];
74
80
  for (var _i = 2; _i < arguments.length; _i++) {
75
81
  _a[_i - 2] = arguments[_i];
76
82
  }
77
83
  var from = _a[0], to = _a[1], _b = _a[2], options = _b === void 0 ? {} : _b;
78
84
  var timeZone = config.timeZone, locale = config.locale, onError = config.onError;
79
- var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, timeZone ? { timeZone: timeZone } : {});
85
+ var filteredOptions = (0, utils_1.filterProps)(options, DATE_TIME_FORMAT_OPTIONS, timeZone ? { timeZone: timeZone } : {});
80
86
  try {
81
87
  return getDateTimeFormat(locale, filteredOptions).formatRange(from, to);
82
88
  }
83
89
  catch (e) {
84
- onError(new IntlFormatError('Error formatting date time range.', config.locale, e));
90
+ onError(new error_1.IntlFormatError('Error formatting date time range.', config.locale, e));
85
91
  }
86
92
  return String(from);
87
93
  }
88
- export function formatDateToParts(config, getDateTimeFormat) {
94
+ exports.formatDateTimeRange = formatDateTimeRange;
95
+ function formatDateToParts(config, getDateTimeFormat) {
89
96
  var _a = [];
90
97
  for (var _i = 2; _i < arguments.length; _i++) {
91
98
  _a[_i - 2] = arguments[_i];
@@ -96,11 +103,12 @@ export function formatDateToParts(config, getDateTimeFormat) {
96
103
  return getFormatter(config, 'date', getDateTimeFormat, options).formatToParts(date); // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged
97
104
  }
98
105
  catch (e) {
99
- config.onError(new IntlFormatError('Error formatting date.', config.locale, e));
106
+ config.onError(new error_1.IntlFormatError('Error formatting date.', config.locale, e));
100
107
  }
101
108
  return [];
102
109
  }
103
- export function formatTimeToParts(config, getDateTimeFormat) {
110
+ exports.formatDateToParts = formatDateToParts;
111
+ function formatTimeToParts(config, getDateTimeFormat) {
104
112
  var _a = [];
105
113
  for (var _i = 2; _i < arguments.length; _i++) {
106
114
  _a[_i - 2] = arguments[_i];
@@ -111,7 +119,8 @@ export function formatTimeToParts(config, getDateTimeFormat) {
111
119
  return getFormatter(config, 'time', getDateTimeFormat, options).formatToParts(date); // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged
112
120
  }
113
121
  catch (e) {
114
- config.onError(new IntlFormatError('Error formatting time.', config.locale, e));
122
+ config.onError(new error_1.IntlFormatError('Error formatting time.', config.locale, e));
115
123
  }
116
124
  return [];
117
125
  }
126
+ exports.formatTimeToParts = formatTimeToParts;
@@ -1,23 +1,27 @@
1
- import { filterProps } from './utils';
2
- import { FormatError, ErrorCode } from 'intl-messageformat';
3
- import { IntlFormatError } from './error';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatDisplayName = void 0;
4
+ var utils_1 = require("./utils");
5
+ var intl_messageformat_1 = require("intl-messageformat");
6
+ var error_1 = require("./error");
4
7
  var DISPLAY_NAMES_OPTONS = [
5
8
  'style',
6
9
  'type',
7
10
  'fallback',
8
11
  'languageDisplay',
9
12
  ];
10
- export function formatDisplayName(_a, getDisplayNames, value, options) {
13
+ function formatDisplayName(_a, getDisplayNames, value, options) {
11
14
  var locale = _a.locale, onError = _a.onError;
12
15
  var DisplayNames = Intl.DisplayNames;
13
16
  if (!DisplayNames) {
14
- onError(new FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", ErrorCode.MISSING_INTL_API));
17
+ onError(new intl_messageformat_1.FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", intl_messageformat_1.ErrorCode.MISSING_INTL_API));
15
18
  }
16
- var filteredOptions = filterProps(options, DISPLAY_NAMES_OPTONS);
19
+ var filteredOptions = (0, utils_1.filterProps)(options, DISPLAY_NAMES_OPTONS);
17
20
  try {
18
21
  return getDisplayNames(locale, filteredOptions).of(value);
19
22
  }
20
23
  catch (e) {
21
- onError(new IntlFormatError('Error formatting display name.', locale, e));
24
+ onError(new error_1.IntlFormatError('Error formatting display name.', locale, e));
22
25
  }
23
26
  }
27
+ exports.formatDisplayName = formatDisplayName;
package/lib/src/error.js CHANGED
@@ -1,14 +1,17 @@
1
- import { __extends } from "tslib";
2
- export var IntlErrorCode;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MissingTranslationError = exports.MessageFormatError = exports.IntlFormatError = exports.MissingDataError = exports.InvalidConfigError = exports.UnsupportedFormatterError = exports.IntlError = exports.IntlErrorCode = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var IntlErrorCode;
3
6
  (function (IntlErrorCode) {
4
7
  IntlErrorCode["FORMAT_ERROR"] = "FORMAT_ERROR";
5
8
  IntlErrorCode["UNSUPPORTED_FORMATTER"] = "UNSUPPORTED_FORMATTER";
6
9
  IntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
7
10
  IntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
8
11
  IntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
9
- })(IntlErrorCode || (IntlErrorCode = {}));
12
+ })(IntlErrorCode || (exports.IntlErrorCode = IntlErrorCode = {}));
10
13
  var IntlError = /** @class */ (function (_super) {
11
- __extends(IntlError, _super);
14
+ tslib_1.__extends(IntlError, _super);
12
15
  function IntlError(code, message, exception) {
13
16
  var _this = this;
14
17
  var err = exception
@@ -27,33 +30,33 @@ var IntlError = /** @class */ (function (_super) {
27
30
  }
28
31
  return IntlError;
29
32
  }(Error));
30
- export { IntlError };
33
+ exports.IntlError = IntlError;
31
34
  var UnsupportedFormatterError = /** @class */ (function (_super) {
32
- __extends(UnsupportedFormatterError, _super);
35
+ tslib_1.__extends(UnsupportedFormatterError, _super);
33
36
  function UnsupportedFormatterError(message, exception) {
34
37
  return _super.call(this, IntlErrorCode.UNSUPPORTED_FORMATTER, message, exception) || this;
35
38
  }
36
39
  return UnsupportedFormatterError;
37
40
  }(IntlError));
38
- export { UnsupportedFormatterError };
41
+ exports.UnsupportedFormatterError = UnsupportedFormatterError;
39
42
  var InvalidConfigError = /** @class */ (function (_super) {
40
- __extends(InvalidConfigError, _super);
43
+ tslib_1.__extends(InvalidConfigError, _super);
41
44
  function InvalidConfigError(message, exception) {
42
45
  return _super.call(this, IntlErrorCode.INVALID_CONFIG, message, exception) || this;
43
46
  }
44
47
  return InvalidConfigError;
45
48
  }(IntlError));
46
- export { InvalidConfigError };
49
+ exports.InvalidConfigError = InvalidConfigError;
47
50
  var MissingDataError = /** @class */ (function (_super) {
48
- __extends(MissingDataError, _super);
51
+ tslib_1.__extends(MissingDataError, _super);
49
52
  function MissingDataError(message, exception) {
50
53
  return _super.call(this, IntlErrorCode.MISSING_DATA, message, exception) || this;
51
54
  }
52
55
  return MissingDataError;
53
56
  }(IntlError));
54
- export { MissingDataError };
57
+ exports.MissingDataError = MissingDataError;
55
58
  var IntlFormatError = /** @class */ (function (_super) {
56
- __extends(IntlFormatError, _super);
59
+ tslib_1.__extends(IntlFormatError, _super);
57
60
  function IntlFormatError(message, locale, exception) {
58
61
  var _this = _super.call(this, IntlErrorCode.FORMAT_ERROR, "".concat(message, "\nLocale: ").concat(locale, "\n"), exception) || this;
59
62
  _this.locale = locale;
@@ -61,9 +64,9 @@ var IntlFormatError = /** @class */ (function (_super) {
61
64
  }
62
65
  return IntlFormatError;
63
66
  }(IntlError));
64
- export { IntlFormatError };
67
+ exports.IntlFormatError = IntlFormatError;
65
68
  var MessageFormatError = /** @class */ (function (_super) {
66
- __extends(MessageFormatError, _super);
69
+ tslib_1.__extends(MessageFormatError, _super);
67
70
  function MessageFormatError(message, locale, descriptor, exception) {
68
71
  var _this = _super.call(this, "".concat(message, "\nMessageID: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.id, "\nDefault Message: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.defaultMessage, "\nDescription: ").concat(descriptor === null || descriptor === void 0 ? void 0 : descriptor.description, "\n"), locale, exception) || this;
69
72
  _this.descriptor = descriptor;
@@ -72,9 +75,9 @@ var MessageFormatError = /** @class */ (function (_super) {
72
75
  }
73
76
  return MessageFormatError;
74
77
  }(IntlFormatError));
75
- export { MessageFormatError };
78
+ exports.MessageFormatError = MessageFormatError;
76
79
  var MissingTranslationError = /** @class */ (function (_super) {
77
- __extends(MissingTranslationError, _super);
80
+ tslib_1.__extends(MissingTranslationError, _super);
78
81
  function MissingTranslationError(descriptor, locale) {
79
82
  var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"".concat(descriptor.id, "\" for locale \"").concat(locale, "\", using ").concat(descriptor.defaultMessage
80
83
  ? "default message (".concat(typeof descriptor.defaultMessage === 'string'
@@ -88,4 +91,4 @@ var MissingTranslationError = /** @class */ (function (_super) {
88
91
  }
89
92
  return MissingTranslationError;
90
93
  }(IntlError));
91
- export { MissingTranslationError };
94
+ exports.MissingTranslationError = MissingTranslationError;
package/lib/src/list.js CHANGED
@@ -1,7 +1,10 @@
1
- import { __assign } from "tslib";
2
- import { filterProps } from './utils';
3
- import { FormatError, ErrorCode } from 'intl-messageformat';
4
- import { IntlFormatError } from './error';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatListToParts = exports.formatList = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var utils_1 = require("./utils");
6
+ var intl_messageformat_1 = require("intl-messageformat");
7
+ var error_1 = require("./error");
5
8
  var LIST_FORMAT_OPTIONS = [
6
9
  'type',
7
10
  'style',
@@ -10,7 +13,7 @@ var now = Date.now();
10
13
  function generateToken(i) {
11
14
  return "".concat(now, "_").concat(i, "_").concat(now);
12
15
  }
13
- export function formatList(opts, getListFormat, values, options) {
16
+ function formatList(opts, getListFormat, values, options) {
14
17
  if (options === void 0) { options = {}; }
15
18
  var results = formatListToParts(opts, getListFormat, values, options).reduce(function (all, el) {
16
19
  var val = el.value;
@@ -27,14 +30,15 @@ export function formatList(opts, getListFormat, values, options) {
27
30
  }, []);
28
31
  return results.length === 1 ? results[0] : results.length === 0 ? '' : results;
29
32
  }
30
- export function formatListToParts(_a, getListFormat, values, options) {
33
+ exports.formatList = formatList;
34
+ function formatListToParts(_a, getListFormat, values, options) {
31
35
  var locale = _a.locale, onError = _a.onError;
32
36
  if (options === void 0) { options = {}; }
33
37
  var ListFormat = Intl.ListFormat;
34
38
  if (!ListFormat) {
35
- onError(new FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", ErrorCode.MISSING_INTL_API));
39
+ onError(new intl_messageformat_1.FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", intl_messageformat_1.ErrorCode.MISSING_INTL_API));
36
40
  }
37
- var filteredOptions = filterProps(options, LIST_FORMAT_OPTIONS);
41
+ var filteredOptions = (0, utils_1.filterProps)(options, LIST_FORMAT_OPTIONS);
38
42
  try {
39
43
  var richValues_1 = {};
40
44
  var serializedValues = values.map(function (v, i) {
@@ -50,12 +54,13 @@ export function formatListToParts(_a, getListFormat, values, options) {
50
54
  .map(function (part) {
51
55
  return part.type === 'literal'
52
56
  ? part
53
- : __assign(__assign({}, part), { value: richValues_1[part.value] || part.value });
57
+ : tslib_1.__assign(tslib_1.__assign({}, part), { value: richValues_1[part.value] || part.value });
54
58
  });
55
59
  }
56
60
  catch (e) {
57
- onError(new IntlFormatError('Error formatting list.', locale, e));
61
+ onError(new error_1.IntlFormatError('Error formatting list.', locale, e));
58
62
  }
59
63
  // @ts-ignore
60
64
  return values;
61
65
  }
66
+ exports.formatListToParts = formatListToParts;
@@ -1,18 +1,21 @@
1
- import { __assign } from "tslib";
2
- import { invariant } from '@formatjs/ecma402-abstract';
3
- import { IntlMessageFormat, } from 'intl-messageformat';
4
- import { MissingTranslationError, MessageFormatError } from './error';
5
- import { TYPE } from '@formatjs/icu-messageformat-parser';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatMessage = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
6
+ var intl_messageformat_1 = require("intl-messageformat");
7
+ var error_1 = require("./error");
8
+ var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
6
9
  function setTimeZoneInOptions(opts, timeZone) {
7
10
  return Object.keys(opts).reduce(function (all, k) {
8
- all[k] = __assign({ timeZone: timeZone }, opts[k]);
11
+ all[k] = tslib_1.__assign({ timeZone: timeZone }, opts[k]);
9
12
  return all;
10
13
  }, {});
11
14
  }
12
15
  function deepMergeOptions(opts1, opts2) {
13
- var keys = Object.keys(__assign(__assign({}, opts1), opts2));
16
+ var keys = Object.keys(tslib_1.__assign(tslib_1.__assign({}, opts1), opts2));
14
17
  return keys.reduce(function (all, k) {
15
- all[k] = __assign(__assign({}, (opts1[k] || {})), (opts2[k] || {}));
18
+ all[k] = tslib_1.__assign(tslib_1.__assign({}, (opts1[k] || {})), (opts2[k] || {}));
16
19
  return all;
17
20
  }, {});
18
21
  }
@@ -20,15 +23,15 @@ function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
20
23
  if (!timeZone) {
21
24
  return f1;
22
25
  }
23
- var mfFormats = IntlMessageFormat.formats;
24
- return __assign(__assign(__assign({}, mfFormats), f1), { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
26
+ var mfFormats = intl_messageformat_1.IntlMessageFormat.formats;
27
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, mfFormats), f1), { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
25
28
  }
26
- export var formatMessage = function (_a, state, messageDescriptor, values, opts) {
29
+ var formatMessage = function (_a, state, messageDescriptor, values, opts) {
27
30
  var locale = _a.locale, formats = _a.formats, messages = _a.messages, defaultLocale = _a.defaultLocale, defaultFormats = _a.defaultFormats, fallbackOnEmptyString = _a.fallbackOnEmptyString, onError = _a.onError, timeZone = _a.timeZone, defaultRichTextElements = _a.defaultRichTextElements;
28
31
  if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; }
29
32
  var msgId = messageDescriptor.id, defaultMessage = messageDescriptor.defaultMessage;
30
33
  // `id` is a required field of a Message Descriptor.
31
- invariant(!!msgId, "[@formatjs/intl] An `id` must be provided to format a message. You can either:\n1. Configure your build toolchain with [babel-plugin-formatjs](https://formatjs.io/docs/tooling/babel-plugin)\nor [@formatjs/ts-transformer](https://formatjs.io/docs/tooling/ts-transformer) OR\n2. Configure your `eslint` config to include [eslint-plugin-formatjs](https://formatjs.io/docs/tooling/linter#enforce-id)\nto autofix this issue");
34
+ (0, ecma402_abstract_1.invariant)(!!msgId, "[@formatjs/intl] An `id` must be provided to format a message. You can either:\n1. Configure your build toolchain with [babel-plugin-formatjs](https://formatjs.io/docs/tooling/babel-plugin)\nor [@formatjs/ts-transformer](https://formatjs.io/docs/tooling/ts-transformer) OR\n2. Configure your `eslint` config to include [eslint-plugin-formatjs](https://formatjs.io/docs/tooling/linter#enforce-id)\nto autofix this issue");
32
35
  var id = String(msgId);
33
36
  var message =
34
37
  // In case messages is Object.create(null)
@@ -40,7 +43,7 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
40
43
  // IMPORTANT: Hot path if `message` is AST with a single literal node
41
44
  if (Array.isArray(message) &&
42
45
  message.length === 1 &&
43
- message[0].type === TYPE.literal) {
46
+ message[0].type === icu_messageformat_parser_1.TYPE.literal) {
44
47
  return message[0].value;
45
48
  }
46
49
  // IMPORTANT: Hot path straight lookup for performance
@@ -50,7 +53,7 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
50
53
  !defaultRichTextElements) {
51
54
  return message.replace(/'\{(.*?)\}'/gi, "{$1}");
52
55
  }
53
- values = __assign(__assign({}, defaultRichTextElements), (values || {}));
56
+ values = tslib_1.__assign(tslib_1.__assign({}, defaultRichTextElements), (values || {}));
54
57
  formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
55
58
  defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
56
59
  if (!message) {
@@ -62,7 +65,7 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
62
65
  // This prevents warnings from littering the console in development
63
66
  // when no `messages` are passed into the <IntlProvider> for the
64
67
  // default locale.
65
- onError(new MissingTranslationError(messageDescriptor, locale));
68
+ onError(new error_1.MissingTranslationError(messageDescriptor, locale));
66
69
  }
67
70
  if (defaultMessage) {
68
71
  try {
@@ -70,7 +73,7 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
70
73
  return formatter.format(values);
71
74
  }
72
75
  catch (e) {
73
- onError(new MessageFormatError("Error formatting default message for: \"".concat(id, "\", rendering default message verbatim"), locale, messageDescriptor, e));
76
+ onError(new error_1.MessageFormatError("Error formatting default message for: \"".concat(id, "\", rendering default message verbatim"), locale, messageDescriptor, e));
74
77
  return typeof defaultMessage === 'string' ? defaultMessage : id;
75
78
  }
76
79
  }
@@ -78,11 +81,11 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
78
81
  }
79
82
  // We have the translated message
80
83
  try {
81
- var formatter = state.getMessageFormat(message, locale, formats, __assign({ formatters: state }, (opts || {})));
84
+ var formatter = state.getMessageFormat(message, locale, formats, tslib_1.__assign({ formatters: state }, (opts || {})));
82
85
  return formatter.format(values);
83
86
  }
84
87
  catch (e) {
85
- onError(new MessageFormatError("Error formatting message: \"".concat(id, "\", using ").concat(defaultMessage ? 'default message' : 'id', " as fallback."), locale, messageDescriptor, e));
88
+ onError(new error_1.MessageFormatError("Error formatting message: \"".concat(id, "\", using ").concat(defaultMessage ? 'default message' : 'id', " as fallback."), locale, messageDescriptor, e));
86
89
  }
87
90
  if (defaultMessage) {
88
91
  try {
@@ -90,7 +93,7 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
90
93
  return formatter.format(values);
91
94
  }
92
95
  catch (e) {
93
- onError(new MessageFormatError("Error formatting the default message for: \"".concat(id, "\", rendering message verbatim"), locale, messageDescriptor, e));
96
+ onError(new error_1.MessageFormatError("Error formatting the default message for: \"".concat(id, "\", rendering message verbatim"), locale, messageDescriptor, e));
94
97
  }
95
98
  }
96
99
  if (typeof message === 'string') {
@@ -101,3 +104,4 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
101
104
  }
102
105
  return id;
103
106
  };
107
+ exports.formatMessage = formatMessage;
package/lib/src/number.js CHANGED
@@ -1,5 +1,8 @@
1
- import { getNamedFormat, filterProps } from './utils';
2
- import { IntlFormatError } from './error';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatNumberToParts = exports.formatNumber = exports.getFormatter = void 0;
4
+ var utils_1 = require("./utils");
5
+ var error_1 = require("./error");
3
6
  var NUMBER_FORMAT_OPTIONS = [
4
7
  'style',
5
8
  'currency',
@@ -22,33 +25,36 @@ var NUMBER_FORMAT_OPTIONS = [
22
25
  'unitDisplay',
23
26
  'numberingSystem',
24
27
  ];
25
- export function getFormatter(_a, getNumberFormat, options) {
28
+ function getFormatter(_a, getNumberFormat, options) {
26
29
  var locale = _a.locale, formats = _a.formats, onError = _a.onError;
27
30
  if (options === void 0) { options = {}; }
28
31
  var format = options.format;
29
32
  var defaults = ((format &&
30
- getNamedFormat(formats, 'number', format, onError)) ||
33
+ (0, utils_1.getNamedFormat)(formats, 'number', format, onError)) ||
31
34
  {});
32
- var filteredOptions = filterProps(options, NUMBER_FORMAT_OPTIONS, defaults);
35
+ var filteredOptions = (0, utils_1.filterProps)(options, NUMBER_FORMAT_OPTIONS, defaults);
33
36
  return getNumberFormat(locale, filteredOptions);
34
37
  }
35
- export function formatNumber(config, getNumberFormat, value, options) {
38
+ exports.getFormatter = getFormatter;
39
+ function formatNumber(config, getNumberFormat, value, options) {
36
40
  if (options === void 0) { options = {}; }
37
41
  try {
38
42
  return getFormatter(config, getNumberFormat, options).format(value);
39
43
  }
40
44
  catch (e) {
41
- config.onError(new IntlFormatError('Error formatting number.', config.locale, e));
45
+ config.onError(new error_1.IntlFormatError('Error formatting number.', config.locale, e));
42
46
  }
43
47
  return String(value);
44
48
  }
45
- export function formatNumberToParts(config, getNumberFormat, value, options) {
49
+ exports.formatNumber = formatNumber;
50
+ function formatNumberToParts(config, getNumberFormat, value, options) {
46
51
  if (options === void 0) { options = {}; }
47
52
  try {
48
53
  return getFormatter(config, getNumberFormat, options).formatToParts(value);
49
54
  }
50
55
  catch (e) {
51
- config.onError(new IntlFormatError('Error formatting number.', config.locale, e));
56
+ config.onError(new error_1.IntlFormatError('Error formatting number.', config.locale, e));
52
57
  }
53
58
  return [];
54
59
  }
60
+ exports.formatNumberToParts = formatNumberToParts;
package/lib/src/plural.js CHANGED
@@ -1,19 +1,23 @@
1
- import { filterProps } from './utils';
2
- import { IntlFormatError } from './error';
3
- import { ErrorCode, FormatError } from 'intl-messageformat';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatPlural = void 0;
4
+ var utils_1 = require("./utils");
5
+ var error_1 = require("./error");
6
+ var intl_messageformat_1 = require("intl-messageformat");
4
7
  var PLURAL_FORMAT_OPTIONS = ['type'];
5
- export function formatPlural(_a, getPluralRules, value, options) {
8
+ function formatPlural(_a, getPluralRules, value, options) {
6
9
  var locale = _a.locale, onError = _a.onError;
7
10
  if (options === void 0) { options = {}; }
8
11
  if (!Intl.PluralRules) {
9
- onError(new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", ErrorCode.MISSING_INTL_API));
12
+ onError(new intl_messageformat_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", intl_messageformat_1.ErrorCode.MISSING_INTL_API));
10
13
  }
11
- var filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);
14
+ var filteredOptions = (0, utils_1.filterProps)(options, PLURAL_FORMAT_OPTIONS);
12
15
  try {
13
16
  return getPluralRules(locale, filteredOptions).select(value);
14
17
  }
15
18
  catch (e) {
16
- onError(new IntlFormatError('Error formatting plural.', locale, e));
19
+ onError(new error_1.IntlFormatError('Error formatting plural.', locale, e));
17
20
  }
18
21
  return 'other';
19
22
  }
23
+ exports.formatPlural = formatPlural;
@@ -1,29 +1,33 @@
1
- import { getNamedFormat, filterProps } from './utils';
2
- import { FormatError, ErrorCode } from 'intl-messageformat';
3
- import { IntlFormatError } from './error';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatRelativeTime = void 0;
4
+ var utils_1 = require("./utils");
5
+ var intl_messageformat_1 = require("intl-messageformat");
6
+ var error_1 = require("./error");
4
7
  var RELATIVE_TIME_FORMAT_OPTIONS = ['numeric', 'style'];
5
8
  function getFormatter(_a, getRelativeTimeFormat, options) {
6
9
  var locale = _a.locale, formats = _a.formats, onError = _a.onError;
7
10
  if (options === void 0) { options = {}; }
8
11
  var format = options.format;
9
- var defaults = (!!format && getNamedFormat(formats, 'relative', format, onError)) || {};
10
- var filteredOptions = filterProps(options, RELATIVE_TIME_FORMAT_OPTIONS, defaults);
12
+ var defaults = (!!format && (0, utils_1.getNamedFormat)(formats, 'relative', format, onError)) || {};
13
+ var filteredOptions = (0, utils_1.filterProps)(options, RELATIVE_TIME_FORMAT_OPTIONS, defaults);
11
14
  return getRelativeTimeFormat(locale, filteredOptions);
12
15
  }
13
- export function formatRelativeTime(config, getRelativeTimeFormat, value, unit, options) {
16
+ function formatRelativeTime(config, getRelativeTimeFormat, value, unit, options) {
14
17
  if (options === void 0) { options = {}; }
15
18
  if (!unit) {
16
19
  unit = 'second';
17
20
  }
18
21
  var RelativeTimeFormat = Intl.RelativeTimeFormat;
19
22
  if (!RelativeTimeFormat) {
20
- config.onError(new FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", ErrorCode.MISSING_INTL_API));
23
+ config.onError(new intl_messageformat_1.FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", intl_messageformat_1.ErrorCode.MISSING_INTL_API));
21
24
  }
22
25
  try {
23
26
  return getFormatter(config, getRelativeTimeFormat, options).format(value, unit);
24
27
  }
25
28
  catch (e) {
26
- config.onError(new IntlFormatError('Error formatting relative time.', config.locale, e));
29
+ config.onError(new error_1.IntlFormatError('Error formatting relative time.', config.locale, e));
27
30
  }
28
31
  return String(value);
29
32
  }
33
+ exports.formatRelativeTime = formatRelativeTime;
package/lib/src/types.js CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/src/utils.js CHANGED
@@ -1,8 +1,11 @@
1
- import { __assign, __spreadArray } from "tslib";
2
- import { IntlMessageFormat } from 'intl-messageformat';
3
- import { memoize, strategies } from '@formatjs/fast-memoize';
4
- import { UnsupportedFormatterError } from './error';
5
- export function filterProps(props, allowlist, defaults) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNamedFormat = exports.createFormatters = exports.createIntlCache = exports.DEFAULT_INTL_CONFIG = exports.filterProps = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var intl_messageformat_1 = require("intl-messageformat");
6
+ var fast_memoize_1 = require("@formatjs/fast-memoize");
7
+ var error_1 = require("./error");
8
+ function filterProps(props, allowlist, defaults) {
6
9
  if (defaults === void 0) { defaults = {}; }
7
10
  return allowlist.reduce(function (filtered, name) {
8
11
  if (name in props) {
@@ -14,6 +17,7 @@ export function filterProps(props, allowlist, defaults) {
14
17
  return filtered;
15
18
  }, {});
16
19
  }
20
+ exports.filterProps = filterProps;
17
21
  var defaultErrorHandler = function (error) {
18
22
  // @ts-ignore just so we don't need to declare dep on @types/node
19
23
  if (process.env.NODE_ENV !== 'production') {
@@ -26,7 +30,7 @@ var defaultWarnHandler = function (warning) {
26
30
  console.warn(warning);
27
31
  }
28
32
  };
29
- export var DEFAULT_INTL_CONFIG = {
33
+ exports.DEFAULT_INTL_CONFIG = {
30
34
  formats: {},
31
35
  messages: {},
32
36
  timeZone: undefined,
@@ -36,7 +40,7 @@ export var DEFAULT_INTL_CONFIG = {
36
40
  onError: defaultErrorHandler,
37
41
  onWarn: defaultWarnHandler,
38
42
  };
39
- export function createIntlCache() {
43
+ function createIntlCache() {
40
44
  return {
41
45
  dateTime: {},
42
46
  number: {},
@@ -47,6 +51,7 @@ export function createIntlCache() {
47
51
  displayNames: {},
48
52
  };
49
53
  }
54
+ exports.createIntlCache = createIntlCache;
50
55
  function createFastMemoizeCache(store) {
51
56
  return {
52
57
  create: function () {
@@ -65,91 +70,92 @@ function createFastMemoizeCache(store) {
65
70
  * Create intl formatters and populate cache
66
71
  * @param cache explicit cache to prevent leaking memory
67
72
  */
68
- export function createFormatters(cache) {
73
+ function createFormatters(cache) {
69
74
  if (cache === void 0) { cache = createIntlCache(); }
70
75
  var RelativeTimeFormat = Intl.RelativeTimeFormat;
71
76
  var ListFormat = Intl.ListFormat;
72
77
  var DisplayNames = Intl.DisplayNames;
73
- var getDateTimeFormat = memoize(function () {
78
+ var getDateTimeFormat = (0, fast_memoize_1.memoize)(function () {
74
79
  var _a;
75
80
  var args = [];
76
81
  for (var _i = 0; _i < arguments.length; _i++) {
77
82
  args[_i] = arguments[_i];
78
83
  }
79
- return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
84
+ return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
80
85
  }, {
81
86
  cache: createFastMemoizeCache(cache.dateTime),
82
- strategy: strategies.variadic,
87
+ strategy: fast_memoize_1.strategies.variadic,
83
88
  });
84
- var getNumberFormat = memoize(function () {
89
+ var getNumberFormat = (0, fast_memoize_1.memoize)(function () {
85
90
  var _a;
86
91
  var args = [];
87
92
  for (var _i = 0; _i < arguments.length; _i++) {
88
93
  args[_i] = arguments[_i];
89
94
  }
90
- return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
95
+ return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
91
96
  }, {
92
97
  cache: createFastMemoizeCache(cache.number),
93
- strategy: strategies.variadic,
98
+ strategy: fast_memoize_1.strategies.variadic,
94
99
  });
95
- var getPluralRules = memoize(function () {
100
+ var getPluralRules = (0, fast_memoize_1.memoize)(function () {
96
101
  var _a;
97
102
  var args = [];
98
103
  for (var _i = 0; _i < arguments.length; _i++) {
99
104
  args[_i] = arguments[_i];
100
105
  }
101
- return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
106
+ return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
102
107
  }, {
103
108
  cache: createFastMemoizeCache(cache.pluralRules),
104
- strategy: strategies.variadic,
109
+ strategy: fast_memoize_1.strategies.variadic,
105
110
  });
106
111
  return {
107
112
  getDateTimeFormat: getDateTimeFormat,
108
113
  getNumberFormat: getNumberFormat,
109
- getMessageFormat: memoize(function (message, locales, overrideFormats, opts) {
110
- return new IntlMessageFormat(message, locales, overrideFormats, __assign({ formatters: {
114
+ getMessageFormat: (0, fast_memoize_1.memoize)(function (message, locales, overrideFormats, opts) {
115
+ return new intl_messageformat_1.IntlMessageFormat(message, locales, overrideFormats, tslib_1.__assign({ formatters: {
111
116
  getNumberFormat: getNumberFormat,
112
117
  getDateTimeFormat: getDateTimeFormat,
113
118
  getPluralRules: getPluralRules,
114
119
  } }, (opts || {})));
115
120
  }, {
116
121
  cache: createFastMemoizeCache(cache.message),
117
- strategy: strategies.variadic,
122
+ strategy: fast_memoize_1.strategies.variadic,
118
123
  }),
119
- getRelativeTimeFormat: memoize(function () {
124
+ getRelativeTimeFormat: (0, fast_memoize_1.memoize)(function () {
120
125
  var args = [];
121
126
  for (var _i = 0; _i < arguments.length; _i++) {
122
127
  args[_i] = arguments[_i];
123
128
  }
124
- return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, __spreadArray([void 0], args, false)))();
129
+ return new (RelativeTimeFormat.bind.apply(RelativeTimeFormat, tslib_1.__spreadArray([void 0], args, false)))();
125
130
  }, {
126
131
  cache: createFastMemoizeCache(cache.relativeTime),
127
- strategy: strategies.variadic,
132
+ strategy: fast_memoize_1.strategies.variadic,
128
133
  }),
129
134
  getPluralRules: getPluralRules,
130
- getListFormat: memoize(function () {
135
+ getListFormat: (0, fast_memoize_1.memoize)(function () {
131
136
  var args = [];
132
137
  for (var _i = 0; _i < arguments.length; _i++) {
133
138
  args[_i] = arguments[_i];
134
139
  }
135
- return new (ListFormat.bind.apply(ListFormat, __spreadArray([void 0], args, false)))();
140
+ return new (ListFormat.bind.apply(ListFormat, tslib_1.__spreadArray([void 0], args, false)))();
136
141
  }, {
137
142
  cache: createFastMemoizeCache(cache.list),
138
- strategy: strategies.variadic,
143
+ strategy: fast_memoize_1.strategies.variadic,
139
144
  }),
140
- getDisplayNames: memoize(function () {
145
+ getDisplayNames: (0, fast_memoize_1.memoize)(function () {
141
146
  var args = [];
142
147
  for (var _i = 0; _i < arguments.length; _i++) {
143
148
  args[_i] = arguments[_i];
144
149
  }
145
- return new (DisplayNames.bind.apply(DisplayNames, __spreadArray([void 0], args, false)))();
150
+ return new (DisplayNames.bind.apply(DisplayNames, tslib_1.__spreadArray([void 0], args, false)))();
146
151
  }, {
147
152
  cache: createFastMemoizeCache(cache.displayNames),
148
- strategy: strategies.variadic,
153
+ strategy: fast_memoize_1.strategies.variadic,
149
154
  }),
150
155
  };
151
156
  }
152
- export function getNamedFormat(formats, type, name, onError) {
157
+ exports.createFormatters = createFormatters;
158
+ function getNamedFormat(formats, type, name, onError) {
153
159
  var formatType = formats && formats[type];
154
160
  var format;
155
161
  if (formatType) {
@@ -158,5 +164,6 @@ export function getNamedFormat(formats, type, name, onError) {
158
164
  if (format) {
159
165
  return format;
160
166
  }
161
- onError(new UnsupportedFormatterError("No ".concat(type, " format named: ").concat(name)));
167
+ onError(new error_1.UnsupportedFormatterError("No ".concat(type, " format named: ").concat(name)));
162
168
  }
169
+ exports.getNamedFormat = getNamedFormat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl",
3
- "version": "2.9.5",
3
+ "version": "2.9.7",
4
4
  "description": "Internationalize JS apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.",
5
5
  "keywords": [
6
6
  "intl",
@@ -30,16 +30,16 @@
30
30
  "sideEffects": false,
31
31
  "dependencies": {
32
32
  "tslib": "^2.4.0",
33
- "@formatjs/intl-displaynames": "6.6.1",
34
- "@formatjs/intl-listformat": "7.5.0",
35
- "@formatjs/icu-messageformat-parser": "2.7.0",
36
- "@formatjs/ecma402-abstract": "1.17.2",
33
+ "@formatjs/intl-displaynames": "6.6.3",
37
34
  "@formatjs/fast-memoize": "2.2.0",
38
- "intl-messageformat": "10.5.4"
35
+ "@formatjs/icu-messageformat-parser": "2.7.2",
36
+ "@formatjs/ecma402-abstract": "1.17.4",
37
+ "@formatjs/intl-listformat": "7.5.2",
38
+ "intl-messageformat": "10.5.6"
39
39
  },
40
40
  "devDependencies": {
41
- "@formatjs/intl-datetimeformat": "6.11.1",
42
- "@formatjs/intl-numberformat": "8.8.0"
41
+ "@formatjs/intl-datetimeformat": "6.11.3",
42
+ "@formatjs/intl-numberformat": "8.8.2"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "typescript": "5"
package/src/error.js CHANGED
@@ -9,7 +9,7 @@ var IntlErrorCode;
9
9
  IntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
10
10
  IntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
11
11
  IntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
12
- })(IntlErrorCode = exports.IntlErrorCode || (exports.IntlErrorCode = {}));
12
+ })(IntlErrorCode || (exports.IntlErrorCode = IntlErrorCode = {}));
13
13
  var IntlError = /** @class */ (function (_super) {
14
14
  tslib_1.__extends(IntlError, _super);
15
15
  function IntlError(code, message, exception) {