@formatjs/intl 4.0.7 → 4.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/number.js CHANGED
@@ -1,58 +1,50 @@
1
- import { IntlFormatError } from './error.js';
2
- import { filterProps, getNamedFormat } from './utils.js';
3
- var NUMBER_FORMAT_OPTIONS = [
4
- 'style',
5
- 'currency',
6
- 'unit',
7
- 'unitDisplay',
8
- 'useGrouping',
9
- 'minimumIntegerDigits',
10
- 'minimumFractionDigits',
11
- 'maximumFractionDigits',
12
- 'minimumSignificantDigits',
13
- 'maximumSignificantDigits',
14
- // ES2020 NumberFormat
15
- 'compactDisplay',
16
- 'currencyDisplay',
17
- 'currencySign',
18
- 'notation',
19
- 'signDisplay',
20
- 'unit',
21
- 'unitDisplay',
22
- 'numberingSystem',
23
- // ES2023 NumberFormat
24
- 'trailingZeroDisplay',
25
- 'roundingPriority',
26
- 'roundingIncrement',
27
- 'roundingMode',
1
+ import "@formatjs/ecma402-abstract";
2
+ import { IntlFormatError } from "./error.js";
3
+ import "./types.js";
4
+ import { filterProps, getNamedFormat } from "./utils.js";
5
+ const NUMBER_FORMAT_OPTIONS = [
6
+ "style",
7
+ "currency",
8
+ "unit",
9
+ "unitDisplay",
10
+ "useGrouping",
11
+ "minimumIntegerDigits",
12
+ "minimumFractionDigits",
13
+ "maximumFractionDigits",
14
+ "minimumSignificantDigits",
15
+ "maximumSignificantDigits",
16
+ "compactDisplay",
17
+ "currencyDisplay",
18
+ "currencySign",
19
+ "notation",
20
+ "signDisplay",
21
+ "unit",
22
+ "unitDisplay",
23
+ "numberingSystem",
24
+ "trailingZeroDisplay",
25
+ "roundingPriority",
26
+ "roundingIncrement",
27
+ "roundingMode"
28
28
  ];
29
- export function getFormatter(_a, getNumberFormat, options) {
30
- var locale = _a.locale, formats = _a.formats, onError = _a.onError;
31
- if (options === void 0) { options = {}; }
32
- var format = options.format;
33
- var defaults = ((format &&
34
- getNamedFormat(formats, 'number', format, onError)) ||
35
- {});
36
- var filteredOptions = filterProps(options, NUMBER_FORMAT_OPTIONS, defaults);
37
- return getNumberFormat(locale, filteredOptions);
29
+ export function getFormatter({ locale, formats, onError }, getNumberFormat, options = {}) {
30
+ const { format } = options;
31
+ const defaults = format && getNamedFormat(formats, "number", format, onError) || {};
32
+ const filteredOptions = filterProps(options, NUMBER_FORMAT_OPTIONS, defaults);
33
+ return getNumberFormat(locale, filteredOptions);
38
34
  }
39
- export 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 IntlFormatError('Error formatting number.', config.locale, e));
46
- }
47
- return String(value);
35
+ export function formatNumber(config, getNumberFormat, value, options = {}) {
36
+ try {
37
+ return getFormatter(config, getNumberFormat, options).format(value);
38
+ } catch (e) {
39
+ config.onError(new IntlFormatError("Error formatting number.", config.locale, e));
40
+ }
41
+ return String(value);
48
42
  }
