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 * [Unicode BCP 47 Locale Identifiers](https://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) definition.
\r
26 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
\r
28 type UnicodeBCP47LocaleIdentifier = string;
\r
31 * Unit to use in the relative time internationalized message.
\r
33 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format#Parameters).
\r
35 type RelativeTimeFormatUnit =
\r
54 * The locale matching algorithm to use.
\r
56 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
\r
58 type RelativeTimeFormatLocaleMatcher = "lookup" | "best fit";
\r
61 * The format of output message.
\r
63 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
\r
65 type RelativeTimeFormatNumeric = "always" | "auto";
\r
68 * The length of the internationalized message.
\r
70 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
\r
72 type RelativeTimeFormatStyle = "long" | "short" | "narrow";
\r
75 * [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) definition.
\r
77 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
\r
79 type BCP47LanguageTag = string;
\r
82 * An object with some or all of properties of `options` parameter
\r
83 * of `Intl.RelativeTimeFormat` constructor.
\r
85 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
\r
87 interface RelativeTimeFormatOptions {
\r
88 /** The locale matching algorithm to use. For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). */
\r
89 localeMatcher?: RelativeTimeFormatLocaleMatcher;
\r
90 /** The format of output message. */
\r
91 numeric?: RelativeTimeFormatNumeric;
\r
92 /** The length of the internationalized message. */
\r
93 style?: RelativeTimeFormatStyle;
\r
97 * An object with properties reflecting the locale
\r
98 * and formatting options computed during initialization
\r
99 * of the `Intl.RelativeTimeFormat` object
\r
101 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions#Description).
\r
103 interface ResolvedRelativeTimeFormatOptions {
\r
104 locale: UnicodeBCP47LocaleIdentifier;
\r
105 style: RelativeTimeFormatStyle;
\r
106 numeric: RelativeTimeFormatNumeric;
\r
107 numberingSystem: string;
\r
111 * An object representing the relative time format in parts
\r
112 * that can be used for custom locale-aware formatting.
\r
114 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts#Using_formatToParts).
\r
116 interface RelativeTimeFormatPart {
\r
119 unit?: RelativeTimeFormatUnit;
\r
122 interface RelativeTimeFormat {
\r
124 * Formats a value and a unit according to the locale
\r
125 * and formatting options of the given
\r
126 * [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
\r
129 * While this method automatically provides the correct plural forms,
\r
130 * the grammatical form is otherwise as neutral as possible.
\r
132 * It is the caller's responsibility to handle cut-off logic
\r
133 * such as deciding between displaying "in 7 days" or "in 1 week".
\r
134 * This API does not support relative dates involving compound units.
\r
135 * e.g "in 5 days and 4 hours".
\r
137 * @param value - Numeric value to use in the internationalized relative time message
\r
139 * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit) to use in the relative time internationalized message.
\r
141 * @throws `RangeError` if `unit` was given something other than `unit` possible values
\r
143 * @returns {string} Internationalized relative time message as string
\r
145 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format).
\r
147 format(value: number, unit: RelativeTimeFormatUnit): string;
\r
150 * Returns an array of objects representing the relative time format in parts that can be used for custom locale-aware formatting.
\r
152 * @param value - Numeric value to use in the internationalized relative time message
\r
154 * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit) to use in the relative time internationalized message.
\r
156 * @throws `RangeError` if `unit` was given something other than `unit` possible values
\r
158 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts).
\r
160 formatToParts(value: number, unit: RelativeTimeFormatUnit): RelativeTimeFormatPart[];
\r
163 * Provides access to the locale and options computed during initialization of this `Intl.RelativeTimeFormat` object.
\r
165 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions).
\r
167 resolvedOptions(): ResolvedRelativeTimeFormatOptions;
\r
171 * The [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
\r
172 * object is a constructor for objects that enable language-sensitive relative time formatting.
\r
174 * [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#Browser_compatibility).
\r
176 const RelativeTimeFormat: {
\r
178 * Creates [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) objects
\r
180 * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
\r
181 * For the general form and interpretation of the locales argument,
\r
182 * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
\r
184 * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
\r
185 * with some or all of options of `RelativeTimeFormatOptions`.
\r
187 * @returns [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) object.
\r
189 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
\r
192 locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[],
\r
193 options?: RelativeTimeFormatOptions,
\r
194 ): RelativeTimeFormat;
\r
197 * Returns an array containing those of the provided locales
\r
198 * that are supported in date and time formatting
\r
199 * without having to fall back to the runtime's default locale.
\r
201 * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
\r
202 * For the general form and interpretation of the locales argument,
\r
203 * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
\r
205 * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
\r
206 * with some or all of options of the formatting.
\r
208 * @returns An array containing those of the provided locales
\r
209 * that are supported in date and time formatting
\r
210 * without having to fall back to the runtime's default locale.
\r
212 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/supportedLocalesOf).
\r
214 supportedLocalesOf(
\r
215 locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[],
\r
216 options?: RelativeTimeFormatOptions,
\r
217 ): UnicodeBCP47LocaleIdentifier[];
\r
220 interface NumberFormatOptions {
\r
221 compactDisplay?: "short" | "long" | undefined;
\r
222 notation?: "standard" | "scientific" | "engineering" | "compact" | undefined;
\r
223 signDisplay?: "auto" | "never" | "always" | undefined;
\r
224 unit?: string | undefined;
\r
225 unitDisplay?: "short" | "long" | "narrow" | undefined;
\r
228 interface ResolvedNumberFormatOptions {
\r
229 compactDisplay?: "short" | "long";
\r
230 notation?: "standard" | "scientific" | "engineering" | "compact";
\r
231 signDisplay?: "auto" | "never" | "always";
\r
233 unitDisplay?: "short" | "long" | "narrow";
\r
236 interface DateTimeFormatOptions {
\r
237 calendar?: string | undefined;
\r
238 dayPeriod?: "narrow" | "short" | "long" | undefined;
\r
239 numberingSystem?: string | undefined;
\r
241 dateStyle?: "full" | "long" | "medium" | "short" | undefined;
\r
242 timeStyle?: "full" | "long" | "medium" | "short" | undefined;
\r
243 hourCycle?: "h11" | "h12" | "h23" | "h24" | undefined;
\r
246 type LocaleHourCycleKey = "h12" | "h23" | "h11" | "h24";
\r
247 type LocaleCollationCaseFirst = "upper" | "lower" | "false";
\r
249 interface LocaleOptions {
\r
250 /** A string containing the language, and the script and region if available. */
\r
252 /** The part of the Locale that indicates the locale's calendar era. */
\r
254 /** Flag that defines whether case is taken into account for the locale's collation rules. */
\r
255 caseFirst?: LocaleCollationCaseFirst;
\r
256 /** The collation type used for sorting */
\r
257 collation?: string;
\r
258 /** The time keeping format convention used by the locale. */
\r
259 hourCycle?: LocaleHourCycleKey;
\r
260 /** The primary language subtag associated with the locale. */
\r
262 /** The numeral system used by the locale. */
\r
263 numberingSystem?: string;
\r
264 /** Flag that defines whether the locale has special collation handling for numeric characters. */
\r
266 /** The region of the world (usually a country) associated with the locale. Possible values are region codes as defined by ISO 3166-1. */
\r
268 /** The script used for writing the particular language used in the locale. Possible values are script codes as defined by ISO 15924. */
\r
272 interface Locale extends LocaleOptions {
\r
273 /** Gets the most likely values for the language, script, and region of the locale based on existing values. */
\r
274 maximize(): Locale;
\r
275 /** Attempts to remove information about the locale that would be added by calling `Locale.maximize()`. */
\r
276 minimize(): Locale;
\r
277 /** Returns the locale's full locale identifier string. */
\r
278 toString(): BCP47LanguageTag;
\r
282 * Constructor creates [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
\r
285 * @param tag - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646).
\r
286 * For the general form and interpretation of the locales argument,
\r
287 * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
\r
289 * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale#Parameters) with some or all of options of the locale.
\r
291 * @returns [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) object.
\r
293 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale).
\r
296 new (tag?: BCP47LanguageTag, options?: LocaleOptions): Locale;
\r
299 interface DisplayNamesOptions {
\r
300 localeMatcher: RelativeTimeFormatLocaleMatcher;
\r
301 style: RelativeTimeFormatStyle;
\r
302 type: "language" | "region" | "script" | "currency";
\r
303 fallback: "code" | "none";
\r
306 interface DisplayNames {
\r
308 * Receives a code and returns a string based on the locale and options provided when instantiating
\r
309 * [`Intl.DisplayNames()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
\r
311 * @param code The `code` to provide depends on the `type` passed to display name during creation:
\r
312 * - If the type is `"region"`, code should be either an [ISO-3166 two letters region code](https://www.iso.org/iso-3166-country-codes.html),
\r
313 * or a [three digits UN M49 Geographic Regions](https://unstats.un.org/unsd/methodology/m49/).
\r
314 * - If the type is `"script"`, code should be an [ISO-15924 four letters script code](https://unicode.org/iso15924/iso15924-codes.html).
\r
315 * - If the type is `"language"`, code should be a `languageCode` ["-" `scriptCode`] ["-" `regionCode` ] *("-" `variant` )
\r
316 * subsequence of the unicode_language_id grammar in [UTS 35's Unicode Language and Locale Identifiers grammar](https://unicode.org/reports/tr35/#Unicode_language_identifier).
\r
317 * `languageCode` is either a two letters ISO 639-1 language code or a three letters ISO 639-2 language code.
\r
318 * - If the type is `"currency"`, code should be a [3-letter ISO 4217 currency code](https://www.iso.org/iso-4217-currency-codes.html).
\r
320 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of).
\r
322 of(code: string): string;
\r
324 * Returns a new object with properties reflecting the locale and style formatting options computed during the construction of the current
\r
325 * [`Intl/DisplayNames`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object.
\r
327 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions).
\r
329 resolvedOptions(): DisplayNamesOptions;
\r
333 * The [`Intl.DisplayNames()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
\r
334 * object enables the consistent translation of language, region and script display names.
\r
336 * [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames#browser_compatibility).
\r
338 const DisplayNames: {
\r
339 prototype: DisplayNames;
\r
342 * @param locales A string with a BCP 47 language tag, or an array of such strings.
\r
343 * For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation)
\r
346 * @param options An object for setting up a display name.
\r
348 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames).
\r
350 new(locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: Partial<DisplayNamesOptions>): DisplayNames;
\r
353 * Returns an array containing those of the provided locales that are supported in display names without having to fall back to the runtime's default locale.
\r
355 * @param locales A string with a BCP 47 language tag, or an array of such strings.
\r
356 * For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation)
\r
359 * @param options An object with a locale matcher.
\r
361 * @returns An array of strings representing a subset of the given locale tags that are supported in display names without having to fall back to the runtime's default locale.
\r
363 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf).
\r
365 supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: {localeMatcher: RelativeTimeFormatLocaleMatcher}): BCP47LanguageTag[];
\r