@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/index.d.ts +19 -15
- package/index.js +14 -13
- package/package.json +5 -5
- package/src/create-intl.d.ts +11 -7
- package/src/create-intl.js +62 -44
- package/src/dateTime.d.ts +32 -32
- package/src/dateTime.js +79 -110
- package/src/displayName.d.ts +5 -5
- package/src/displayName.js +22 -21
- package/src/error.d.ts +19 -19
- package/src/error.js +68 -91
- package/src/list.d.ts +7 -7
- package/src/list.js +47 -57
- package/src/message.d.ts +14 -14
- package/src/message.js +103 -96
- package/src/number.d.ts +14 -14
- package/src/number.js +46 -54
- package/src/plural.d.ts +5 -5
- package/src/plural.js +18 -18
- package/src/relativeTime.d.ts +5 -5
- package/src/relativeTime.js +26 -27
- package/src/types.d.ts +84 -80
- package/src/types.js +3 -1
- package/src/utils.d.ts +10 -7
- package/src/utils.js +112 -155
package/src/number.js
CHANGED
|
@@ -1,58 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
2
|
-
export declare function formatPlural({ locale, onError
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}, getPluralRules: Formatters[
|
|
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
|
|
2
|
-
import { IntlFormatError } from
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
}
|
package/src/relativeTime.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IntlFormatters, Formatters, CustomFormats, OnErrorFn } from
|
|
1
|
+
import { type IntlFormatters, type Formatters, type CustomFormats, type OnErrorFn } from "./types.js";
|
|
2
2
|
export declare function formatRelativeTime(config: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}, getRelativeTimeFormat: Formatters[
|
|
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;
|
package/src/relativeTime.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
2
|
-
import { NumberFormatOptions } from
|
|
3
|
-
import { FormatError,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
22
|
+
ids: infer T;
|
|
22
23
|
} ? T extends string ? T : string : string;
|
|
23
24
|
type Locale = FormatjsIntl.IntlConfig extends {
|
|
24
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
47
|
+
relative?: Record<string, Intl.RelativeTimeFormatOptions>;
|
|
48
|
+
dateTimeRange?: Record<string, Intl.DateTimeFormatOptions>;
|
|
48
49
|
}
|
|
49
50
|
export interface CustomFormatConfig<Source = string> {
|
|
50
|
-
|
|
51
|
+
format?: Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
|
|
51
52
|
}
|
|
52
|
-
export type FormatDateTimeRangeOptions = Omit<Intl.DateTimeFormatOptions,
|
|
53
|
-
export type FormatDateOptions = Omit<Intl.DateTimeFormatOptions,
|
|
54
|
-
export type FormatTimeOptions = Omit<Intl.DateTimeFormatOptions,
|
|
55
|
-
export type FormatNumberOptions = Omit<NumberFormatOptions,
|
|
56
|
-
export type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions,
|
|
57
|
-
export type FormatPluralOptions = Omit<Intl.PluralRulesOptions,
|
|
58
|
-
export type FormatListOptions = Omit<Intl.ListFormatOptions,
|
|
59
|
-
export type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions,
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
97
|
+
formatters: Formatters;
|
|
94
98
|
}
|
|
95
99
|
export interface IntlCache {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
package/src/utils.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { NumberFormatOptions } from
|
|
2
|
-
import { CustomFormats, Formatters, IntlCache, OnErrorFn, ResolvedIntlConfig } from
|
|
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<
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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;
|