@formatjs/intl 2.10.14 → 3.0.0

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/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # @formatjs/intl
2
2
 
3
- We've migrated the docs to https://formatjs.io/docs/intl.
3
+ We've migrated the docs to https://formatjs.github.io/docs/intl.
package/index.js CHANGED
@@ -38,4 +38,3 @@ Object.defineProperty(exports, "formatNumber", { enumerable: true, get: function
38
38
  Object.defineProperty(exports, "formatNumberToParts", { enumerable: true, get: function () { return number_1.formatNumberToParts; } });
39
39
  var create_intl_1 = require("./src/create-intl");
40
40
  Object.defineProperty(exports, "createIntl", { enumerable: true, get: function () { return create_intl_1.createIntl; } });
41
- //# sourceMappingURL=index.js.map
package/lib/index.js CHANGED
@@ -15,4 +15,3 @@ export { formatPlural } from './src/plural';
15
15
  export { formatRelativeTime } from './src/relativeTime';
16
16
  export { formatNumber, formatNumberToParts } from './src/number';
17
17
  export { createIntl } from './src/create-intl';
18
- //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { IntlCache, IntlShape, IntlConfig } from './types';
1
+ import { IntlCache, IntlConfig, IntlShape } from './types';
2
2
  export interface CreateIntlFn<T = string, C extends IntlConfig<T> = IntlConfig<T>, S extends IntlShape<T> = IntlShape<T>> {
3
3
  (config: C, cache?: IntlCache): S;
4
4
  }
@@ -1,13 +1,13 @@
1
1
  import { __assign } from "tslib";
2
- import { createFormatters, DEFAULT_INTL_CONFIG } from './utils';
2
+ import { formatDate, formatDateTimeRange, formatDateToParts, formatTime, formatTimeToParts, } from './dateTime';
3
+ import { formatDisplayName } from './displayName';
3
4
  import { InvalidConfigError, MissingDataError } from './error';
5
+ import { formatList, formatListToParts } from './list';
6
+ import { formatMessage } from './message';
4
7
  import { formatNumber, formatNumberToParts } from './number';
5
- import { formatRelativeTime } from './relativeTime';
6
- import { formatDate, formatDateToParts, formatTime, formatTimeToParts, formatDateTimeRange, } from './dateTime';
7
8
  import { formatPlural } from './plural';
8
- import { formatMessage } from './message';
9
- import { formatList, formatListToParts } from './list';
10
- import { formatDisplayName } from './displayName';
9
+ import { formatRelativeTime } from './relativeTime';
10
+ import { createFormatters, DEFAULT_INTL_CONFIG } from './utils';
11
11
  function messagesContainString(messages) {
12
12
  var firstMessage = messages ? messages[Object.keys(messages)[0]] : undefined;
13
13
  return typeof firstMessage === 'string';
@@ -16,7 +16,7 @@ function verifyConfigMessages(config) {
16
16
  if (config.onWarn &&
17
17
  config.defaultRichTextElements &&
18
18
  messagesContainString(config.messages || {})) {
19
- config.onWarn("[@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.io/docs/getting-started/message-distribution");
19
+ config.onWarn("[@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.github.io/docs/getting-started/message-distribution");
20
20
  }
21
21
  }
22
22
  /**
@@ -30,7 +30,7 @@ export function createIntl(config, cache) {
30
30
  var locale = resolvedConfig.locale, defaultLocale = resolvedConfig.defaultLocale, onError = resolvedConfig.onError;
31
31
  if (!locale) {
32
32
  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")));
33
+ onError(new InvalidConfigError("\"locale\" was not configured, using \"".concat(defaultLocale, "\" as fallback. See https://formatjs.github.io/docs/react-intl/api#intlshape for more details")));
34
34
  }
35
35
  // Since there's no registered locale data for `locale`, this will
36
36
  // fallback to the `defaultLocale` to make sure things can render.
@@ -40,11 +40,11 @@ export function createIntl(config, cache) {
40
40
  resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
41
41
  }
42
42
  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")));
43
+ onError(new MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.NumberFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.github.io/docs/react-intl#runtime-requirements for more details")));
44
44
  }
45
45
  else if (!Intl.DateTimeFormat.supportedLocalesOf(locale).length &&
46
46
  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")));
47
+ onError(new MissingDataError("Missing locale data for locale: \"".concat(locale, "\" in Intl.DateTimeFormat. Using default locale: \"").concat(defaultLocale, "\" as fallback. See https://formatjs.github.io/docs/react-intl#runtime-requirements for more details")));
48
48
  }
49
49
  verifyConfigMessages(resolvedConfig);
50
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,4 +53,3 @@ export function createIntl(config, cache) {
53
53
  // @ts-expect-error TODO: will get to this later
54
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) });
55
55
  }
56
- //# sourceMappingURL=create-intl.js.map
@@ -115,4 +115,3 @@ export function formatTimeToParts(config, getDateTimeFormat) {
115
115
  }
116
116
  return [];
117
117
  }
118
- //# sourceMappingURL=dateTime.js.map
@@ -1,5 +1,5 @@
1
1
  import { filterProps } from './utils';
2
- import { FormatError, ErrorCode } from 'intl-messageformat';
2
+ import { ErrorCode, FormatError } from 'intl-messageformat';
3
3
  import { IntlFormatError } from './error';
4
4
  var DISPLAY_NAMES_OPTONS = [
5
5
  'style',
@@ -21,4 +21,3 @@ export function formatDisplayName(_a, getDisplayNames, value, options) {
21
21
  onError(new IntlFormatError('Error formatting display name.', locale, e));
22
22
  }
23
23
  }
24
- //# sourceMappingURL=displayName.js.map
package/lib/src/error.js CHANGED
@@ -89,4 +89,3 @@ var MissingTranslationError = /** @class */ (function (_super) {
89
89
  return MissingTranslationError;
90
90
  }(IntlError));
91
91
  export { MissingTranslationError };
92
- //# sourceMappingURL=error.js.map
package/lib/src/list.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Formatters, IntlFormatters, OnErrorFn } from './types';
2
- import type { Part } from '@formatjs/intl-listformat';
1
+ import { Formatters, IntlFormatters, OnErrorFn, Part } from './types';
3
2
  export declare function formatList(opts: {
4
3
  locale: string;
5
4
  onError: OnErrorFn;
package/lib/src/list.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { __assign } from "tslib";
2
- import { filterProps } from './utils';
3
- import { FormatError, ErrorCode } from 'intl-messageformat';
2
+ import { ErrorCode, FormatError } from 'intl-messageformat';
4
3
  import { IntlFormatError } from './error';
4
+ import { filterProps } from './utils';
5
5
  var LIST_FORMAT_OPTIONS = [
6
6
  'type',
7
7
  'style',
@@ -48,9 +48,9 @@ export function formatListToParts(_a, getListFormat, values, options) {
48
48
  return getListFormat(locale, filteredOptions)
49
49
  .formatToParts(serializedValues)
50
50
  .map(function (part) {
51
- return part.type === 'literal'
51
+ return (part.type === 'literal'
52
52
  ? part
53
- : __assign(__assign({}, part), { value: richValues_1[part.value] || part.value });
53
+ : __assign(__assign({}, part), { value: richValues_1[part.value] || part.value }));
54
54
  });
55
55
  }
56
56
  catch (e) {
@@ -59,4 +59,3 @@ export function formatListToParts(_a, getListFormat, values, options) {
59
59
  // @ts-ignore
60
60
  return values;
61
61
  }
62
- //# sourceMappingURL=list.js.map
@@ -1,6 +1,6 @@
1
- import { Formatters, MessageDescriptor, CustomFormats, OnErrorFn } from './types';
2
- import { FormatXMLElementFn, PrimitiveType, Formatters as IntlMessageFormatFormatters, Options } from 'intl-messageformat';
1
+ import { CustomFormats, Formatters, MessageDescriptor, OnErrorFn } from './types';
3
2
  import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
3
+ import { FormatXMLElementFn, Formatters as IntlMessageFormatFormatters, Options, PrimitiveType } from 'intl-messageformat';
4
4
  export type FormatMessageFn<T> = ({ locale, formats, messages, defaultLocale, defaultFormats, fallbackOnEmptyString, onError, timeZone, defaultRichTextElements, }: {
5
5
  locale: string;
6
6
  timeZone?: string;
@@ -1,8 +1,8 @@
1
1
  import { __assign } from "tslib";
2
2
  import { invariant } from '@formatjs/ecma402-abstract';
3
- import { IntlMessageFormat, } from 'intl-messageformat';
4
- import { MissingTranslationError, MessageFormatError } from './error';
5
3
  import { TYPE } from '@formatjs/icu-messageformat-parser';
4
+ import { IntlMessageFormat, } from 'intl-messageformat';
5
+ import { MessageFormatError, MissingTranslationError } from './error';
6
6
  function setTimeZoneInOptions(opts, timeZone) {
7
7
  return Object.keys(opts).reduce(function (all, k) {
8
8
  all[k] = __assign({ timeZone: timeZone }, opts[k]);
@@ -28,7 +28,7 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
28
28
  if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; }
29
29
  var msgId = messageDescriptor.id, defaultMessage = messageDescriptor.defaultMessage;
30
30
  // `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");
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.github.io/docs/tooling/babel-plugin)\nor [@formatjs/ts-transformer](https://formatjs.github.io/docs/tooling/ts-transformer) OR\n2. Configure your `eslint` config to include [eslint-plugin-formatjs](https://formatjs.github.io/docs/tooling/linter#enforce-id)\nto autofix this issue");
32
32
  var id = String(msgId);
33
33
  var message =
34
34
  // In case messages is Object.create(null)
@@ -101,4 +101,3 @@ export var formatMessage = function (_a, state, messageDescriptor, values, opts)
101
101
  }
102
102
  return id;
103
103
  };
104
- //# sourceMappingURL=message.js.map
package/lib/src/number.js CHANGED
@@ -56,4 +56,3 @@ export function formatNumberToParts(config, getNumberFormat, value, options) {
56
56
  }
57
57
  return [];
58
58
  }
59
- //# sourceMappingURL=number.js.map
package/lib/src/plural.js CHANGED
@@ -17,4 +17,3 @@ export function formatPlural(_a, getPluralRules, value, options) {
17
17
  }
18
18
  return 'other';
19
19
  }
20
- //# sourceMappingURL=plural.js.map
@@ -27,4 +27,3 @@ export function formatRelativeTime(config, getRelativeTimeFormat, value, unit, o
27
27
  }
28
28
  return String(value);
29
29
  }
30
- //# sourceMappingURL=relativeTime.js.map
@@ -1,10 +1,12 @@
1
1
  import { DateTimeFormat, NumberFormatOptions } from '@formatjs/ecma402-abstract';
2
2
  import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
3
- import { DisplayNames, DisplayNamesOptions } from '@formatjs/intl-displaynames';
4
- import IntlListFormat, { IntlListFormatOptions, Part } from '@formatjs/intl-listformat';
5
3
  import { FormatError, Formats, FormatXMLElementFn, IntlMessageFormat, Options as IntlMessageFormatOptions, PrimitiveType } from 'intl-messageformat';
6
4
  import { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, UnsupportedFormatterError } from './error';
7
5
  import { DEFAULT_INTL_CONFIG } from './utils';
6
+ export interface Part<T = string> {
7
+ type: 'element' | 'literal';
8
+ value: T;
9
+ }
8
10
  declare global {
9
11
  namespace FormatjsIntl {
10
12
  interface Message {
@@ -50,8 +52,8 @@ export type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'
50
52
  export type FormatNumberOptions = Omit<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'>;
51
53
  export type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'time'>;
52
54
  export type FormatPluralOptions = Omit<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
53
- export type FormatListOptions = Omit<IntlListFormatOptions, 'localeMatcher'>;
54
- export type FormatDisplayNameOptions = Omit<DisplayNamesOptions, 'localeMatcher'>;
55
+ export type FormatListOptions = Omit<Intl.ListFormatOptions, 'localeMatcher'>;
56
+ export type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions, 'localeMatcher'>;
55
57
  /**
56
58
  * `TBase` is the type constraints of the rich text element in the formatted output.
57
59
  * For example, with React, `TBase` should be `React.ReactNode`.
@@ -73,7 +75,7 @@ export interface IntlFormatters<TBase = unknown> {
73
75
  formatList(this: void, values: ReadonlyArray<string>, opts?: FormatListOptions): string;
74
76
  formatList<T extends TBase>(this: void, values: ReadonlyArray<string | T>, opts?: FormatListOptions): T | string | (string | T)[];
75
77
  formatListToParts<T extends TBase>(this: void, values: ReadonlyArray<string | T>, opts?: FormatListOptions): Part[];
76
- formatDisplayName(this: void, value: Parameters<DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
78
+ formatDisplayName(this: void, value: Parameters<Intl.DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
77
79
  }
78
80
  export interface Formatters {
79
81
  getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): DateTimeFormat;
@@ -81,8 +83,8 @@ export interface Formatters {
81
83
  getMessageFormat(this: void, ...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
82
84
  getRelativeTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
83
85
  getPluralRules(this: void, ...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
84
- getListFormat(this: void, ...args: ConstructorParameters<typeof IntlListFormat>): IntlListFormat;
85
- getDisplayNames(this: void, ...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
86
+ getListFormat(this: void, ...args: ConstructorParameters<typeof Intl.ListFormat>): Intl.ListFormat;
87
+ getDisplayNames(this: void, ...args: ConstructorParameters<typeof Intl.DisplayNames>): Intl.DisplayNames;
86
88
  }
87
89
  export interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormatters<T> {
88
90
  formatters: Formatters;
@@ -93,8 +95,8 @@ export interface IntlCache {
93
95
  message: Record<string, IntlMessageFormat>;
94
96
  relativeTime: Record<string, Intl.RelativeTimeFormat>;
95
97
  pluralRules: Record<string, Intl.PluralRules>;
96
- list: Record<string, IntlListFormat>;
97
- displayNames: Record<string, DisplayNames>;
98
+ list: Record<string, Intl.ListFormat>;
99
+ displayNames: Record<string, Intl.DisplayNames>;
98
100
  }
99
101
  export interface MessageDescriptor {
100
102
  id?: MessageIds;
package/lib/src/types.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
package/lib/src/utils.js CHANGED
@@ -160,4 +160,3 @@ export function getNamedFormat(formats, type, name, onError) {
160
160
  }
161
161
  onError(new UnsupportedFormatterError("No ".concat(type, " format named: ").concat(name)));
162
162
  }
163
- //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl",
3
- "version": "2.10.14",
3
+ "version": "3.0.0",
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",
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "author": "Long Ho <holevietlong@gmail.com>",
19
19
  "license": "MIT",
20
- "homepage": "https://formatjs.io",
20
+ "homepage": "https://formatjs.github.io",
21
21
  "bugs": {
22
22
  "url": "https://github.com/formatjs/formatjs/issues"
23
23
  },
@@ -30,19 +30,13 @@
30
30
  "sideEffects": false,
31
31
  "dependencies": {
32
32
  "tslib": "2",
33
- "@formatjs/ecma402-abstract": "2.2.3",
33
+ "@formatjs/ecma402-abstract": "2.2.4",
34
34
  "@formatjs/fast-memoize": "2.2.3",
35
- "@formatjs/icu-messageformat-parser": "2.9.3",
36
- "@formatjs/intl-displaynames": "6.8.4",
37
- "intl-messageformat": "10.7.6",
38
- "@formatjs/intl-listformat": "7.7.4"
39
- },
40
- "devDependencies": {
41
- "@formatjs/intl-numberformat": "8.14.4",
42
- "@formatjs/intl-datetimeformat": "6.16.4"
35
+ "intl-messageformat": "10.7.7",
36
+ "@formatjs/icu-messageformat-parser": "2.9.4"
43
37
  },
44
38
  "peerDependencies": {
45
- "typescript": "^4.7 || 5"
39
+ "typescript": "5"
46
40
  },
47
41
  "peerDependenciesMeta": {
48
42
  "typescript": {
@@ -1,4 +1,4 @@
1
- import { IntlCache, IntlShape, IntlConfig } from './types';
1
+ import { IntlCache, IntlConfig, IntlShape } from './types';
2
2
  export interface CreateIntlFn<T = string, C extends IntlConfig<T> = IntlConfig<T>, S extends IntlShape<T> = IntlShape<T>> {
3
3
  (config: C, cache?: IntlCache): S;
4
4
  }
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createIntl = createIntl;
4
4
  var tslib_1 = require("tslib");
5
- var utils_1 = require("./utils");
5
+ var dateTime_1 = require("./dateTime");
6
+ var displayName_1 = require("./displayName");
6
7
  var error_1 = require("./error");
8
+ var list_1 = require("./list");
9
+ var message_1 = require("./message");
7
10
  var number_1 = require("./number");
8
- var relativeTime_1 = require("./relativeTime");
9
- var dateTime_1 = require("./dateTime");
10
11
  var plural_1 = require("./plural");
11
- var message_1 = require("./message");
12
- var list_1 = require("./list");
13
- var displayName_1 = require("./displayName");
12
+ var relativeTime_1 = require("./relativeTime");
13
+ var utils_1 = require("./utils");
14
14
  function messagesContainString(messages) {
15
15
  var firstMessage = messages ? messages[Object.keys(messages)[0]] : undefined;
16
16
  return typeof firstMessage === 'string';
@@ -19,7 +19,7 @@ function verifyConfigMessages(config) {
19
19
  if (config.onWarn &&
20
20
  config.defaultRichTextElements &&
21
21
  messagesContainString(config.messages || {})) {
22
- config.onWarn("[@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.io/docs/getting-started/message-distribution");
22
+ config.onWarn("[@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.github.io/docs/getting-started/message-distribution");
23
23
  }
24
24
  }
25
25
  /**
@@ -33,7 +33,7 @@ function createIntl(config, cache) {
33
33
  var locale = resolvedConfig.locale, defaultLocale = resolvedConfig.defaultLocale, onError = resolvedConfig.onError;
34
34
  if (!locale) {
35
35
  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")));
36
+ onError(new error_1.InvalidConfigError("\"locale\" was not configured, using \"".concat(defaultLocale, "\" as fallback. See https://formatjs.github.io/docs/react-intl/api#intlshape for more details")));
37
37
  }
38
38
  // Since there's no registered locale data for `locale`, this will
39
39
  // fallback to the `defaultLocale` to make sure things can render.
@@ -43,11 +43,11 @@ function createIntl(config, cache) {
43
43
  resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
44
44
  }
45
45
  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")));
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.github.io/docs/react-intl#runtime-requirements for more details")));
47
47
  }
48
48
  else if (!Intl.DateTimeFormat.supportedLocalesOf(locale).length &&
49
49
  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")));
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.github.io/docs/react-intl#runtime-requirements for more details")));
51
51
  }
52
52
  verifyConfigMessages(resolvedConfig);
53
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),
@@ -56,4 +56,3 @@ function createIntl(config, cache) {
56
56
  // @ts-expect-error TODO: will get to this later
57
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) });
58
58
  }
59
- //# sourceMappingURL=create-intl.js.map
package/src/dateTime.js CHANGED
@@ -123,4 +123,3 @@ function formatTimeToParts(config, getDateTimeFormat) {
123
123
  }
124
124
  return [];
125
125
  }
126
- //# sourceMappingURL=dateTime.js.map
@@ -24,4 +24,3 @@ function formatDisplayName(_a, getDisplayNames, value, options) {
24
24
  onError(new error_1.IntlFormatError('Error formatting display name.', locale, e));
25
25
  }
26
26
  }
27
- //# sourceMappingURL=displayName.js.map
package/src/error.js CHANGED
@@ -92,4 +92,3 @@ var MissingTranslationError = /** @class */ (function (_super) {
92
92
  return MissingTranslationError;
93
93
  }(IntlError));
94
94
  exports.MissingTranslationError = MissingTranslationError;
95
- //# sourceMappingURL=error.js.map
package/src/list.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Formatters, IntlFormatters, OnErrorFn } from './types';
2
- import type { Part } from '@formatjs/intl-listformat';
1
+ import { Formatters, IntlFormatters, OnErrorFn, Part } from './types';
3
2
  export declare function formatList(opts: {
4
3
  locale: string;
5
4
  onError: OnErrorFn;
package/src/list.js CHANGED
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatList = formatList;
4
4
  exports.formatListToParts = formatListToParts;
5
5
  var tslib_1 = require("tslib");
6
- var utils_1 = require("./utils");
7
6
  var intl_messageformat_1 = require("intl-messageformat");
8
7
  var error_1 = require("./error");
8
+ var utils_1 = require("./utils");
9
9
  var LIST_FORMAT_OPTIONS = [
10
10
  'type',
11
11
  'style',
@@ -52,9 +52,9 @@ function formatListToParts(_a, getListFormat, values, options) {
52
52
  return getListFormat(locale, filteredOptions)
53
53
  .formatToParts(serializedValues)
54
54
  .map(function (part) {
55
- return part.type === 'literal'
55
+ return (part.type === 'literal'
56
56
  ? part
57
- : tslib_1.__assign(tslib_1.__assign({}, part), { value: richValues_1[part.value] || part.value });
57
+ : tslib_1.__assign(tslib_1.__assign({}, part), { value: richValues_1[part.value] || part.value }));
58
58
  });
59
59
  }
60
60
  catch (e) {
@@ -63,4 +63,3 @@ function formatListToParts(_a, getListFormat, values, options) {
63
63
  // @ts-ignore
64
64
  return values;
65
65
  }
66
- //# sourceMappingURL=list.js.map
package/src/message.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Formatters, MessageDescriptor, CustomFormats, OnErrorFn } from './types';
2
- import { FormatXMLElementFn, PrimitiveType, Formatters as IntlMessageFormatFormatters, Options } from 'intl-messageformat';
1
+ import { CustomFormats, Formatters, MessageDescriptor, OnErrorFn } from './types';
3
2
  import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
3
+ import { FormatXMLElementFn, Formatters as IntlMessageFormatFormatters, Options, PrimitiveType } from 'intl-messageformat';
4
4
  export type FormatMessageFn<T> = ({ locale, formats, messages, defaultLocale, defaultFormats, fallbackOnEmptyString, onError, timeZone, defaultRichTextElements, }: {
5
5
  locale: string;
6
6
  timeZone?: string;
package/src/message.js CHANGED
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatMessage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
6
+ var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
6
7
  var intl_messageformat_1 = require("intl-messageformat");
7
8
  var error_1 = require("./error");
8
- var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
9
9
  function setTimeZoneInOptions(opts, timeZone) {
10
10
  return Object.keys(opts).reduce(function (all, k) {
11
11
  all[k] = tslib_1.__assign({ timeZone: timeZone }, opts[k]);
@@ -31,7 +31,7 @@ var formatMessage = function (_a, state, messageDescriptor, values, opts) {
31
31
  if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; }
32
32
  var msgId = messageDescriptor.id, defaultMessage = messageDescriptor.defaultMessage;
33
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");
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.github.io/docs/tooling/babel-plugin)\nor [@formatjs/ts-transformer](https://formatjs.github.io/docs/tooling/ts-transformer) OR\n2. Configure your `eslint` config to include [eslint-plugin-formatjs](https://formatjs.github.io/docs/tooling/linter#enforce-id)\nto autofix this issue");
35
35
  var id = String(msgId);
36
36
  var message =
37
37
  // In case messages is Object.create(null)
@@ -105,4 +105,3 @@ var formatMessage = function (_a, state, messageDescriptor, values, opts) {
105
105
  return id;
106
106
  };
107
107
  exports.formatMessage = formatMessage;
108
- //# sourceMappingURL=message.js.map
package/src/number.js CHANGED
@@ -61,4 +61,3 @@ function formatNumberToParts(config, getNumberFormat, value, options) {
61
61
  }
62
62
  return [];
63
63
  }
64
- //# sourceMappingURL=number.js.map
package/src/plural.js CHANGED
@@ -20,4 +20,3 @@ function formatPlural(_a, getPluralRules, value, options) {
20
20
  }
21
21
  return 'other';
22
22
  }
23
- //# sourceMappingURL=plural.js.map
@@ -30,4 +30,3 @@ function formatRelativeTime(config, getRelativeTimeFormat, value, unit, options)
30
30
  }
31
31
  return String(value);
32
32
  }
33
- //# sourceMappingURL=relativeTime.js.map
package/src/types.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { DateTimeFormat, NumberFormatOptions } from '@formatjs/ecma402-abstract';
2
2
  import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
3
- import { DisplayNames, DisplayNamesOptions } from '@formatjs/intl-displaynames';
4
- import IntlListFormat, { IntlListFormatOptions, Part } from '@formatjs/intl-listformat';
5
3
  import { FormatError, Formats, FormatXMLElementFn, IntlMessageFormat, Options as IntlMessageFormatOptions, PrimitiveType } from 'intl-messageformat';
6
4
  import { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, UnsupportedFormatterError } from './error';
7
5
  import { DEFAULT_INTL_CONFIG } from './utils';
6
+ export interface Part<T = string> {
7
+ type: 'element' | 'literal';
8
+ value: T;
9
+ }
8
10
  declare global {
9
11
  namespace FormatjsIntl {
10
12
  interface Message {
@@ -50,8 +52,8 @@ export type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'
50
52
  export type FormatNumberOptions = Omit<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'>;
51
53
  export type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'time'>;
52
54
  export type FormatPluralOptions = Omit<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
53
- export type FormatListOptions = Omit<IntlListFormatOptions, 'localeMatcher'>;
54
- export type FormatDisplayNameOptions = Omit<DisplayNamesOptions, 'localeMatcher'>;
55
+ export type FormatListOptions = Omit<Intl.ListFormatOptions, 'localeMatcher'>;
56
+ export type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions, 'localeMatcher'>;
55
57
  /**
56
58
  * `TBase` is the type constraints of the rich text element in the formatted output.
57
59
  * For example, with React, `TBase` should be `React.ReactNode`.
@@ -73,7 +75,7 @@ export interface IntlFormatters<TBase = unknown> {
73
75
  formatList(this: void, values: ReadonlyArray<string>, opts?: FormatListOptions): string;
74
76
  formatList<T extends TBase>(this: void, values: ReadonlyArray<string | T>, opts?: FormatListOptions): T | string | (string | T)[];
75
77
  formatListToParts<T extends TBase>(this: void, values: ReadonlyArray<string | T>, opts?: FormatListOptions): Part[];
76
- formatDisplayName(this: void, value: Parameters<DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
78
+ formatDisplayName(this: void, value: Parameters<Intl.DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
77
79
  }
78
80
  export interface Formatters {
79
81
  getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): DateTimeFormat;
@@ -81,8 +83,8 @@ export interface Formatters {
81
83
  getMessageFormat(this: void, ...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
82
84
  getRelativeTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
83
85
  getPluralRules(this: void, ...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
84
- getListFormat(this: void, ...args: ConstructorParameters<typeof IntlListFormat>): IntlListFormat;
85
- getDisplayNames(this: void, ...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
86
+ getListFormat(this: void, ...args: ConstructorParameters<typeof Intl.ListFormat>): Intl.ListFormat;
87
+ getDisplayNames(this: void, ...args: ConstructorParameters<typeof Intl.DisplayNames>): Intl.DisplayNames;
86
88
  }
87
89
  export interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormatters<T> {
88
90
  formatters: Formatters;
@@ -93,8 +95,8 @@ export interface IntlCache {
93
95
  message: Record<string, IntlMessageFormat>;
94
96
  relativeTime: Record<string, Intl.RelativeTimeFormat>;
95
97
  pluralRules: Record<string, Intl.PluralRules>;
96
- list: Record<string, IntlListFormat>;
97
- displayNames: Record<string, DisplayNames>;
98
+ list: Record<string, Intl.ListFormat>;
99
+ displayNames: Record<string, Intl.DisplayNames>;
98
100
  }
99
101
  export interface MessageDescriptor {
100
102
  id?: MessageIds;
package/src/types.js CHANGED
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
package/src/utils.js CHANGED
@@ -167,4 +167,3 @@ function getNamedFormat(formats, type, name, onError) {
167
167
  }
168
168
  onError(new error_1.UnsupportedFormatterError("No ".concat(type, " format named: ").concat(name)));
169
169
  }
170
- //# sourceMappingURL=utils.js.map