1 /*! *****************************************************************************
2 Copyright (c) Microsoft Corporation. All rights reserved.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the
5 License at http://www.apache.org/licenses/LICENSE-2.0
7 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 MERCHANTABLITY OR NON-INFRINGEMENT.
12 See the Apache Version 2.0 License for specific language governing permissions
13 and limitations under the License.
14 ***************************************************************************** */
18 /// <reference no-default-lib="true"/>
\r
21 declare namespace Intl {
\r
24 * [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) definition.
\r
26 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
\r
28 * [Wikipedia](https://en.wikipedia.org/wiki/IETF_language_tag).
\r
30 type BCP47LanguageTag = string;
\r
33 * Unit to use in the relative time internationalized message.
\r
35 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format#Parameters).
\r
37 * [Specification](https://tc39.es/ecma402/#sec-singularrelativetimeunit).
\r
39 type RelativeTimeFormatUnit =
\r
41 | "quarter" | "quarters"
\r
42 | "month" | "months"
\r
46 | "minute" | "minutes"
\r
47 | "second" | "seconds"
\r
51 * The locale matching algorithm to use.
\r
53 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
\r
55 * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
\r
57 type RelativeTimeFormatLocaleMatcher = "lookup" | "best fit";
\r
60 * The format of output message.
\r
62 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
\r
64 * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
\r
66 type RelativeTimeFormatNumeric = "always" | "auto";
\r
69 * The length of the internationalized message.
\r
71 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
\r
73 * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
\r
75 type RelativeTimeFormatStyle = "long" | "short" | "narrow";
\r
78 * An object with some or all of properties of `options` parameter
\r
79 * of `Intl.RelativeTimeFormat` constructor.
\r
81 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
\r
83 * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
\r
85 interface RelativeTimeFormatOptions {
\r
86 localeMatcher?: RelativeTimeFormatLocaleMatcher;
\r
87 numeric?: RelativeTimeFormatNumeric;
\r
88 style?: RelativeTimeFormatStyle;
\r
92 * An object with properties reflecting the locale
\r
93 * and formatting options computed during initialization
\r
94 * of the `Intel.RelativeTimeFormat` object
\r
96 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions#Description).
\r
98 * [Specification](https://tc39.es/ecma402/#table-relativetimeformat-resolvedoptions-properties)
\r
100 interface ResolvedRelativeTimeFormatOptions {
\r
101 locale: BCP47LanguageTag;
\r
102 style: RelativeTimeFormatStyle;
\r
103 numeric: RelativeTimeFormatNumeric;
\r
104 numberingSystem: string;
\r
108 * An object representing the relative time format in parts
\r
109 * that can be used for custom locale-aware formatting.
\r
111 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts#Using_formatToParts).
\r
113 * [Specification](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts).
\r
115 interface RelativeTimeFormatPart {
\r
118 unit?: RelativeTimeFormatUnit;
\r
121 interface RelativeTimeFormat {
\r
123 * Formats a value and a unit according to the locale
\r
124 * and formatting options of the given
\r
125 * [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
\r
128 * While this method automatically provides the correct plural forms,
\r
129 * the grammatical form is otherwise as neutral as possible.
\r
130 * It is the caller's responsibility to handle cut-off logic
\r
131 * such as deciding between displaying "in 7 days" or "in 1 week".
\r
132 * This API does not support relative dates involving compound units.
\r
133 * e.g "in 5 days and 4 hours".
\r
135 * @param value - Numeric value to use in the internationalized relative time message
\r
137 * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit)
\r
138 * to use in the relative time internationalized message.
\r
139 * Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`,
\r
140 * `"day"`, `"hour"`, `"minute"`, `"second"`.
\r
141 * Plural forms are also permitted.
\r
143 * @throws `RangeError` if `unit` was given something other than `unit` possible values
\r
145 * @returns Internationalized relative time message as string
\r
147 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format).
\r
149 * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.format).
\r
153 unit: RelativeTimeFormatUnit,
\r
157 * A version of the format method which it returns an array of objects
\r
158 * which represent "parts" of the object,
\r
159 * separating the formatted number into its constituent parts
\r
160 * and separating it from other surrounding text.
\r
161 * These objects have two properties:
\r
162 * `type` a NumberFormat formatToParts type, and `value`,
\r
163 * which is the String which is the component of the output.
\r
164 * If a "part" came from NumberFormat,
\r
165 * it will have a unit property which indicates the `unit` being formatted;
\r
166 * literals which are part of the larger frame will not have this property.
\r
168 * @param value - Numeric value to use in the internationalized relative time message
\r
170 * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit)
\r
171 * to use in the relative time internationalized message.
\r
172 * Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`,
\r
173 * `"day"`, `"hour"`, `"minute"`, `"second"`.
\r
174 * Plural forms are also permitted.
\r
176 * @throws `RangeError` if `unit` was given something other than `unit` possible values
\r
178 * @returns Array of [FormatRelativeTimeToParts](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts)
\r
180 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts).
\r
182 * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.formatToParts).
\r
186 unit: RelativeTimeFormatUnit,
\r
187 ): RelativeTimeFormatPart[];
\r
190 * Provides access to the locale and options computed during initialization of this `Intl.RelativeTimeFormat` object.
\r
192 * @returns A new object with properties reflecting the locale
\r
193 * and formatting options computed during initialization
\r
194 * of the `Intel.RelativeTimeFormat` object.
\r
196 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions).
\r
198 * [Specification](https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions)
\r
200 resolvedOptions(): ResolvedRelativeTimeFormatOptions;
\r
204 * The [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
\r
205 * object is a constructor for objects that enable language-sensitive relative time formatting.
\r
207 * Part of [Intl object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl)
\r
208 * namespace and the [ECMAScript Internationalization API](https://www.ecma-international.org/publications/standards/Ecma-402.htm).
\r
210 * [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#Browser_compatibility).
\r
212 * [Polyfills](https://github.com/tc39/proposal-intl-relative-time#polyfills).
\r
214 const RelativeTimeFormat: {
\r
216 * Constructor creates [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
\r
219 * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
\r
220 * For the general form and interpretation of the locales argument,
\r
221 * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
\r
223 * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
\r
224 * with some or all of options of the formatting.
\r
225 * An object with some or all of the following properties:
\r
226 * - `localeMatcher` - The locale matching algorithm to use.
\r
227 * Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`.
\r
228 * For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
\r
229 * - `numeric` - The format of output message.
\r
230 * Possible values are: `"always"` (default, e.g., `1 day ago`) or `"auto"` (e.g., `yesterday`).
\r
231 * The `"auto"` value allows to not always have to use numeric values in the output.
\r
232 * - `style` - The length of the internationalized message. Possible values are:
\r
233 * `"long"` (default, e.g., in 1 month),
\r
234 * `"short"` (e.g., in 1 mo.)
\r
235 * or `"narrow"` (e.g., in 1 mo.). The narrow style could be similar to the short style for some locales.
\r
237 * @returns [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) object.
\r
239 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
\r
241 * [Specification](https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor).
\r
244 locales?: BCP47LanguageTag | BCP47LanguageTag[],
\r
245 options?: RelativeTimeFormatOptions,
\r
246 ): RelativeTimeFormat;
\r
249 * Returns an array containing those of the provided locales
\r
250 * that are supported in date and time formatting
\r
251 * without having to fall back to the runtime's default locale.
\r
253 * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
\r
254 * For the general form and interpretation of the locales argument,
\r
255 * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
\r
257 * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
\r
258 * with some or all of options of the formatting.
\r
259 * An object with some or all of the following properties:
\r
260 * - `localeMatcher` - The locale matching algorithm to use.
\r
261 * Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`.
\r
262 * For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
\r
263 * - `numeric` - The format of output message.
\r
264 * Possible values are: `"always"` (default, e.g., `1 day ago`) or `"auto"` (e.g., `yesterday`).
\r
265 * The `"auto"` value allows to not always have to use numeric values in the output.
\r
266 * - `style` - The length of the internationalized message. Possible values are:
\r
267 * `"long"` (default, e.g., in 1 month),
\r
268 * `"short"` (e.g., in 1 mo.)
\r
269 * or `"narrow"` (e.g., in 1 mo.). The narrow style could be similar to the short style for some locales.
\r
271 * @returns An array containing those of the provided locales
\r
272 * that are supported in date and time formatting
\r
273 * without having to fall back to the runtime's default locale.
\r
275 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/supportedLocalesOf).
\r
277 * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.supportedLocalesOf).
\r
279 supportedLocalesOf(
\r
280 locales: BCP47LanguageTag | BCP47LanguageTag[],
\r
281 options?: RelativeTimeFormatOptions,
\r
282 ): BCP47LanguageTag[];
\r
285 interface NumberFormatOptions {
\r
286 compactDisplay?: string;
\r
288 signDisplay?: string;
\r
290 unitDisplay?: string;
\r
293 interface ResolvedNumberFormatOptions {
\r
294 compactDisplay?: string;
\r
296 signDisplay?: string;
\r
298 unitDisplay?: string;
\r