1 | // https://github.com/microsoft/TypeScript/blob/master/lib/lib.es2020.intl.d.ts
|
2 |
|
3 | /*! *****************************************************************************
|
4 | Copyright (c) Microsoft Corporation. All rights reserved.
|
5 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
6 | this file except in compliance with the License. You may obtain a copy of the
|
7 | License at http://www.apache.org/licenses/LICENSE-2.0
|
8 |
|
9 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
10 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
11 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
12 | MERCHANTABLITY OR NON-INFRINGEMENT.
|
13 |
|
14 | See the Apache Version 2.0 License for specific language governing permissions
|
15 | and limitations under the License.
|
16 | ***************************************************************************** */
|
17 |
|
18 | declare namespace Intl {
|
19 | /**
|
20 | * [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) definition.
|
21 | *
|
22 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
|
23 | *
|
24 | * [Wikipedia](https://en.wikipedia.org/wiki/IETF_language_tag).
|
25 | */
|
26 | type BCP47LanguageTag = string;
|
27 |
|
28 | /**
|
29 | * Unit to use in the relative time internationalized message.
|
30 | *
|
31 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format#Parameters).
|
32 | *
|
33 | * [Specification](https://tc39.es/ecma402/#sec-singularrelativetimeunit).
|
34 | */
|
35 | type RelativeTimeFormatUnit =
|
36 | | 'year'
|
37 | | 'years'
|
38 | | 'quarter'
|
39 | | 'quarters'
|
40 | | 'month'
|
41 | | 'months'
|
42 | | 'week'
|
43 | | 'weeks'
|
44 | | 'day'
|
45 | | 'days'
|
46 | | 'hour'
|
47 | | 'hours'
|
48 | | 'minute'
|
49 | | 'minutes'
|
50 | | 'second'
|
51 | | 'seconds';
|
52 |
|
53 | /**
|
54 | * The locale matching algorithm to use.
|
55 | *
|
56 | * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
|
57 | *
|
58 | * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
|
59 | */
|
60 | type RelativeTimeFormatLocaleMatcher = 'lookup' | 'best fit';
|
61 |
|
62 | /**
|
63 | * The format of output message.
|
64 | *
|
65 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
|
66 | *
|
67 | * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
|
68 | */
|
69 | type RelativeTimeFormatNumeric = 'always' | 'auto';
|
70 |
|
71 | /**
|
72 | * The length of the internationalized message.
|
73 | *
|
74 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
|
75 | *
|
76 | * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
|
77 | */
|
78 | type RelativeTimeFormatStyle = 'long' | 'short' | 'narrow';
|
79 |
|
80 | /**
|
81 | * An object with some or all of properties of `options` parameter
|
82 | * of `Intl.RelativeTimeFormat` constructor.
|
83 | *
|
84 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
|
85 | *
|
86 | * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
|
87 | */
|
88 | interface RelativeTimeFormatOptions {
|
89 | localeMatcher?: RelativeTimeFormatLocaleMatcher;
|
90 | numeric?: RelativeTimeFormatNumeric;
|
91 | style?: RelativeTimeFormatStyle;
|
92 | }
|
93 |
|
94 | /**
|
95 | * An object with properties reflecting the locale
|
96 | * and formatting options computed during initialization
|
97 | * of the `Intel.RelativeTimeFormat` object
|
98 | *
|
99 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions#Description).
|
100 | *
|
101 | * [Specification](https://tc39.es/ecma402/#table-relativetimeformat-resolvedoptions-properties)
|
102 | */
|
103 | interface ResolvedRelativeTimeFormatOptions {
|
104 | locale: BCP47LanguageTag;
|
105 | style: RelativeTimeFormatStyle;
|
106 | numeric: RelativeTimeFormatNumeric;
|
107 | numberingSystem: string;
|
108 | }
|
109 |
|
110 | /**
|
111 | * An object representing the relative time format in parts
|
112 | * that can be used for custom locale-aware formatting.
|
113 | *
|
114 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts#Using_formatToParts).
|
115 | *
|
116 | * [Specification](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts).
|
117 | */
|
118 | interface RelativeTimeFormatPart {
|
119 | type: string;
|
120 | value: string;
|
121 | unit?: RelativeTimeFormatUnit;
|
122 | }
|
123 |
|
124 | interface RelativeTimeFormat {
|
125 | /**
|
126 | * Formats a value and a unit according to the locale
|
127 | * and formatting options of the given
|
128 | * [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
|
129 | * object.
|
130 | *
|
131 | * While this method automatically provides the correct plural forms,
|
132 | * the grammatical form is otherwise as neutral as possible.
|
133 | * It is the caller's responsibility to handle cut-off logic
|
134 | * such as deciding between displaying "in 7 days" or "in 1 week".
|
135 | * This API does not support relative dates involving compound units.
|
136 | * e.g "in 5 days and 4 hours".
|
137 | *
|
138 | * @param value - Numeric value to use in the internationalized relative time message
|
139 | *
|
140 | * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit)
|
141 | * to use in the relative time internationalized message.
|
142 | * Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`,
|
143 | * `"day"`, `"hour"`, `"minute"`, `"second"`.
|
144 | * Plural forms are also permitted.
|
145 | *
|
146 | * @throws `RangeError` if `unit` was given something other than `unit` possible values
|
147 | *
|
148 | * @returns Internationalized relative time message as string
|
149 | *
|
150 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format).
|
151 | *
|
152 | * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.format).
|
153 | */
|
154 | format(value: number, unit: RelativeTimeFormatUnit): string;
|
155 |
|
156 | /**
|
157 | * A version of the format method which it returns an array of objects
|
158 | * which represent "parts" of the object,
|
159 | * separating the formatted number into its constituent parts
|
160 | * and separating it from other surrounding text.
|
161 | * These objects have two properties:
|
162 | * `type` a NumberFormat formatToParts type, and `value`,
|
163 | * which is the String which is the component of the output.
|
164 | * If a "part" came from NumberFormat,
|
165 | * it will have a unit property which indicates the `unit` being formatted;
|
166 | * literals which are part of the larger frame will not have this property.
|
167 | *
|
168 | * @param value - Numeric value to use in the internationalized relative time message
|
169 | *
|
170 | * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit)
|
171 | * to use in the relative time internationalized message.
|
172 | * Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`,
|
173 | * `"day"`, `"hour"`, `"minute"`, `"second"`.
|
174 | * Plural forms are also permitted.
|
175 | *
|
176 | * @throws `RangeError` if `unit` was given something other than `unit` possible values
|
177 | *
|
178 | * @returns Array of [FormatRelativeTimeToParts](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts)
|
179 | *
|
180 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts).
|
181 | *
|
182 | * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.formatToParts).
|
183 | */
|
184 | formatToParts(value: number, unit: RelativeTimeFormatUnit): RelativeTimeFormatPart[];
|
185 |
|
186 | /**
|
187 | * Provides access to the locale and options computed during initialization of this `Intl.RelativeTimeFormat` object.
|
188 | *
|
189 | * @returns A new object with properties reflecting the locale
|
190 | * and formatting options computed during initialization
|
191 | * of the `Intel.RelativeTimeFormat` object.
|
192 | *
|
193 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions).
|
194 | *
|
195 | * [Specification](https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions)
|
196 | */
|
197 | resolvedOptions(): ResolvedRelativeTimeFormatOptions;
|
198 | }
|
199 |
|
200 | /**
|
201 | * The [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
|
202 | * object is a constructor for objects that enable language-sensitive relative time formatting.
|
203 | *
|
204 | * Part of [Intl object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl)
|
205 | * namespace and the [ECMAScript Internationalization API](https://www.ecma-international.org/publications/standards/Ecma-402.htm).
|
206 | *
|
207 | * [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#Browser_compatibility).
|
208 | *
|
209 | * [Polyfills](https://github.com/tc39/proposal-intl-relative-time#polyfills).
|
210 | */
|
211 | const RelativeTimeFormat: {
|
212 | /**
|
213 | * Constructor creates [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
|
214 | * objects
|
215 | *
|
216 | * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
|
217 | * For the general form and interpretation of the locales argument,
|
218 | * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
219 | *
|
220 | * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
|
221 | * with some or all of options of the formatting.
|
222 | * An object with some or all of the following properties:
|
223 | * - `localeMatcher` - The locale matching algorithm to use.
|
224 | * Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`.
|
225 | * For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
|
226 | * - `numeric` - The format of output message.
|
227 | * Possible values are: `"always"` (default, e.g., `1 day ago`) or `"auto"` (e.g., `yesterday`).
|
228 | * The `"auto"` value allows to not always have to use numeric values in the output.
|
229 | * - `style` - The length of the internationalized message. Possible values are:
|
230 | * `"long"` (default, e.g., in 1 month),
|
231 | * `"short"` (e.g., in 1 mo.)
|
232 | * or `"narrow"` (e.g., in 1 mo.). The narrow style could be similar to the short style for some locales.
|
233 | *
|
234 | * @returns [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) object.
|
235 | *
|
236 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
|
237 | *
|
238 | * [Specification](https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor).
|
239 | */
|
240 | new (locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: RelativeTimeFormatOptions): RelativeTimeFormat;
|
241 |
|
242 | /**
|
243 | * Returns an array containing those of the provided locales
|
244 | * that are supported in date and time formatting
|
245 | * without having to fall back to the runtime's default locale.
|
246 | *
|
247 | * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
|
248 | * For the general form and interpretation of the locales argument,
|
249 | * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
250 | *
|
251 | * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
|
252 | * with some or all of options of the formatting.
|
253 | * An object with some or all of the following properties:
|
254 | * - `localeMatcher` - The locale matching algorithm to use.
|
255 | * Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`.
|
256 | * For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
|
257 | * - `numeric` - The format of output message.
|
258 | * Possible values are: `"always"` (default, e.g., `1 day ago`) or `"auto"` (e.g., `yesterday`).
|
259 | * The `"auto"` value allows to not always have to use numeric values in the output.
|
260 | * - `style` - The length of the internationalized message. Possible values are:
|
261 | * `"long"` (default, e.g., in 1 month),
|
262 | * `"short"` (e.g., in 1 mo.)
|
263 | * or `"narrow"` (e.g., in 1 mo.). The narrow style could be similar to the short style for some locales.
|
264 | *
|
265 | * @returns An array containing those of the provided locales
|
266 | * that are supported in date and time formatting
|
267 | * without having to fall back to the runtime's default locale.
|
268 | *
|
269 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/supportedLocalesOf).
|
270 | *
|
271 | * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.supportedLocalesOf).
|
272 | */
|
273 | supportedLocalesOf(
|
274 | locales: BCP47LanguageTag | BCP47LanguageTag[],
|
275 | options?: RelativeTimeFormatOptions
|
276 | ): BCP47LanguageTag[];
|
277 | };
|
278 |
|
279 | interface NumberFormatOptions {
|
280 | notation?: string;
|
281 | unit?: string;
|
282 | unitDisplay?: string;
|
283 | }
|
284 |
|
285 | interface ResolvedNumberFormatOptions {
|
286 | notation?: string;
|
287 | unit?: string;
|
288 | unitDisplay?: string;
|
289 | }
|
290 | }
|