@formatjs/intl 4.1.18 → 4.1.20
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 +48 -48
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -44,54 +44,54 @@ type NumberFormatOptions = Omit<Intl.NumberFormatOptions, "signDisplay" | "useGr
|
|
|
44
44
|
};
|
|
45
45
|
//#endregion
|
|
46
46
|
//#region packages/intl/error.d.ts
|
|
47
|
-
declare enum IntlErrorCode {
|
|
47
|
+
export declare enum IntlErrorCode {
|
|
48
48
|
FORMAT_ERROR = "FORMAT_ERROR",
|
|
49
49
|
UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
|
|
50
50
|
INVALID_CONFIG = "INVALID_CONFIG",
|
|
51
51
|
MISSING_DATA = "MISSING_DATA",
|
|
52
52
|
MISSING_TRANSLATION = "MISSING_TRANSLATION"
|
|
53
53
|
}
|
|
54
|
-
declare class IntlError<T extends IntlErrorCode = IntlErrorCode.FORMAT_ERROR> extends Error {
|
|
54
|
+
export declare class IntlError<T extends IntlErrorCode = IntlErrorCode.FORMAT_ERROR> extends Error {
|
|
55
55
|
readonly code: T;
|
|
56
56
|
constructor(code: T, message: string, exception?: Error | unknown);
|
|
57
57
|
}
|
|
58
|
-
declare class UnsupportedFormatterError extends IntlError<IntlErrorCode.UNSUPPORTED_FORMATTER> {
|
|
58
|
+
export declare class UnsupportedFormatterError extends IntlError<IntlErrorCode.UNSUPPORTED_FORMATTER> {
|
|
59
59
|
constructor(message: string, exception?: Error | unknown);
|
|
60
60
|
}
|
|
61
|
-
declare class InvalidConfigError extends IntlError<IntlErrorCode.INVALID_CONFIG> {
|
|
61
|
+
export declare class InvalidConfigError extends IntlError<IntlErrorCode.INVALID_CONFIG> {
|
|
62
62
|
constructor(message: string, exception?: Error | unknown);
|
|
63
63
|
}
|
|
64
|
-
declare class MissingDataError extends IntlError<IntlErrorCode.MISSING_DATA> {
|
|
64
|
+
export declare class MissingDataError extends IntlError<IntlErrorCode.MISSING_DATA> {
|
|
65
65
|
constructor(message: string, exception?: Error | unknown);
|
|
66
66
|
}
|
|
67
|
-
declare class IntlFormatError extends IntlError<IntlErrorCode.FORMAT_ERROR> {
|
|
67
|
+
export declare class IntlFormatError extends IntlError<IntlErrorCode.FORMAT_ERROR> {
|
|
68
68
|
readonly descriptor?: MessageDescriptor;
|
|
69
69
|
readonly locale: string;
|
|
70
70
|
constructor(message: string, locale: string, exception?: Error | unknown);
|
|
71
71
|
}
|
|
72
|
-
declare class MessageFormatError extends IntlFormatError {
|
|
72
|
+
export declare class MessageFormatError extends IntlFormatError {
|
|
73
73
|
readonly descriptor?: MessageDescriptor;
|
|
74
74
|
readonly locale: string;
|
|
75
75
|
constructor(message: string, locale: string, descriptor?: MessageDescriptor, exception?: Error | unknown);
|
|
76
76
|
}
|
|
77
|
-
declare class MissingTranslationError extends IntlError<IntlErrorCode.MISSING_TRANSLATION> {
|
|
77
|
+
export declare class MissingTranslationError extends IntlError<IntlErrorCode.MISSING_TRANSLATION> {
|
|
78
78
|
readonly descriptor?: MessageDescriptor;
|
|
79
79
|
constructor(descriptor: MessageDescriptor, locale: string);
|
|
80
80
|
}
|
|
81
81
|
//#endregion
|
|
82
82
|
//#region packages/intl/utils.d.ts
|
|
83
|
-
declare function filterProps<T extends Record<string, any>, K extends string>(props: T, allowlist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
|
|
84
|
-
declare const DEFAULT_INTL_CONFIG: Pick<ResolvedIntlConfig<any>, "fallbackOnEmptyString" | "formats" | "messages" | "timeZone" | "defaultLocale" | "defaultFormats" | "onError" | "onWarn">;
|
|
85
|
-
declare function createIntlCache(): IntlCache;
|
|
83
|
+
export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, allowlist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
|
|
84
|
+
export declare const DEFAULT_INTL_CONFIG: Pick<ResolvedIntlConfig<any>, "fallbackOnEmptyString" | "formats" | "messages" | "timeZone" | "defaultLocale" | "defaultFormats" | "onError" | "onWarn">;
|
|
85
|
+
export declare function createIntlCache(): IntlCache;
|
|
86
86
|
/**
|
|
87
87
|
* Create intl formatters and populate cache
|
|
88
88
|
* @param cache explicit cache to prevent leaking memory
|
|
89
89
|
*/
|
|
90
|
-
declare function createFormatters(cache?: IntlCache): Formatters;
|
|
91
|
-
declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.RelativeTimeFormatOptions | undefined;
|
|
90
|
+
export declare function createFormatters(cache?: IntlCache): Formatters;
|
|
91
|
+
export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: OnErrorFn): NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.RelativeTimeFormatOptions | undefined;
|
|
92
92
|
//#endregion
|
|
93
93
|
//#region packages/intl/types.d.ts
|
|
94
|
-
interface Part<T = string> {
|
|
94
|
+
export interface Part<T = string> {
|
|
95
95
|
type: "element" | "literal";
|
|
96
96
|
value: T;
|
|
97
97
|
}
|
|
@@ -108,14 +108,14 @@ type MessageIds = FormatjsIntl.Message extends {
|
|
|
108
108
|
type Locale = FormatjsIntl.IntlConfig extends {
|
|
109
109
|
locale: infer T;
|
|
110
110
|
} ? T extends string ? T : string : string;
|
|
111
|
-
type OnErrorFn = (err: MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError) => void;
|
|
112
|
-
type OnWarnFn = (warning: string) => void;
|
|
111
|
+
export type OnErrorFn = (err: MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError) => void;
|
|
112
|
+
export type OnWarnFn = (warning: string) => void;
|
|
113
113
|
/**
|
|
114
114
|
* Config for intl object.
|
|
115
115
|
* Generic type T is the type of potential rich text element. For example:
|
|
116
116
|
* With React, T would be React.ReactNode
|
|
117
117
|
*/
|
|
118
|
-
interface ResolvedIntlConfig<T = string> {
|
|
118
|
+
export interface ResolvedIntlConfig<T = string> {
|
|
119
119
|
locale: Locale;
|
|
120
120
|
timeZone?: string;
|
|
121
121
|
fallbackOnEmptyString?: boolean;
|
|
@@ -127,26 +127,26 @@ interface ResolvedIntlConfig<T = string> {
|
|
|
127
127
|
onError: OnErrorFn;
|
|
128
128
|
onWarn?: OnWarnFn;
|
|
129
129
|
}
|
|
130
|
-
interface CustomFormats extends Partial<Formats> {
|
|
130
|
+
export interface CustomFormats extends Partial<Formats> {
|
|
131
131
|
relative?: Record<string, Intl.RelativeTimeFormatOptions>;
|
|
132
132
|
dateTimeRange?: Record<string, Intl.DateTimeFormatOptions>;
|
|
133
133
|
}
|
|
134
|
-
interface CustomFormatConfig<Source = string> {
|
|
134
|
+
export interface CustomFormatConfig<Source = string> {
|
|
135
135
|
format?: Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
|
|
136
136
|
}
|
|
137
|
-
type FormatDateTimeRangeOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"dateTimeRange">;
|
|
138
|
-
type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"date">;
|
|
139
|
-
type FormatTimeOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"time">;
|
|
140
|
-
type FormatNumberOptions = Omit<NumberFormatOptions, "localeMatcher"> & CustomFormatConfig<"number">;
|
|
141
|
-
type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"time">;
|
|
142
|
-
type FormatPluralOptions = Omit<Intl.PluralRulesOptions, "localeMatcher"> & CustomFormatConfig;
|
|
143
|
-
type FormatListOptions = Omit<Intl.ListFormatOptions, "localeMatcher">;
|
|
144
|
-
type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions, "localeMatcher">;
|
|
137
|
+
export type FormatDateTimeRangeOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"dateTimeRange">;
|
|
138
|
+
export type FormatDateOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"date">;
|
|
139
|
+
export type FormatTimeOptions = Omit<Intl.DateTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"time">;
|
|
140
|
+
export type FormatNumberOptions = Omit<NumberFormatOptions, "localeMatcher"> & CustomFormatConfig<"number">;
|
|
141
|
+
export type FormatRelativeTimeOptions = Omit<Intl.RelativeTimeFormatOptions, "localeMatcher"> & CustomFormatConfig<"time">;
|
|
142
|
+
export type FormatPluralOptions = Omit<Intl.PluralRulesOptions, "localeMatcher"> & CustomFormatConfig;
|
|
143
|
+
export type FormatListOptions = Omit<Intl.ListFormatOptions, "localeMatcher">;
|
|
144
|
+
export type FormatDisplayNameOptions = Omit<Intl.DisplayNamesOptions, "localeMatcher">;
|
|
145
145
|
/**
|
|
146
146
|
* `TBase` is the type constraints of the rich text element in the formatted output.
|
|
147
147
|
* For example, with React, `TBase` should be `React.ReactNode`.
|
|
148
148
|
*/
|
|
149
|
-
interface IntlFormatters<TBase = unknown> {
|
|
149
|
+
export interface IntlFormatters<TBase = unknown> {
|
|
150
150
|
formatDateTimeRange(this: void, from: Parameters<Intl.DateTimeFormat["formatRange"]>[0] | string, to: Parameters<Intl.DateTimeFormat["formatRange"]>[1] | string, opts?: FormatDateTimeRangeOptions): string;
|
|
151
151
|
formatDate(this: void, value: Parameters<Intl.DateTimeFormat["format"]>[0] | string, opts?: FormatDateOptions): string;
|
|
152
152
|
formatTime(this: void, value: Parameters<Intl.DateTimeFormat["format"]>[0] | string, opts?: FormatTimeOptions): string;
|
|
@@ -165,7 +165,7 @@ interface IntlFormatters<TBase = unknown> {
|
|
|
165
165
|
formatListToParts<T extends TBase>(this: void, values: Iterable<string | T>, opts?: FormatListOptions): Part[];
|
|
166
166
|
formatDisplayName(this: void, value: Parameters<Intl.DisplayNames["of"]>[0], opts: FormatDisplayNameOptions): string | undefined;
|
|
167
167
|
}
|
|
168
|
-
interface Formatters {
|
|
168
|
+
export interface Formatters {
|
|
169
169
|
getDateTimeFormat(this: void, ...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
|
|
170
170
|
getNumberFormat(this: void, locales?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
|
|
171
171
|
getMessageFormat(this: void, ...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
|
|
@@ -174,10 +174,10 @@ interface Formatters {
|
|
|
174
174
|
getListFormat(this: void, ...args: ConstructorParameters<typeof Intl.ListFormat>): Intl.ListFormat;
|
|
175
175
|
getDisplayNames(this: void, ...args: ConstructorParameters<typeof Intl.DisplayNames>): Intl.DisplayNames;
|
|
176
176
|
}
|
|
177
|
-
interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormatters<T> {
|
|
177
|
+
export interface IntlShape<T = string> extends ResolvedIntlConfig<T>, IntlFormatters<T> {
|
|
178
178
|
formatters: Formatters;
|
|
179
179
|
}
|
|
180
|
-
interface IntlCache {
|
|
180
|
+
export interface IntlCache {
|
|
181
181
|
dateTime: Record<string, Intl.DateTimeFormat>;
|
|
182
182
|
number: Record<string, Intl.NumberFormat>;
|
|
183
183
|
message: Record<string, IntlMessageFormat>;
|
|
@@ -186,12 +186,12 @@ interface IntlCache {
|
|
|
186
186
|
list: Record<string, Intl.ListFormat>;
|
|
187
187
|
displayNames: Record<string, Intl.DisplayNames>;
|
|
188
188
|
}
|
|
189
|
-
interface MessageDescriptor {
|
|
189
|
+
export interface MessageDescriptor {
|
|
190
190
|
id?: MessageIds;
|
|
191
191
|
description?: string | object;
|
|
192
192
|
defaultMessage?: string | MessageFormatElement[];
|
|
193
193
|
}
|
|
194
|
-
type IntlConfig<T = string> = Omit<ResolvedIntlConfig<T>, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
|
|
194
|
+
export type IntlConfig<T = string> = Omit<ResolvedIntlConfig<T>, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
|
|
195
195
|
//#endregion
|
|
196
196
|
//#region packages/intl/message.d.ts
|
|
197
197
|
type FormatMessageFn<T> = ({ locale, formats, messages, defaultLocale, defaultFormats, fallbackOnEmptyString, onError, timeZone, defaultRichTextElements }: {
|
|
@@ -205,28 +205,28 @@ type FormatMessageFn<T> = ({ locale, formats, messages, defaultLocale, defaultFo
|
|
|
205
205
|
fallbackOnEmptyString?: boolean;
|
|
206
206
|
onError: OnErrorFn;
|
|
207
207
|
}, state: Formatters$1 & Pick<Formatters, "getMessageFormat">, messageDescriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: Options) => T extends string ? string : Array<T | string> | string | T;
|
|
208
|
-
declare const formatMessage: FormatMessageFn<any>;
|
|
208
|
+
export declare const formatMessage: FormatMessageFn<any>;
|
|
209
209
|
//#endregion
|
|
210
210
|
//#region packages/intl/dateTime.d.ts
|
|
211
|
-
declare function formatDate(config: {
|
|
211
|
+
export declare function formatDate(config: {
|
|
212
212
|
locale: string;
|
|
213
213
|
timeZone?: string;
|
|
214
214
|
formats: CustomFormats;
|
|
215
215
|
onError: OnErrorFn;
|
|
216
216
|
}, getDateTimeFormat: Formatters["getDateTimeFormat"], value: Parameters<IntlFormatters["formatDate"]>[0], options?: Parameters<IntlFormatters["formatDate"]>[1]): string;
|
|
217
|
-
declare function formatTime(config: {
|
|
217
|
+
export declare function formatTime(config: {
|
|
218
218
|
locale: string;
|
|
219
219
|
timeZone?: string;
|
|
220
220
|
formats: CustomFormats;
|
|
221
221
|
onError: OnErrorFn;
|
|
222
222
|
}, getDateTimeFormat: Formatters["getDateTimeFormat"], value: Parameters<IntlFormatters["formatTime"]>[0], options?: Parameters<IntlFormatters["formatTime"]>[1]): string;
|
|
223
|
-
declare function formatDateToParts(config: {
|
|
223
|
+
export declare function formatDateToParts(config: {
|
|
224
224
|
locale: string;
|
|
225
225
|
timeZone?: string;
|
|
226
226
|
formats: CustomFormats;
|
|
227
227
|
onError: OnErrorFn;
|
|
228
228
|
}, getDateTimeFormat: Formatters["getDateTimeFormat"], value: Parameters<IntlFormatters["formatDate"]>[0], options?: Parameters<IntlFormatters["formatDate"]>[1]): Intl.DateTimeFormatPart[];
|
|
229
|
-
declare function formatTimeToParts(config: {
|
|
229
|
+
export declare function formatTimeToParts(config: {
|
|
230
230
|
locale: string;
|
|
231
231
|
timeZone?: string;
|
|
232
232
|
formats: CustomFormats;
|
|
@@ -234,37 +234,37 @@ declare function formatTimeToParts(config: {
|
|
|
234
234
|
}, getDateTimeFormat: Formatters["getDateTimeFormat"], value: Parameters<IntlFormatters["formatTimeToParts"]>[0], options?: Parameters<IntlFormatters["formatTimeToParts"]>[1]): Intl.DateTimeFormatPart[];
|
|
235
235
|
//#endregion
|
|
236
236
|
//#region packages/intl/displayName.d.ts
|
|
237
|
-
declare function formatDisplayName({ locale, onError }: {
|
|
237
|
+
export declare function formatDisplayName({ locale, onError }: {
|
|
238
238
|
locale: string;
|
|
239
239
|
onError: OnErrorFn;
|
|
240
240
|
}, getDisplayNames: Formatters["getDisplayNames"], value: Parameters<IntlFormatters["formatDisplayName"]>[0], options: Parameters<IntlFormatters["formatDisplayName"]>[1]): string | undefined;
|
|
241
241
|
//#endregion
|
|
242
242
|
//#region packages/intl/list.d.ts
|
|
243
|
-
declare function formatList(opts: {
|
|
243
|
+
export declare function formatList(opts: {
|
|
244
244
|
locale: string;
|
|
245
245
|
onError: OnErrorFn;
|
|
246
246
|
}, getListFormat: Formatters["getListFormat"], values: Iterable<string>, options: Parameters<IntlFormatters["formatList"]>[1]): string;
|
|
247
247
|
//#endregion
|
|
248
248
|
//#region packages/intl/plural.d.ts
|
|
249
|
-
declare function formatPlural({ locale, onError }: {
|
|
249
|
+
export declare function formatPlural({ locale, onError }: {
|
|
250
250
|
locale: string;
|
|
251
251
|
onError: OnErrorFn;
|
|
252
252
|
}, getPluralRules: Formatters["getPluralRules"], value: Parameters<IntlFormatters["formatPlural"]>[0], options?: Parameters<IntlFormatters["formatPlural"]>[1]): Intl.LDMLPluralRule;
|
|
253
253
|
//#endregion
|
|
254
254
|
//#region packages/intl/relativeTime.d.ts
|
|
255
|
-
declare function formatRelativeTime(config: {
|
|
255
|
+
export declare function formatRelativeTime(config: {
|
|
256
256
|
locale: string;
|
|
257
257
|
formats: CustomFormats;
|
|
258
258
|
onError: OnErrorFn;
|
|
259
259
|
}, getRelativeTimeFormat: Formatters["getRelativeTimeFormat"], value: Parameters<IntlFormatters["formatRelativeTime"]>[0], unit?: Parameters<IntlFormatters["formatRelativeTime"]>[1], options?: Parameters<IntlFormatters["formatRelativeTime"]>[2]): string;
|
|
260
260
|
//#endregion
|
|
261
261
|
//#region packages/intl/number.d.ts
|
|
262
|
-
declare function formatNumber(config: {
|
|
262
|
+
export declare function formatNumber(config: {
|
|
263
263
|
locale: string;
|
|
264
264
|
formats: CustomFormats;
|
|
265
265
|
onError: OnErrorFn;
|
|
266
266
|
}, getNumberFormat: Formatters["getNumberFormat"], value: Parameters<IntlFormatters["formatNumber"]>[0], options?: Parameters<IntlFormatters["formatNumber"]>[1]): string;
|
|
267
|
-
declare function formatNumberToParts(config: {
|
|
267
|
+
export declare function formatNumberToParts(config: {
|
|
268
268
|
locale: string;
|
|
269
269
|
formats: CustomFormats;
|
|
270
270
|
onError: OnErrorFn;
|
|
@@ -279,11 +279,11 @@ interface CreateIntlFn<T = string, C extends IntlConfig<T> = IntlConfig<T>, S ex
|
|
|
279
279
|
* @param config intl config
|
|
280
280
|
* @param cache cache for formatter instances to prevent memory leak
|
|
281
281
|
*/
|
|
282
|
-
declare function createIntl<T = string>(config: IntlConfig<T>, cache?: IntlCache): IntlShape<T>;
|
|
282
|
+
export declare function createIntl<T = string>(config: IntlConfig<T>, cache?: IntlCache): IntlShape<T>;
|
|
283
283
|
//#endregion
|
|
284
284
|
//#region packages/intl/index.d.ts
|
|
285
|
-
declare function defineMessages<K extends keyof any, T = MessageDescriptor, U extends Record<K, T> = Record<K, T>>(msgs: U): U;
|
|
286
|
-
declare function defineMessage<T>(msg: T): T;
|
|
285
|
+
export declare function defineMessages<K extends keyof any, T = MessageDescriptor, U extends Record<K, T> = Record<K, T>>(msgs: U): U;
|
|
286
|
+
export declare function defineMessage<T>(msg: T): T;
|
|
287
287
|
//#endregion
|
|
288
|
-
export {
|
|
288
|
+
export type { CreateIntlFn, FormatMessageFn };
|
|
289
289
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.20",
|
|
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
|
"format",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@formatjs/fast-memoize": "3.1.7",
|
|
34
|
-
"@formatjs/icu-messageformat-parser": "3.5.
|
|
35
|
-
"intl-messageformat": "11.2.
|
|
34
|
+
"@formatjs/icu-messageformat-parser": "3.5.17",
|
|
35
|
+
"intl-messageformat": "11.2.14"
|
|
36
36
|
}
|
|
37
37
|
}
|