@formatjs/intl 2.3.1 → 2.3.2

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.
Files changed (106) hide show
  1. package/BUILD +79 -0
  2. package/CHANGELOG.md +537 -0
  3. package/LICENSE.md +0 -0
  4. package/README.md +0 -0
  5. package/index.ts +38 -0
  6. package/package.json +12 -8
  7. package/src/create-intl.ts +159 -0
  8. package/src/dateTime.ts +204 -0
  9. package/src/displayName.ts +54 -0
  10. package/src/error.ts +106 -0
  11. package/src/list.ts +119 -0
  12. package/src/message.ts +246 -0
  13. package/src/number.ts +101 -0
  14. package/src/plural.ts +45 -0
  15. package/src/relativeTime.ts +74 -0
  16. package/src/types.ts +234 -0
  17. package/src/utils.ts +177 -0
  18. package/tests/__snapshots__/formatDate.test.ts.snap +13 -0
  19. package/tests/__snapshots__/formatMessage.test.ts.snap +45 -0
  20. package/tests/__snapshots__/formatNumber.test.ts.snap +13 -0
  21. package/tests/__snapshots__/formatRelativeTime.test.ts.snap +19 -0
  22. package/tests/__snapshots__/formatTime.test.ts.snap +13 -0
  23. package/tests/create-intl.test.ts +60 -0
  24. package/tests/error.test.ts +25 -0
  25. package/tests/formatDate.test.ts +167 -0
  26. package/tests/formatDisplayNames.test.ts +63 -0
  27. package/tests/formatList.test.ts +51 -0
  28. package/tests/formatMessage.test.ts +495 -0
  29. package/tests/formatNumber.test.ts +172 -0
  30. package/tests/formatPlural.test.ts +119 -0
  31. package/tests/formatRelativeTime.test.ts +145 -0
  32. package/tests/formatTime.test.ts +234 -0
  33. package/tests/global.d.ts +7 -0
  34. package/tsconfig.json +5 -0
  35. package/index.d.ts +0 -17
  36. package/index.d.ts.map +0 -1
  37. package/index.js +0 -40
  38. package/lib/index.d.ts +0 -17
  39. package/lib/index.d.ts.map +0 -1
  40. package/lib/index.js +0 -17
  41. package/lib/src/create-intl.d.ts +0 -11
  42. package/lib/src/create-intl.d.ts.map +0 -1
  43. package/lib/src/create-intl.js +0 -51
  44. package/lib/src/dateTime.d.ts +0 -38
  45. package/lib/src/dateTime.d.ts.map +0 -1
  46. package/lib/src/dateTime.js +0 -117
  47. package/lib/src/displayName.d.ts +0 -6
  48. package/lib/src/displayName.d.ts.map +0 -1
  49. package/lib/src/displayName.js +0 -22
  50. package/lib/src/error.d.ts +0 -34
  51. package/lib/src/error.d.ts.map +0 -1
  52. package/lib/src/error.js +0 -88
  53. package/lib/src/list.d.ts +0 -11
  54. package/lib/src/list.d.ts.map +0 -1
  55. package/lib/src/list.js +0 -61
  56. package/lib/src/message.d.ts +0 -16
  57. package/lib/src/message.d.ts.map +0 -1
  58. package/lib/src/message.js +0 -103
  59. package/lib/src/number.d.ts +0 -17
  60. package/lib/src/number.d.ts.map +0 -1
  61. package/lib/src/number.js +0 -54
  62. package/lib/src/plural.d.ts +0 -7
  63. package/lib/src/plural.d.ts.map +0 -1
  64. package/lib/src/plural.js +0 -19
  65. package/lib/src/relativeTime.d.ts +0 -7
  66. package/lib/src/relativeTime.d.ts.map +0 -1
  67. package/lib/src/relativeTime.js +0 -29
  68. package/lib/src/types.d.ts +0 -103
  69. package/lib/src/types.d.ts.map +0 -1
  70. package/lib/src/types.js +0 -1
  71. package/lib/src/utils.d.ts +0 -12
  72. package/lib/src/utils.d.ts.map +0 -1
  73. package/lib/src/utils.js +0 -162
  74. package/src/create-intl.d.ts +0 -11
  75. package/src/create-intl.d.ts.map +0 -1
  76. package/src/create-intl.js +0 -55
  77. package/src/dateTime.d.ts +0 -38
  78. package/src/dateTime.d.ts.map +0 -1
  79. package/src/dateTime.js +0 -126
  80. package/src/displayName.d.ts +0 -6
  81. package/src/displayName.d.ts.map +0 -1
  82. package/src/displayName.js +0 -26
  83. package/src/error.d.ts +0 -34
  84. package/src/error.d.ts.map +0 -1
  85. package/src/error.js +0 -91
  86. package/src/list.d.ts +0 -11
  87. package/src/list.d.ts.map +0 -1
  88. package/src/list.js +0 -66
  89. package/src/message.d.ts +0 -16
  90. package/src/message.d.ts.map +0 -1
  91. package/src/message.js +0 -107
  92. package/src/number.d.ts +0 -17
  93. package/src/number.d.ts.map +0 -1
  94. package/src/number.js +0 -60
  95. package/src/plural.d.ts +0 -7
  96. package/src/plural.d.ts.map +0 -1
  97. package/src/plural.js +0 -23
  98. package/src/relativeTime.d.ts +0 -7
  99. package/src/relativeTime.d.ts.map +0 -1
  100. package/src/relativeTime.js +0 -33
  101. package/src/types.d.ts +0 -103
  102. package/src/types.d.ts.map +0 -1
  103. package/src/types.js +0 -2
  104. package/src/utils.d.ts +0 -12
  105. package/src/utils.d.ts.map +0 -1
  106. package/src/utils.js +0 -169
