• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1declare namespace Intl {
2
3    // http://cldr.unicode.org/index/cldr-spec/plural-rules#TOC-Determining-Plural-Categories
4    type LDMLPluralRule = "zero" | "one" | "two" | "few" | "many" | "other";
5    type PluralRuleType = "cardinal" | "ordinal";
6
7    interface PluralRulesOptions {
8        localeMatcher?: "lookup" | "best fit" | undefined;
9        type?: PluralRuleType | undefined;
10        minimumIntegerDigits?: number | undefined;
11        minimumFractionDigits?: number | undefined;
12        maximumFractionDigits?: number | undefined;
13        minimumSignificantDigits?: number | undefined;
14        maximumSignificantDigits?: number | undefined;
15    }
16
17    interface ResolvedPluralRulesOptions {
18        locale: string;
19        pluralCategories: LDMLPluralRule[];
20        type: PluralRuleType;
21        minimumIntegerDigits: number;
22        minimumFractionDigits: number;
23        maximumFractionDigits: number;
24        minimumSignificantDigits?: number;
25        maximumSignificantDigits?: number;
26    }
27
28    interface PluralRules {
29        resolvedOptions(): ResolvedPluralRulesOptions;
30        select(n: number): LDMLPluralRule;
31    }
32
33    const PluralRules: {
34        new (locales?: string | string[], options?: PluralRulesOptions): PluralRules;
35        (locales?: string | string[], options?: PluralRulesOptions): PluralRules;
36
37        supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit" }): string[];
38    };
39
40    // We can only have one definition for 'type' in TypeScript, and so you can learn where the keys come from here:
41    type ES2018NumberFormatPartType = "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name";
42    type ES2020NumberFormatPartType = "compact" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "unit" | "unknown";
43    type NumberFormatPartTypes = ES2018NumberFormatPartType | ES2020NumberFormatPartType;
44
45    interface NumberFormatPart {
46        type: NumberFormatPartTypes;
47        value: string;
48    }
49
50    interface NumberFormat {
51        formatToParts(number?: number | bigint): NumberFormatPart[];
52    }
53}
54