UNPKG

2.05 kBTypeScriptView Raw
1import { NumberFormatOptions } from '@formatjs/ecma402-abstract';
2import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
3declare global {
4 namespace FormatjsIntl {
5 interface Message {
6 }
7 interface IntlConfig {
8 }
9 interface Formats {
10 }
11 }
12}
13type Format<Source = string> = Source extends keyof FormatjsIntl.Formats ? FormatjsIntl.Formats[Source] : string;
14export interface Formats {
15 number: Record<Format<'number'>, NumberFormatOptions>;
16 date: Record<Format<'date'>, Intl.DateTimeFormatOptions>;
17 time: Record<Format<'time'>, Intl.DateTimeFormatOptions>;
18}
19export interface FormatterCache {
20 number: Record<string, NumberFormatOptions>;
21 dateTime: Record<string, Intl.DateTimeFormat>;
22 pluralRules: Record<string, Intl.PluralRules>;
23}
24export interface Formatters {
25 getNumberFormat(locals?: string | string[], opts?: NumberFormatOptions): Intl.NumberFormat;
26 getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
27 getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
28}
29export declare enum PART_TYPE {
30 literal = 0,
31 object = 1
32}
33export interface LiteralPart {
34 type: PART_TYPE.literal;
35 value: string;
36}
37export interface ObjectPart<T = any> {
38 type: PART_TYPE.object;
39 value: T;
40}
41export type MessageFormatPart<T> = LiteralPart | ObjectPart<T>;
42export type PrimitiveType = string | number | boolean | null | undefined | Date;
43export declare function isFormatXMLElementFn<T>(el: PrimitiveType | T | FormatXMLElementFn<T>): el is FormatXMLElementFn<T>;
44export declare function formatToParts<T>(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, currentPluralValue?: number, originalMessage?: string): MessageFormatPart<T>[];
45export type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (parts: Array<string | T>) => R;
46export {};