UNPKG

2.36 kBTypeScriptView Raw
1export type Locale = string;
2
3export type Style = 'long' | 'short' | 'narrow';
4
5type Numeric = 'auto' | 'always';
6
7export type Unit = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
8
9// https://github.com/eemeli/make-plural/blob/master/packages/compiler/src/compile-range.js#L1
10export type Count = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
11
12export type CountLabels = {
13 [count in Count]?: string;
14}
15
16export interface PastAndFutureLabels {
17 past: string | CountLabels;
18 future: string | CountLabels;
19 previous?: string;
20 current?: string;
21 next?: string;
22}
23
24export type UnitLabels = string | CountLabels | PastAndFutureLabels
25
26export type Labels = {
27 // Won't compile:
28 // [unit in Unit]: UnitLabels;
29 year: UnitLabels;
30 quarter: UnitLabels;
31 month: UnitLabels;
32 week: UnitLabels;
33 day: UnitLabels;
34 hour: UnitLabels;
35 minute: UnitLabels;
36 second: UnitLabels;
37}
38
39export type LocaleData = {
40 locale: Locale;
41 long: Labels;
42 short: Labels;
43 narrow: Labels;
44}
45
46// 'best fit' locale matching is not supported.
47export type LocaleMatcher = 'lookup' | 'best fit';
48
49export class PluralRules {
50 constructor(locale: Locale | Locale[], options?: { type?: 'cardinal' });
51 select(number: number): Count;
52 static supportedLocalesOf(locale: Locale | Locale[]): Locale[];
53}
54
55interface LiteralPart {
56 type: 'literal';
57 value: string;
58}
59
60interface IntegerPart {
61 type: 'integer';
62 value: string;
63 unit: Unit;
64}
65
66export type Part = LiteralPart | IntegerPart;
67
68// `new Intl.NumberFormat().resolvedOptions().numberingSystem`.
69// Example: 'latn'.
70type NumberingSystem = string;
71
72export default class RelativeTimeFormat {
73 constructor(locale: Locale | Locale[], options?: { style?: Style, numeric?: Numeric, localeMatcher?: LocaleMatcher });
74
75 format(number: number, unit: Unit): string;
76 formatToParts(number: number, unit: Unit): Part[];
77 resolvedOptions(): { locale: Locale, style: Style, numeric: Numeric, numberingSystem: NumberingSystem };
78
79 static addLocale(localeData: LocaleData): void;
80 static addDefaultLocale(localeData: LocaleData): void;
81 static setDefaultLocale(locale: Locale): void;
82
83 static PluralRules: PluralRules;
84 static supportedLocalesOf(locale: Locale | Locale[], options?: { localeMatcher?: LocaleMatcher }): Locale[];
85}
\No newline at end of file