UNPKG

3.13 kBTypeScriptView Raw
1/*! *****************************************************************************
2Copyright (c) Microsoft Corporation. All rights reserved.
3Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4this file except in compliance with the License. You may obtain a copy of the
5License at http://www.apache.org/licenses/LICENSE-2.0
6
7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10MERCHANTABLITY OR NON-INFRINGEMENT.
11
12See the Apache Version 2.0 License for specific language governing permissions
13and limitations under the License.
14***************************************************************************** */
15
16
17
18/// <reference no-default-lib="true"/>
19
20
21declare namespace Intl {
22
23 // http://cldr.unicode.org/index/cldr-spec/plural-rules#TOC-Determining-Plural-Categories
24 type LDMLPluralRule = "zero" | "one" | "two" | "few" | "many" | "other";
25 type PluralRuleType = "cardinal" | "ordinal";
26
27 interface PluralRulesOptions {
28 localeMatcher?: "lookup" | "best fit" | undefined;
29 type?: PluralRuleType | undefined;
30 minimumIntegerDigits?: number | undefined;
31 minimumFractionDigits?: number | undefined;
32 maximumFractionDigits?: number | undefined;
33 minimumSignificantDigits?: number | undefined;
34 maximumSignificantDigits?: number | undefined;
35 }
36
37 interface ResolvedPluralRulesOptions {
38 locale: string;
39 pluralCategories: LDMLPluralRule[];
40 type: PluralRuleType;
41 minimumIntegerDigits: number;
42 minimumFractionDigits: number;
43 maximumFractionDigits: number;
44 minimumSignificantDigits?: number;
45 maximumSignificantDigits?: number;
46 }
47
48 interface PluralRules {
49 resolvedOptions(): ResolvedPluralRulesOptions;
50 select(n: number): LDMLPluralRule;
51 }
52
53 const PluralRules: {
54 new (locales?: string | string[], options?: PluralRulesOptions): PluralRules;
55 (locales?: string | string[], options?: PluralRulesOptions): PluralRules;
56
57 supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit" }): string[];
58 };
59
60 // We can only have one definition for 'type' in TypeScript, and so you can learn where the keys come from here:
61 type ES2018NumberFormatPartType = "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name";
62 type ES2020NumberFormatPartType = "compact" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "unit" | "unknown";
63 type NumberFormatPartTypes = ES2018NumberFormatPartType | ES2020NumberFormatPartType;
64
65 interface NumberFormatPart {
66 type: NumberFormatPartTypes;
67 value: string;
68 }
69
70 interface NumberFormat {
71 formatToParts(number?: number | bigint): NumberFormatPart[];
72 }
73}