package/src/dateTime.js DELETED
@@ -1,126 +0,0 @@
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");
7
- var DATE_TIME_FORMAT_OPTIONS = [
8
- 'formatMatcher',
9
- 'timeZone',
10
- 'hour12',
11
- 'weekday',
12
- 'era',
13
- 'year',
14
- 'month',
15
- 'day',
16
- 'hour',
17
- 'minute',
18
- 'second',
19
- 'timeZoneName',
20
- 'hourCycle',
21
- 'dateStyle',
22
- 'timeStyle',
23
- 'calendar',
24
- // 'dayPeriod',
25
- 'numberingSystem',
26
- 'fractionalSecondDigits',
27
- ];
28
- function getFormatter(_a, type, getDateTimeFormat, options) {
29
- var locale = _a.locale, formats = _a.formats, onError = _a.onError, timeZone = _a.timeZone;
30
- if (options === void 0) { options = {}; }
31
- var format = options.format;
32
- var defaults = (0, tslib_1.__assign)((0, 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);
34
- if (type === 'time' &&
35
- !filteredOptions.hour &&
36
- !filteredOptions.minute &&
37
- !filteredOptions.second &&
38
- !filteredOptions.timeStyle &&
39
- !filteredOptions.dateStyle) {
40
- // Add default formatting options if hour, minute, or second isn't defined.
41
- filteredOptions = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, filteredOptions), { hour: 'numeric', minute: 'numeric' });
42
- }
43
- return getDateTimeFormat(locale, filteredOptions);
44
- }
45
- exports.getFormatter = getFormatter;
46
- function formatDate(config, getDateTimeFormat) {
47
- var _a = [];
48
- for (var _i = 2; _i < arguments.length; _i++) {
49
- _a[_i - 2] = arguments[_i];
50
- }
51
- var value = _a[0], _b = _a[1], options = _b === void 0 ? {} : _b;
52
- var date = typeof value === 'string' ? new Date(value || 0) : value;
53
- try {
54
- return getFormatter(config, 'date', getDateTimeFormat, options).format(date);
55
- }
56
- catch (e) {
57
- config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting date.', e));
58
- }
59
- return String(date);
60
- }
61
- exports.formatDate = formatDate;
62
- function formatTime(config, getDateTimeFormat) {
63
- var _a = [];
64
- for (var _i = 2; _i < arguments.length; _i++) {
65
- _a[_i - 2] = arguments[_i];
66
- }
67
- var value = _a[0], _b = _a[1], options = _b === void 0 ? {} : _b;
68
- var date = typeof value === 'string' ? new Date(value || 0) : value;
69
- try {
70
- return getFormatter(config, 'time', getDateTimeFormat, options).format(date);
71
- }
72
- catch (e) {
73
- config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting time.', e));
74
- }
75
- return String(date);
76
- }
77
- exports.formatTime = formatTime;
78
- function formatDateTimeRange(config, getDateTimeFormat) {
79
- var _a = [];
80
- for (var _i = 2; _i < arguments.length; _i++) {
81
- _a[_i - 2] = arguments[_i];
82
- }
83
- var from = _a[0], to = _a[1], _b = _a[2], options = _b === void 0 ? {} : _b;
84
- 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 } : {});
86
- try {
87
- return getDateTimeFormat(locale, filteredOptions).formatRange(from, to);
88
- }
89
- catch (e) {
90
- onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting date time range.', e));
91
- }
92
- return String(from);
93
- }
94
- exports.formatDateTimeRange = formatDateTimeRange;
95
- function formatDateToParts(config, getDateTimeFormat) {
96
- var _a = [];
97
- for (var _i = 2; _i < arguments.length; _i++) {
98
- _a[_i - 2] = arguments[_i];
99
- }
100
- var value = _a[0], _b = _a[1], options = _b === void 0 ? {} : _b;
101
- var date = typeof value === 'string' ? new Date(value || 0) : value;
102
- try {
103
- return getFormatter(config, 'date', getDateTimeFormat, options).formatToParts(date);
104
- }
105
- catch (e) {
106
- config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting date.', e));
107
- }
108
- return [];
109
- }
110
- exports.formatDateToParts = formatDateToParts;
111
- function formatTimeToParts(config, getDateTimeFormat) {
112
- var _a = [];
113
- for (var _i = 2; _i < arguments.length; _i++) {
114
- _a[_i - 2] = arguments[_i];
115
- }
116
- var value = _a[0], _b = _a[1], options = _b === void 0 ? {} : _b;
117
- var date = typeof value === 'string' ? new Date(value || 0) : value;
118
- try {
119
- return getFormatter(config, 'time', getDateTimeFormat, options).formatToParts(date);
120
- }
121
- catch (e) {
122
- config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting time.', e));
123
- }
124
- return [];
125
- }
126
- exports.formatTimeToParts = formatTimeToParts;
@@ -1,6 +0,0 @@
1
- import { Formatters, IntlFormatters, OnErrorFn } from './types';
2
- export declare function formatDisplayName({ locale, onError, }: {
3
- locale: string;
4
- onError: OnErrorFn;
5
- }, getDisplayNames: Formatters['getDisplayNames'], value: Parameters<IntlFormatters['formatDisplayName']>[0], options: Parameters<IntlFormatters['formatDisplayName']>[1]): string | undefined;
6
- //# sourceMappingURL=displayName.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"displayName.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/displayName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAe7D,wBAAgB,iBAAiB,CAC/B,EACE,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAC9C,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,EACzD,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1D,MAAM,GAAG,SAAS,CA2BpB"}
@@ -1,26 +0,0 @@
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");
7
- var DISPLAY_NAMES_OPTONS = [
8
- 'style',
9
- 'type',
10
- 'fallback',
11
- ];
12
- function formatDisplayName(_a, getDisplayNames, value, options) {
13
- var locale = _a.locale, onError = _a.onError;
14
- var DisplayNames = Intl.DisplayNames;
15
- if (!DisplayNames) {
16
- 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));
17
- }
18
- var filteredOptions = (0, utils_1.filterProps)(options, DISPLAY_NAMES_OPTONS);
19
- try {
20
- return getDisplayNames(locale, filteredOptions).of(value);
21
- }
22
- catch (e) {
23
- onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting display name.', e));
24
- }
25
- }
26
- exports.formatDisplayName = formatDisplayName;
package/src/error.d.ts DELETED
@@ -1,34 +0,0 @@
1
- import { MessageDescriptor } from './types';
2
- export declare enum IntlErrorCode {
3
- FORMAT_ERROR = "FORMAT_ERROR",
4
- UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
5
- INVALID_CONFIG = "INVALID_CONFIG",
6
- MISSING_DATA = "MISSING_DATA",
7
- MISSING_TRANSLATION = "MISSING_TRANSLATION"
8
- }
9
- export declare class IntlError<T extends IntlErrorCode = IntlErrorCode.FORMAT_ERROR> extends Error {
10
- readonly code: T;
11
- constructor(code: T, message: string, exception?: Error | unknown);
12
- }
13
- export declare class UnsupportedFormatterError extends IntlError<IntlErrorCode.UNSUPPORTED_FORMATTER> {
14
- constructor(message: string, exception?: Error | unknown);
15
- }
16
- export declare class InvalidConfigError extends IntlError<IntlErrorCode.INVALID_CONFIG> {
17
- constructor(message: string, exception?: Error | unknown);
18
- }
19
- export declare class MissingDataError extends IntlError<IntlErrorCode.MISSING_DATA> {
20
- constructor(message: string, exception?: Error | unknown);
21
- }
22
- export declare class IntlFormatError extends IntlError<IntlErrorCode.FORMAT_ERROR> {
23
- readonly descriptor?: MessageDescriptor;
24
- constructor(message: string, locale: string, exception?: Error | unknown);
25
- }
26
- export declare class MessageFormatError extends IntlFormatError {
27
- readonly descriptor?: MessageDescriptor;
28
- constructor(message: string, locale: string, descriptor?: MessageDescriptor, exception?: Error | unknown);
29
- }
30
- export declare class MissingTranslationError extends IntlError<IntlErrorCode.MISSING_TRANSLATION> {
31
- readonly descriptor?: MessageDescriptor;
32
- constructor(descriptor: MessageDescriptor, locale: string);
33
- }
34
- //# sourceMappingURL=error.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAA;AAEzC,oBAAY,aAAa;IACvB,YAAY,iBAAiB;IAC7B,qBAAqB,0BAA0B;IAC/C,cAAc,mBAAmB;IACjC,YAAY,iBAAiB;IAC7B,mBAAmB,wBAAwB;CAC5C;AAED,qBAAa,SAAS,CACpB,CAAC,SAAS,aAAa,GAAG,aAAa,CAAC,YAAY,CACpD,SAAQ,KAAK;IACb,SAAgB,IAAI,EAAE,CAAC,CAAA;gBAEX,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO;CAiBlE;AAED,qBAAa,yBAA0B,SAAQ,SAAS,CAAC,aAAa,CAAC,qBAAqB,CAAC;gBAC/E,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO;CAGzD;AAED,qBAAa,kBAAmB,SAAQ,SAAS,CAAC,aAAa,CAAC,cAAc,CAAC;gBACjE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO;CAGzD;AAED,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,aAAa,CAAC,YAAY,CAAC;gBAC7D,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO;CAGzD;AAED,qBAAa,eAAgB,SAAQ,SAAS,CAAC,aAAa,CAAC,YAAY,CAAC;IACxE,SAAgB,UAAU,CAAC,EAAE,iBAAiB,CAAA;gBAClC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO;CASzE;AAED,qBAAa,kBAAmB,SAAQ,eAAe;IACrD,SAAgB,UAAU,CAAC,EAAE,iBAAiB,CAAA;gBAE5C,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO;CAa9B;AAED,qBAAa,uBAAwB,SAAQ,SAAS,CAAC,aAAa,CAAC,mBAAmB,CAAC;IACvF,SAAgB,UAAU,CAAC,EAAE,iBAAiB,CAAA;gBAClC,UAAU,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM;CAiB1D"}
package/src/error.js DELETED
@@ -1,91 +0,0 @@
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;
6
- (function (IntlErrorCode) {
7
- IntlErrorCode["FORMAT_ERROR"] = "FORMAT_ERROR";
8
- IntlErrorCode["UNSUPPORTED_FORMATTER"] = "UNSUPPORTED_FORMATTER";
9
- IntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
10
- IntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
11
- IntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
12
- })(IntlErrorCode = exports.IntlErrorCode || (exports.IntlErrorCode = {}));
13
- var IntlError = /** @class */ (function (_super) {
14
- (0, tslib_1.__extends)(IntlError, _super);
15
- function IntlError(code, message, exception) {
16
- var _this = this;
17
- var err = exception
18
- ? exception instanceof Error
19
- ? exception
20
- : new Error(String(exception))
21
- : undefined;
22
- _this = _super.call(this, "[@formatjs/intl Error ".concat(code, "] ").concat(message, "\n").concat(err ? "\n".concat(err.message, "\n").concat(err.stack) : '')) || this;
23
- _this.code = code;
24
- // @ts-ignore just so we don't need to declare dep on @types/node
25
- if (typeof Error.captureStackTrace === 'function') {
26
- // @ts-ignore just so we don't need to declare dep on @types/node
27
- Error.captureStackTrace(_this, IntlError);
28
- }
29
- return _this;
30
- }
31
- return IntlError;
32
- }(Error));
33
- exports.IntlError = IntlError;
34
- var UnsupportedFormatterError = /** @class */ (function (_super) {
35
- (0, tslib_1.__extends)(UnsupportedFormatterError, _super);
36
- function UnsupportedFormatterError(message, exception) {
37
- return _super.call(this, IntlErrorCode.UNSUPPORTED_FORMATTER, message, exception) || this;
38
- }
39
- return UnsupportedFormatterError;
40
- }(IntlError));
41
- exports.UnsupportedFormatterError = UnsupportedFormatterError;
42
- var InvalidConfigError = /** @class */ (function (_super) {
43
- (0, tslib_1.__extends)(InvalidConfigError, _super);
44
- function InvalidConfigError(message, exception) {
45
- return _super.call(this, IntlErrorCode.INVALID_CONFIG, message, exception) || this;
46
- }
47
- return InvalidConfigError;
48
- }(IntlError));
49
- exports.InvalidConfigError = InvalidConfigError;
50
- var MissingDataError = /** @class */ (function (_super) {
51
- (0, tslib_1.__extends)(MissingDataError, _super);
52
- function MissingDataError(message, exception) {
53
- return _super.call(this, IntlErrorCode.MISSING_DATA, message, exception) || this;
54
- }
55
- return MissingDataError;
56
- }(IntlError));
57
- exports.MissingDataError = MissingDataError;
58
- var IntlFormatError = /** @class */ (function (_super) {
59
- (0, tslib_1.__extends)(IntlFormatError, _super);
60
- function IntlFormatError(message, locale, exception) {
61
- return _super.call(this, IntlErrorCode.FORMAT_ERROR, "".concat(message, "\nLocale: ").concat(locale, "\n"), exception) || this;
62
- }
63
- return IntlFormatError;
64
- }(IntlError));
65
- exports.IntlFormatError = IntlFormatError;
66
- var MessageFormatError = /** @class */ (function (_super) {
67
- (0, tslib_1.__extends)(MessageFormatError, _super);
68
- function MessageFormatError(message, locale, descriptor, exception) {
69
- 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;
70
- _this.descriptor = descriptor;
71
- return _this;
72
- }
73
- return MessageFormatError;
74
- }(IntlFormatError));
75
- exports.MessageFormatError = MessageFormatError;
76
- var MissingTranslationError = /** @class */ (function (_super) {
77
- (0, tslib_1.__extends)(MissingTranslationError, _super);
78
- function MissingTranslationError(descriptor, locale) {
79
- var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"".concat(descriptor.id, "\" for locale \"").concat(locale, "\", using ").concat(descriptor.defaultMessage
80
- ? "default message (".concat(typeof descriptor.defaultMessage === 'string'
81
- ? descriptor.defaultMessage
82
- : descriptor.defaultMessage
83
- .map(function (e) { var _a; return (_a = e.value) !== null && _a !== void 0 ? _a : JSON.stringify(e); })
84
- .join(), ")")
85
- : 'id', " as fallback.")) || this;
86
- _this.descriptor = descriptor;
87
- return _this;
88
- }
89
- return MissingTranslationError;
90
- }(IntlError));
91
- exports.MissingTranslationError = MissingTranslationError;
package/src/list.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { Formatters, IntlFormatters, OnErrorFn } from './types';
2
- import type { Part } from '@formatjs/intl-listformat';
3
- export declare function formatList(opts: {
4
- locale: string;
5
- onError: OnErrorFn;
6
- }, getListFormat: Formatters['getListFormat'], values: ReadonlyArray<string>, options: Parameters<IntlFormatters['formatList']>[1]): string;
7
- export declare function formatListToParts<T>(opts: {
8
- locale: string;
9
- onError: OnErrorFn;
10
- }, getListFormat: Formatters['getListFormat'], values: ReadonlyArray<string>, options: Parameters<IntlFormatters['formatList']>[1]): Part[];
11
- //# sourceMappingURL=list.d.ts.map
package/src/list.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAG7D,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,2BAA2B,CAAA;AAgBnD,wBAAgB,UAAU,CACxB,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,aAAa,EAAE,UAAU,CAAC,eAAe,CAAC,EAC1C,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GACnD,MAAM,CAAA;AA6BT,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,aAAa,EAAE,UAAU,CAAC,eAAe,CAAC,EAC1C,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GACnD,IAAI,EAAE,CAAA"}
package/src/list.js DELETED
@@ -1,66 +0,0 @@
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");
8
- var LIST_FORMAT_OPTIONS = [
9
- 'type',
10
- 'style',
11
- ];
12
- var now = Date.now();
13
- function generateToken(i) {
14
- return "".concat(now, "_").concat(i, "_").concat(now);
15
- }
16
- function formatList(opts, getListFormat, values, options) {
17
- if (options === void 0) { options = {}; }
18
- var results = formatListToParts(opts, getListFormat, values, options).reduce(function (all, el) {
19
- var val = el.value;
20
- if (typeof val !== 'string') {
21
- all.push(val);
22
- }
23
- else if (typeof all[all.length - 1] === 'string') {
24
- all[all.length - 1] += val;
25
- }
26
- else {
27
- all.push(val);
28
- }
29
- return all;
30
- }, []);
31
- return results.length === 1 ? results[0] : results;
32
- }
33
- exports.formatList = formatList;
34
- function formatListToParts(_a, getListFormat, values, options) {
35
- var locale = _a.locale, onError = _a.onError;
36
- if (options === void 0) { options = {}; }
37
- var ListFormat = Intl.ListFormat;
38
- 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));
40
- }
41
- var filteredOptions = (0, utils_1.filterProps)(options, LIST_FORMAT_OPTIONS);
42
- try {
43
- var richValues_1 = {};
44
- var serializedValues = values.map(function (v, i) {
45
- if (typeof v === 'object') {
46
- var id = generateToken(i);
47
- richValues_1[id] = v;
48
- return id;
49
- }
50
- return String(v);
51
- });
52
- return getListFormat(locale, filteredOptions)
53
- .formatToParts(serializedValues)
54
- .map(function (part) {
55
- return part.type === 'literal'
56
- ? part
57
- : (0, tslib_1.__assign)((0, tslib_1.__assign)({}, part), { value: richValues_1[part.value] || part.value });
58
- });
59
- }
60
- catch (e) {
61
- onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting list.', e));
62
- }
63
- // @ts-ignore
64
- return values;
65
- }
66
- exports.formatListToParts = formatListToParts;
package/src/message.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Formatters, MessageDescriptor, CustomFormats, OnErrorFn } from './types';
2
- import { FormatXMLElementFn, PrimitiveType, Formatters as IntlMessageFormatFormatters, Options } from 'intl-messageformat';
3
- import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
4
- export declare type FormatMessageFn<T> = ({ locale, formats, messages, defaultLocale, defaultFormats, fallbackOnEmptyString, onError, timeZone, defaultRichTextElements, }: {
5
- locale: string;
6
- timeZone?: string;
7
- formats: CustomFormats;
8
- messages: Record<string, string> | Record<string, MessageFormatElement[]>;
9
- defaultLocale: string;
10
- defaultFormats: CustomFormats;
11
- defaultRichTextElements?: Record<string, FormatXMLElementFn<T>>;
12
- fallbackOnEmptyString?: boolean;
13
- onError: OnErrorFn;
14
- }, state: IntlMessageFormatFormatters & Pick<Formatters, 'getMessageFormat'>, messageDescriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: Options) => T extends string ? string : Array<T | string> | string | T;
15
- export declare const formatMessage: FormatMessageFn<any>;
16
- //# sourceMappingURL=message.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAE/E,OAAO,EAEL,kBAAkB,EAClB,aAAa,EACb,UAAU,IAAI,2BAA2B,EACzC,OAAO,EACR,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAO,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AAsD7E,oBAAY,eAAe,CAAC,CAAC,IAAI,CAC/B,EACE,MAAM,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,OAAO,EACP,QAAQ,EACR,uBAAuB,GACxB,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,aAAa,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAA;IACzE,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,aAAa,CAAA;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/D,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,KAAK,EAAE,2BAA2B,GAAG,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,EACzE,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAClE,IAAI,CAAC,EAAE,OAAO,KACX,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,CAAA;AAE/D,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,GAAG,CAuJ9C,CAAA"}
package/src/message.js DELETED
@@ -1,107 +0,0 @@
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");
9
- function setTimeZoneInOptions(opts, timeZone) {
10
- return Object.keys(opts).reduce(function (all, k) {
11
- all[k] = (0, tslib_1.__assign)({ timeZone: timeZone }, opts[k]);
12
- return all;
13
- }, {});
14
- }
15
- function deepMergeOptions(opts1, opts2) {
16
- var keys = Object.keys((0, tslib_1.__assign)((0, tslib_1.__assign)({}, opts1), opts2));
17
- return keys.reduce(function (all, k) {
18
- all[k] = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (opts1[k] || {})), (opts2[k] || {}));
19
- return all;
20
- }, {});
21
- }
22
- function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
23
- if (!timeZone) {
24
- return f1;
25
- }
26
- var mfFormats = intl_messageformat_1.IntlMessageFormat.formats;
27
- return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, 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)) });
28
- }
29
- var formatMessage = function (_a, state, messageDescriptor, values, opts) {
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;
31
- if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; }
32
- var msgId = messageDescriptor.id, defaultMessage = messageDescriptor.defaultMessage;
33
- // `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");
35
- var id = String(msgId);
36
- var message =
37
- // In case messages is Object.create(null)
38
- // e.g import('foo.json') from webpack)
39
- // See https://github.com/formatjs/formatjs/issues/1914
40
- messages &&
41
- Object.prototype.hasOwnProperty.call(messages, id) &&
42
- messages[id];
43
- // IMPORTANT: Hot path if `message` is AST with a single literal node
44
- if (Array.isArray(message) &&
45
- message.length === 1 &&
46
- message[0].type === icu_messageformat_parser_1.TYPE.literal) {
47
- return message[0].value;
48
- }
49
- // IMPORTANT: Hot path straight lookup for performance
50
- if (!values &&
51
- message &&
52
- typeof message === 'string' &&
53
- !defaultRichTextElements) {
54
- return message.replace(/'\{(.*?)\}'/gi, "{$1}");
55
- }
56
- values = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, defaultRichTextElements), (values || {}));
57
- formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
58
- defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
59
- if (!message) {
60
- if (fallbackOnEmptyString === false && message === '') {
61
- return message;
62
- }
63
- if (!defaultMessage ||
64
- (locale && locale.toLowerCase() !== defaultLocale.toLowerCase())) {
65
- // This prevents warnings from littering the console in development
66
- // when no `messages` are passed into the <IntlProvider> for the
67
- // default locale.
68
- onError(new error_1.MissingTranslationError(messageDescriptor, locale));
69
- }
70
- if (defaultMessage) {
71
- try {
72
- var formatter = state.getMessageFormat(defaultMessage, defaultLocale, defaultFormats, opts);
73
- return formatter.format(values);
74
- }
75
- catch (e) {
76
- onError(new error_1.MessageFormatError("Error formatting default message for: \"".concat(id, "\", rendering default message verbatim"), locale, messageDescriptor, e));
77
- return typeof defaultMessage === 'string' ? defaultMessage : id;
78
- }
79
- }
80
- return id;
81
- }
82
- // We have the translated message
83
- try {
84
- var formatter = state.getMessageFormat(message, locale, formats, (0, tslib_1.__assign)({ formatters: state }, (opts || {})));
85
- return formatter.format(values);
86
- }
87
- catch (e) {
88
- onError(new error_1.MessageFormatError("Error formatting message: \"".concat(id, "\", using ").concat(defaultMessage ? 'default message' : 'id', " as fallback."), locale, messageDescriptor, e));
89
- }
90
- if (defaultMessage) {
91
- try {
92
- var formatter = state.getMessageFormat(defaultMessage, defaultLocale, defaultFormats, opts);
93
- return formatter.format(values);
94
- }
95
- catch (e) {
96
- onError(new error_1.MessageFormatError("Error formatting the default message for: \"".concat(id, "\", rendering message verbatim"), locale, messageDescriptor, e));
97
- }
98
- }
99
- if (typeof message === 'string') {
100
- return message;
101
- }
102
- if (typeof defaultMessage === 'string') {
103
- return defaultMessage;
104
- }
105
- return id;
106
- };
107
- exports.formatMessage = formatMessage;
package/src/number.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { Formatters, IntlFormatters, CustomFormats, OnErrorFn } from './types';
2
- export declare function getFormatter({ locale, formats, onError, }: {
3
- locale: string;
4
- formats: CustomFormats;
5
- onError: OnErrorFn;
6
- }, getNumberFormat: Formatters['getNumberFormat'], options?: Parameters<IntlFormatters['formatNumber']>[1]): Intl.NumberFormat;
7
- export declare function formatNumber(config: {
8
- locale: string;
9
- formats: CustomFormats;
10
- onError: OnErrorFn;
11
- }, getNumberFormat: Formatters['getNumberFormat'], value: Parameters<IntlFormatters['formatNumber']>[0], options?: Parameters<IntlFormatters['formatNumber']>[1]): string;
12
- export declare function formatNumberToParts(config: {
13
- locale: string;
14
- formats: CustomFormats;
15
- onError: OnErrorFn;
16
- }, getNumberFormat: Formatters['getNumberFormat'], value: Parameters<IntlFormatters['formatNumber']>[0], options?: Parameters<IntlFormatters['formatNumber']>[1]): Intl.NumberFormatPart[];
17
- //# sourceMappingURL=number.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AA8B5E,wBAAgB,YAAY,CAC1B,EACE,MAAM,EACN,OAAO,EACP,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IAEd,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAC9C,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAM,GAC1D,IAAI,CAAC,YAAY,CAYnB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IAEd,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAC9C,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,EACpD,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAM,GAC1D,MAAM,CAUR;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAC9C,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,EACpD,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAM,GAC1D,IAAI,CAAC,gBAAgB,EAAE,CAYzB"}
package/src/number.js DELETED
@@ -1,60 +0,0 @@
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");
6
- var NUMBER_FORMAT_OPTIONS = [
7
- 'style',
8
- 'currency',
9
- 'currencyDisplay',
10
- 'unit',
11
- 'unitDisplay',
12
- 'useGrouping',
13
- 'minimumIntegerDigits',
14
- 'minimumFractionDigits',
15
- 'maximumFractionDigits',
16
- 'minimumSignificantDigits',
17
- 'maximumSignificantDigits',
18
- // ES2020 NumberFormat
19
- 'compactDisplay',
20
- 'currencyDisplay',
21
- 'currencySign',
22
- 'notation',
23
- 'signDisplay',
24
- 'unit',
25
- 'unitDisplay',
26
- 'numberingSystem',
27
- ];
28
- function getFormatter(_a, getNumberFormat, options) {
29
- var locale = _a.locale, formats = _a.formats, onError = _a.onError;
30
- if (options === void 0) { options = {}; }
31
- var format = options.format;
32
- var defaults = ((format &&
33
- (0, utils_1.getNamedFormat)(formats, 'number', format, onError)) ||
34
- {});
35
- var filteredOptions = (0, utils_1.filterProps)(options, NUMBER_FORMAT_OPTIONS, defaults);
36
- return getNumberFormat(locale, filteredOptions);
37
- }
38
- exports.getFormatter = getFormatter;
39
- function formatNumber(config, getNumberFormat, value, options) {
40
- if (options === void 0) { options = {}; }
41
- try {
42
- return getFormatter(config, getNumberFormat, options).format(value);
43
- }
44
- catch (e) {
45
- config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
46
- }
47
- return String(value);
48
- }
49
- exports.formatNumber = formatNumber;
50
- function formatNumberToParts(config, getNumberFormat, value, options) {
51
- if (options === void 0) { options = {}; }
52
- try {
53
- return getFormatter(config, getNumberFormat, options).formatToParts(value);
54
- }
55
- catch (e) {
56
- config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
57
- }
58
- return [];
59
- }
60
- exports.formatNumberToParts = formatNumberToParts;
package/src/plural.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Formatters, IntlFormatters, OnErrorFn } from './types';
2
- import { LDMLPluralRule } from '@formatjs/ecma402-abstract';
3
- export declare function formatPlural({ locale, onError, }: {
4
- locale: string;
5
- onError: OnErrorFn;
6
- }, getPluralRules: Formatters['getPluralRules'], value: Parameters<IntlFormatters['formatPlural']>[0], options?: Parameters<IntlFormatters['formatPlural']>[1]): LDMLPluralRule;
7
- //# sourceMappingURL=plural.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/plural.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAI7D,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAA;AAIzD,wBAAgB,YAAY,CAC1B,EACE,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,EAC5C,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,EACpD,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAM,GAC1D,cAAc,CAyBhB"}
package/src/plural.js DELETED
@@ -1,23 +0,0 @@
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");
7
- var PLURAL_FORMAT_OPTIONS = ['type'];
8
- function formatPlural(_a, getPluralRules, value, options) {
9
- var locale = _a.locale, onError = _a.onError;
10
- if (options === void 0) { options = {}; }
11
- 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));
13
- }
14
- var filteredOptions = (0, utils_1.filterProps)(options, PLURAL_FORMAT_OPTIONS);
15
- try {
16
- return getPluralRules(locale, filteredOptions).select(value);
17
- }
18
- catch (e) {
19
- onError(new error_1.IntlFormatError('Error formatting plural.', locale, e));
20
- }
21
- return 'other';
22
- }
23
- exports.formatPlural = formatPlural;
@@ -1,7 +0,0 @@
1
- import { IntlFormatters, Formatters, CustomFormats, OnErrorFn } from './types';
2
- export declare function formatRelativeTime(config: {
3
- locale: string;
4
- formats: CustomFormats;
5
- onError: OnErrorFn;
6
- }, getRelativeTimeFormat: Formatters['getRelativeTimeFormat'], value: Parameters<IntlFormatters['formatRelativeTime']>[0], unit?: Parameters<IntlFormatters['formatRelativeTime']>[1], options?: Parameters<IntlFormatters['formatRelativeTime']>[2]): string;
7
- //# sourceMappingURL=relativeTime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relativeTime.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/relativeTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAoC5E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,SAAS,CAAA;CACnB,EACD,qBAAqB,EAAE,UAAU,CAAC,uBAAuB,CAAC,EAC1D,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAC1D,IAAI,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAC1D,OAAO,GAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAM,GAChE,MAAM,CA2BR"}