-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.d.ts
85 lines (66 loc) · 2.22 KB
/
index.d.ts
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
export type Locale = string;
export type Style = 'long' | 'short' | 'narrow';
type Numeric = 'auto' | 'always';
export type Unit = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
// https://github.com/eemeli/make-plural/blob/master/packages/compiler/src/compile-range.js#L1
export type Count = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
export type CountLabels = {
[count in Count]?: string;
}
export interface PastAndFutureLabels {
past: string | CountLabels;
future: string | CountLabels;
previous?: string;
current?: string;
next?: string;
}
export type UnitLabels = string | CountLabels | PastAndFutureLabels
export type Labels = {
// Won't compile:
// [unit in Unit]: UnitLabels;
year: UnitLabels;
quarter: UnitLabels;
month: UnitLabels;
week: UnitLabels;
day: UnitLabels;
hour: UnitLabels;
minute: UnitLabels;
second: UnitLabels;
}
export type LocaleData = {
locale: Locale;
long: Labels;
short: Labels;
narrow: Labels;
}
// 'best fit' locale matching is not supported.
export type LocaleMatcher = 'lookup' | 'best fit';
export class PluralRules {
constructor(locale: Locale | Locale[], options?: { type?: 'cardinal' });
select(number: number): Count;
static supportedLocalesOf(locale: Locale | Locale[]): Locale[];
}
interface LiteralPart {
type: 'literal';
value: string;
}
interface IntegerPart {
type: 'integer';
value: string;
unit: Unit;
}
export type Part = LiteralPart | IntegerPart;
// `new Intl.NumberFormat().resolvedOptions().numberingSystem`.
// Example: 'latn'.
type NumberingSystem = string;
export default class RelativeTimeFormat {
constructor(locale: Locale | Locale[], options?: { style?: Style, numeric?: Numeric, localeMatcher?: LocaleMatcher });
format(number: number, unit: Unit): string;
formatToParts(number: number, unit: Unit): Part[];
resolvedOptions(): { locale: Locale, style: Style, numeric: Numeric, numberingSystem: NumberingSystem };
static addLocale(localeData: LocaleData): void;
static addDefaultLocale(localeData: LocaleData): void;
static setDefaultLocale(locale: Locale): void;
static PluralRules: PluralRules;
static supportedLocalesOf(locale: Locale | Locale[], options?: { localeMatcher?: LocaleMatcher }): Locale[];
}