49
- export function formatNumberToParts(config, getNumberFormat, value, options) {
50
- if (options === void 0) { options = {}; }
51
- try {
52
- return getFormatter(config, getNumberFormat, options).formatToParts(value);
53
- }
54
- catch (e) {
55
- config.onError(new IntlFormatError('Error formatting number.', config.locale, e));
56
- }
57
- return [];
43
+ export function formatNumberToParts(config, getNumberFormat, value, options = {}) {
44
+ try {
45
+ return getFormatter(config, getNumberFormat, options).formatToParts(value);
46
+ } catch (e) {
47
+ config.onError(new IntlFormatError("Error formatting number.", config.locale, e));
48
+ }
49
+ return [];
58
50
  }
package/src/plural.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Formatters, IntlFormatters, OnErrorFn } from './types.js';
2
- export declare function formatPlural({ locale, onError, }: {
3
- locale: string;
4
- onError: OnErrorFn;
5
- }, getPluralRules: Formatters['getPluralRules'], value: Parameters<IntlFormatters['formatPlural']>[0], options?: Parameters<IntlFormatters['formatPlural']>[1]): Intl.LDMLPluralRule;
1
+ import { type Formatters, type IntlFormatters, type OnErrorFn } from "./types.js";
2
+ export declare function formatPlural({ locale, onError }: {
3
+ locale: string;
4
+ onError: OnErrorFn;
5
+ }, getPluralRules: Formatters["getPluralRules"], value: Parameters<IntlFormatters["formatPlural"]>[0], options?: Parameters<IntlFormatters["formatPlural"]>[1]): Intl.LDMLPluralRule;
package/src/plural.js CHANGED
@@ -1,19 +1,19 @@
1
- import { ErrorCode, FormatError } from 'intl-messageformat';
2
- import { IntlFormatError } from './error.js';
3
- import { filterProps } from './utils.js';
4
- var PLURAL_FORMAT_OPTIONS = ['type'];
5
- export function formatPlural(_a, getPluralRules, value, options) {
6
- var locale = _a.locale, onError = _a.onError;
7
- if (options === void 0) { options = {}; }
8
- if (!Intl.PluralRules) {
9
- onError(new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", ErrorCode.MISSING_INTL_API));
10
- }
11
- var filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);
12
- try {
13
- return getPluralRules(locale, filteredOptions).select(value);
14
- }
15
- catch (e) {
16
- onError(new IntlFormatError('Error formatting plural.', locale, e));
17
- }
18
- return 'other';
1
+ import { ErrorCode, FormatError } from "intl-messageformat";
2
+ import { IntlFormatError } from "./error.js";
3
+ import "./types.js";
4
+ import { filterProps } from "./utils.js";
5
+ const PLURAL_FORMAT_OPTIONS = ["type"];
6
+ export function formatPlural({ locale, onError }, getPluralRules, value, options = {}) {
7
+ if (!Intl.PluralRules) {
8
+ onError(new FormatError(`Intl.PluralRules is not available in this environment.
9
+ Try polyfilling it using "@formatjs/intl-pluralrules"
10
+ `, ErrorCode.MISSING_INTL_API));
11
+ }
12
+ const filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);
13
+ try {
14
+ return getPluralRules(locale, filteredOptions).select(value);
15
+ } catch (e) {
16
+ onError(new IntlFormatError("Error formatting plural.", locale, e));
17
+ }
18
+ return "other";
19
19
  }
