@formatjs/intl 2.9.6 → 2.9.8

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