@@ -1,6 +1,6 @@
1
- import { IntlFormatters, Formatters, CustomFormats, OnErrorFn } from './types.js';
1
+ import { type IntlFormatters, type Formatters, type CustomFormats, type OnErrorFn } from "./types.js";
2
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;
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;
@@ -1,29 +1,28 @@
1
- import { getNamedFormat, filterProps } from './utils.js';
2
- import { FormatError, ErrorCode } from 'intl-messageformat';
3
- import { IntlFormatError } from './error.js';
4
- var RELATIVE_TIME_FORMAT_OPTIONS = ['numeric', 'style'];
5
- function getFormatter(_a, getRelativeTimeFormat, options) {
6
- var locale = _a.locale, formats = _a.formats, onError = _a.onError;
7
- if (options === void 0) { options = {}; }
8
- var format = options.format;
9
- var defaults = (!!format && getNamedFormat(formats, 'relative', format, onError)) || {};
10
- var filteredOptions = filterProps(options, RELATIVE_TIME_FORMAT_OPTIONS, defaults);
11
- return getRelativeTimeFormat(locale, filteredOptions);
1
+ import "./types.js";
2
+ import { getNamedFormat, filterProps } from "./utils.js";
3
+ import { FormatError, ErrorCode } from "intl-messageformat";
4
+ import { IntlFormatError } from "./error.js";
5
+ const RELATIVE_TIME_FORMAT_OPTIONS = ["numeric", "style"];
6
+ function getFormatter({ locale, formats, onError }, getRelativeTimeFormat, options = {}) {
7
+ const { format } = options;
8
+ const defaults = !!format && getNamedFormat(formats, "relative", format, onError) || {};
9
+ const filteredOptions = filterProps(options, RELATIVE_TIME_FORMAT_OPTIONS, defaults);
10
+ return getRelativeTimeFormat(locale, filteredOptions);
12
11
  }
13
- export function formatRelativeTime(config, getRelativeTimeFormat, value, unit, options) {
14
- if (options === void 0) { options = {}; }
15
- if (!unit) {
16
- unit = 'second';
17
- }
18
- var RelativeTimeFormat = Intl.RelativeTimeFormat;
19
- if (!RelativeTimeFormat) {
20
- config.onError(new FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", ErrorCode.MISSING_INTL_API));
21
- }
22
- try {
23
- return getFormatter(config, getRelativeTimeFormat, options).format(value, unit);
24
- }
25
- catch (e) {
26
- config.onError(new IntlFormatError('Error formatting relative time.', config.locale, e));
27
- }
28
- return String(value);
12
+ export function formatRelativeTime(config, getRelativeTimeFormat, value, unit, options = {}) {
13
+ if (!unit) {
14
+ unit = "second";
15
+ }
16
+ const RelativeTimeFormat = Intl.RelativeTimeFormat;
17
+ if (!RelativeTimeFormat) {
18
+ config.onError(new FormatError(`Intl.RelativeTimeFormat is not available in this environment.
19
+ Try polyfilling it using "@formatjs/intl-relativetimeformat"
20
+ `, ErrorCode.MISSING_INTL_API));
21
+ }
22
+ try {
23
+ return getFormatter(config, getRelativeTimeFormat, options).format(value, unit);
24
+ } catch (e) {
25
+ config.onError(new IntlFormatError("Error formatting relative time.", config.locale, e));
26
+ }
27
+ return String(value);
29
28
  }
package/src/types.d.ts CHANGED
@@ -1,110 +1,114 @@
1
- import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
2
- import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
3
- import { FormatError, Formats, FormatXMLElementFn, IntlMessageFormat, Options as IntlMessageFormatOptions, PrimitiveType } from 'intl-messageformat';
4
- import { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, UnsupportedFormatterError } from './error.js';
5
- import { DEFAULT_INTL_CONFIG } from './utils.js';
1
+ import { type MessageFormatElement } from "@formatjs/icu-messageformat-parser";
2
+ import { type NumberFormatOptions } from "@formatjs/ecma402-abstract";
3
+ import type { FormatError, IntlMessageFormat } from "intl-messageformat";
4
+ import { type Formats, type FormatXMLElementFn, type Options as IntlMessageFormatOptions, type PrimitiveType } from "intl-messageformat";
5
+ import type { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, UnsupportedFormatterError } from "./error.js";
6
+ import type { DEFAULT_INTL_CONFIG } from "./utils.js";
6
7
  export interface Part<T = string> {
7
- type: 'element' | 'literal';
8
- value: T;
8
+ type: "element" | "literal";
9
+ value: T;
9
10
  }
11
+ // Note: FormatjsIntl is defined as a global namespace so the library user can
12
+ // override the default types of Message.ids (e.g. as string literal unions from extracted strings)
13
+ // or IntlConfig.locale (e.g. to a list of supported locales).
10
14
  declare global {
11
- namespace FormatjsIntl {
12
- interface Message {
13
- }
14
- interface IntlConfig {
15
- }
16
- interface Formats {
17
- }
18
- }
15
+ namespace FormatjsIntl {
16
+ interface Message {}
17
+ interface IntlConfig {}
18
+ interface Formats {}
19
+ }
19
20
  }
20
21
  type MessageIds = FormatjsIntl.Message extends {
21
- ids: infer T;
22
+ ids: infer T;
22
23
  } ? T extends string ? T : string : string;
23
24
  type Locale = FormatjsIntl.IntlConfig extends {
24
- locale: infer T;
25
+ locale: infer T;
25
26
  } ? T extends string ? T : string : string;
26
27
  export type OnErrorFn = (err: MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError) => void;
27
28
  export type OnWarnFn = (warning: string) => void;
28
29
  /**
29
- * Config for intl object.
30
- * Generic type T is the type of potential rich text element. For example:
31
- * With React, T would be React.ReactNode
32
- */
30
+ * Config for intl object.
31
+ * Generic type T is the type of potential rich text element. For example:
32
+ * With React, T would be React.ReactNode
33
+ */
33
34
  export interface ResolvedIntlConfig<T = string> {
34
- locale: Locale;
35
- timeZone?: string;
36
- fallbackOnEmptyString?: boolean;
37
- formats: CustomFormats;
38
- messages: Record<MessageIds, string> | Record<MessageIds, MessageFormatElement[]>;
39
- defaultLocale: string;
40
- defaultFormats: CustomFormats;
41
- defaultRichTextElements?: Record<string, FormatXMLElementFn<T>>;
42
- onError: OnErrorFn;
43
- onWarn?: OnWarnFn;
35
+ locale: Locale;
36
+ timeZone?: string;
37
+ fallbackOnEmptyString?: boolean;
38
+ formats: CustomFormats;
39
+ messages: Record<MessageIds, string> | Record<MessageIds, MessageFormatElement[]>;
40
+ defaultLocale: string;
41
+ defaultFormats: CustomFormats;
42
+ defaultRichTextElements?: Record<string, FormatXMLElementFn<T>>;
43
+ onError: OnErrorFn;
44
+ onWarn?: OnWarnFn;
44
45
  }
45
46
  export interface CustomFormats extends Partial<Formats> {
46
- relative?: Record<string, Intl.RelativeTimeFormatOptions>;
47
- dateTimeRange?: Record<string, Intl.DateTimeFormatOptions>;
47
+ relative?: Record<string, Intl.RelativeTimeFormatOptions>;
48
+ dateTimeRange?: Record<string, Intl.DateTimeFormatOptions>;
48
49
  }
49
50
  export interface CustomFormatConfig<Source = string> {
50
- format?: Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
51
+ format?: Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
51
52
  }
52
- export type FormatDateTimeRangeOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'dateTimeRange'>;
53
- export type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'date'>;
54
- export type FormatTimeOptions = Omit<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'time'>;
55
- export type FormatNumberOptions = Omit<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'>;
56
- export type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig<'time'>;
57
- export type FormatPluralOptions = Omit<Intl.PluralRulesOptions, 'localeMatcher'> & CustomFormatConfig;
58
- export type FormatListOptions = Omit<Intl.ListFormatOptions, 'localeMatcher'>;
59
- export type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions, 'localeMatcher'>;
53
+ export type FormatDateTimeRangeOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"dateTimeRange">;
54
+ export type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"date">;
55
+ export type FormatTimeOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"time">;
56
+ export type FormatNumberOptions = Omit<NumberFormatOptions, "localeMatcher"> & CustomFormatConfig<"number">;
57
+ export type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"time">;
58
+ export type FormatPluralOptions = Omit<Intl.PluralRulesOptions, "localeMatcher"> & CustomFormatConfig;
59
+ export type FormatListOptions = Omit<Intl.ListFormatOptions, "localeMatcher">;
60
+ export type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions, "localeMatcher">;
60
61
  /**
61
- * `TBase` is the type constraints of the rich text element in the formatted output.
62
- * For example, with React, `TBase` should be `React.ReactNode`.
63
- */
62
+ * `TBase` is the type constraints of the rich text element in the formatted output.
63
+ * For example, with React, `TBase` should be `React.ReactNode`.
64
+ */
64
65
  export interface IntlFormatters<TBase = unknown> {
65
- formatDateTimeRange(this: void, from: Parameters<Intl.DateTimeFormat['formatRange']>[0] | string, to: Parameters<Intl.DateTimeFormat['formatRange']>[1] | string, opts?: FormatDateTimeRangeOptions): string;
66
- formatDate(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
67
- formatTime(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatTimeOptions): string;
68
- formatDateToParts(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
69
- formatTimeToParts(this: void, value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
70
- formatRelativeTime(this: void, value: Parameters<Intl.RelativeTimeFormat['format']>[0], unit?: Parameters<Intl.RelativeTimeFormat['format']>[1], opts?: FormatRelativeTimeOptions): string;
71
- formatNumber(this: void, value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): string;
72
- formatNumberToParts(this: void, value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
73
- formatPlural(this: void, value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
74
- formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
75
- formatMessage<T extends TBase, TValue extends T | FormatXMLElementFn<T>>(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | TValue>, opts?: IntlMessageFormatOptions): string | T | Array<string | T>;
76
- $t(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
77
- $t<T extends TBase>(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: IntlMessageFormatOptions): string | T | (T | string)[];
78
- formatList(this: void, values: Iterable<string>, opts?: FormatListOptions): string;
79
- formatList<T extends TBase>(this: void, values: Iterable<string | T>, opts?: FormatListOptions): T | string | (string | T)[];
80
- formatListToParts<T extends TBase>(this: void, values: Iterable<string | T>, opts?: FormatListOptions): Part[];
81
- formatDisplayName(this: void, value: Parameters<Intl.DisplayNames['of']>[0], opts: FormatDisplayNameOptions): string | undefined;
66
+ formatDateTimeRange(this: void, from: Parameters<Intl.DateTimeFormat["formatRange"]>[0] | string, to: Parameters<Intl.DateTimeFormat["formatRange"]>[1] | string, opts?: FormatDateTimeRangeOptions): string;
67
+ formatDate(this: void, value: Parameters<Intl.DateTimeFormat["format"]>[0] | string, opts?: FormatDateOptions): string;
68
+ formatTime(this: void, value: Parameters<Intl.DateTimeFormat["format"]>[0] | string, opts?: FormatTimeOptions): string;
69
+ formatDateToParts(this: void, value: Parameters<Intl.DateTimeFormat["format"]>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
70
+ formatTimeToParts(this: void, value: Parameters<Intl.DateTimeFormat["format"]>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
71
+ formatRelativeTime(this: void, value: Parameters<Intl.RelativeTimeFormat["format"]>[0], unit?: Parameters<Intl.RelativeTimeFormat["format"]>[1], opts?: FormatRelativeTimeOptions): string;
72
+ formatNumber(this: void, value: Parameters<Intl.NumberFormat["format"]>[0], opts?: FormatNumberOptions): string;
73
+ formatNumberToParts(this: void, value: Parameters<Intl.NumberFormat["format"]>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
74
+ formatPlural(this: void, value: Parameters<Intl.PluralRules["select"]>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules["select"]>;
75
+ formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
76
+ formatMessage<
77
+ T extends TBase,
78
+ TValue extends T | FormatXMLElementFn<T>
79
+ >(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | TValue>, opts?: IntlMessageFormatOptions): string | T | Array<string | T>;
80
+ $t(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
81
+ $t<T extends TBase>(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: IntlMessageFormatOptions): string | T | (T | string)[];
82
+ formatList(this: void, values: Iterable<string>, opts?: FormatListOptions): string;
83
+ formatList<T extends TBase>(this: void, values: Iterable<string | T>, opts?: FormatListOptions): T | string | (string | T)[];
84
+ formatListToParts<T extends TBase>(this: void, values: Iterable<string | T>, opts?: FormatListOptions): Part[];
85
+ formatDisplayName(this: void, value: Parameters<Intl.DisplayNames["of"]>[0], opts: FormatDisplayNameOptions): string | undefined;
82
86
  }
83
87
  export interface Formatters {
84
- getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
85
- getNumberFormat(this: void, locales?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
86
- getMessageFormat(this: void, ...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
87
- getRelativeTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
88
- getPluralRules(this: void, ...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
89
- getListFormat(this: void, ...args: ConstructorParameters<typeof Intl.ListFormat>): Intl.ListFormat;
90
- getDisplayNames(this: void, ...args: ConstructorParameters<typeof Intl.DisplayNames>): Intl.DisplayNames;
88
+ getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
89
+ getNumberFormat(this: void, locales?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
90
+ getMessageFormat(this: void, ...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
91
+ getRelativeTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
92
+ getPluralRules(this: void, ...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
93
+ getListFormat(this: void, ...args: ConstructorParameters<typeof Intl.ListFormat>): Intl.ListFormat;
94
+ getDisplayNames(this: void, ...args: ConstructorParameters<typeof Intl.DisplayNames>): Intl.DisplayNames;
91
95
  }
92
96
  export interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormatters<T> {
93
- formatters: Formatters;
97
+ formatters: Formatters;
94
98
  }
95
99
  export interface IntlCache {
96
- dateTime: Record<string, Intl.DateTimeFormat>;
97
- number: Record<string, Intl.NumberFormat>;
98
- message: Record<string, IntlMessageFormat>;
99
- relativeTime: Record<string, Intl.RelativeTimeFormat>;
100
- pluralRules: Record<string, Intl.PluralRules>;
101
- list: Record<string, Intl.ListFormat>;
102
- displayNames: Record<string, Intl.DisplayNames>;
100
+ dateTime: Record<string, Intl.DateTimeFormat>;
101
+ number: Record<string, Intl.NumberFormat>;
102
+ message: Record<string, IntlMessageFormat>;
103
+ relativeTime: Record<string, Intl.RelativeTimeFormat>;
104
+ pluralRules: Record<string, Intl.PluralRules>;
105
+ list: Record<string, Intl.ListFormat>;
106
+ displayNames: Record<string, Intl.DisplayNames>;
103
107
  }
104
108
  export interface MessageDescriptor {
105
- id?: MessageIds;
106
- description?: string | object;
107
- defaultMessage?: string | MessageFormatElement[];
109
+ id?: MessageIds;
110
+ description?: string | object;
111
+ defaultMessage?: string | MessageFormatElement[];
108
112
  }
109
113
  export type IntlConfig<T = string> = Omit<ResolvedIntlConfig<T>, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
110
114
  export {};
package/src/types.js CHANGED
@@ -1 +1,3 @@
1
- export {};
1
+ import "@formatjs/icu-messageformat-parser";
2
+ import "@formatjs/ecma402-abstract";
3
+ import "intl-messageformat";
package/src/utils.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
2
- import { CustomFormats, Formatters, IntlCache, OnErrorFn, ResolvedIntlConfig } from './types.js';
1
+ import { type NumberFormatOptions } from "@formatjs/ecma402-abstract";
2
+ import { type CustomFormats, type Formatters, type IntlCache, type OnErrorFn, type ResolvedIntlConfig } from "./types.js";
3
3
  export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
4
- export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, allowlist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
5
- export declare const DEFAULT_INTL_CONFIG: Pick<ResolvedIntlConfig<any>, 'fallbackOnEmptyString' | 'formats' | 'messages' | 'timeZone' | 'defaultLocale' | 'defaultFormats' | 'onError' | 'onWarn'>;
4
+ export declare function filterProps<
5
+ T extends Record<string, any>,
6
+ K extends string
7
+ >(props: T, allowlist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
8
+ export declare const DEFAULT_INTL_CONFIG: Pick<ResolvedIntlConfig<any>, "fallbackOnEmptyString" | "formats" | "messages" | "timeZone" | "defaultLocale" | "defaultFormats" | "onError" | "onWarn">;
6
9
  export declare function createIntlCache(): IntlCache;
7
10
  /**
8
- * Create intl formatters and populate cache
9
- * @param cache explicit cache to prevent leaking memory
10
- */
11
+ * Create intl formatters and populate cache
12
+ * @param cache explicit cache to prevent leaking memory
13
+ */
11
14
  export declare function createFormatters(cache?: IntlCache): Formatters;
12
15
  export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.RelativeTimeFormatOptions | undefined;