Skip to content

Commit 5616d77

Browse files
committed
Add Intl.DisplayNames types
The TC39 proposal (https://github.com/tc39/proposal-intl-displaynames) reached stage 4 in September 2020. Fixes microsoft#41338
1 parent fc34fa0 commit 5616d77

File tree

1 file changed

+109
-2
lines changed

1 file changed

+109
-2
lines changed

src/lib/es2020.intl.d.ts

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ declare namespace Intl {
7070
/**
7171
* An object with properties reflecting the locale
7272
* and formatting options computed during initialization
73-
* of the `Intel.RelativeTimeFormat` object
73+
* of the `Intl.RelativeTimeFormat` object
7474
*
7575
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions#Description).
7676
*
@@ -170,7 +170,7 @@ declare namespace Intl {
170170
*
171171
* @returns A new object with properties reflecting the locale
172172
* and formatting options computed during initialization
173-
* of the `Intel.RelativeTimeFormat` object.
173+
* of the `Intl.RelativeTimeFormat` object.
174174
*
175175
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions).
176176
*
@@ -286,4 +286,111 @@ declare namespace Intl {
286286
hourCycle?: "h11" | "h12" | "h23" | "h24";
287287
fractionalSecondDigits?: 0 | 1 | 2 | 3;
288288
}
289+
290+
/**
291+
* An object with properties reflecting the locale
292+
* and styles options computed during initialization
293+
* of the `Intl.DisplayNames` object
294+
*
295+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions#Description).
296+
*
297+
* [Specification](https://tc39.es/ecma402/#sec-intl-displaynames-constructor)
298+
*/
299+
interface DisplayNamesOptions {
300+
localeMatcher: RelativeTimeFormatLocaleMatcher;
301+
style: RelativeTimeFormatStyle;
302+
type: "language" | "region" | "script" | "currency";
303+
fallback: "code" | "none";
304+
}
305+
306+
interface DisplayNames {
307+
/**
308+
* Receives a code and returns a string based on the locale and options provided when instantiating
309+
* [`Intl.DisplayNames()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
310+
*
311+
* @param code The `code` to provide depends on the `type`:
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),
313+
* or a [three digits UN M49 Geographic Regions](https://unstats.un.org/unsd/methodology/m49/).
314+
* - If the type is "script", code should be an [ISO-15924 four letters script code](https://unicode.org/iso15924/iso15924-codes.html).
315+
* - If the type is "language", code should be a `languageCode` ["-" `scriptCode`] ["-" `regionCode` ] *("-" `variant` )
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).
317+
* `languageCode` is either a two letters ISO 639-1 language code or a three letters ISO 639-2 language code.
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).
319+
*
320+
* @returns A language-specific formatted string.
321+
*
322+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of).
323+
*
324+
* [Specification](https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.of).
325+
*/
326+
of(code: string): string;
327+
/**
328+
* Returns a new object with properties reflecting the locale and style formatting options computed during the construction of the current
329+
* [`Intl/DisplayNames`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object.
330+
*
331+
* @returns An object with properties reflecting the locale and formatting options computed during the construction of the
332+
* given [`Intl/DisplayNames`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object.
333+
*
334+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions).
335+
*
336+
* [Specification](https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.resolvedOptions)
337+
*/
338+
resolvedOptions(): DisplayNamesOptions;
339+
}
340+
341+
/**
342+
* The [`Intl.DisplayNames()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
343+
* object enables the consistent translation of language, region and script display names.
344+
*
345+
* Part of [Intl object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl)
346+
* namespace and the [ECMAScript Internationalization API](https://www.ecma-international.org/publications/standards/Ecma-402.htm).
347+
*
348+
* [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames#browser_compatibility).
349+
*/
350+
const DisplayNames: {
351+
prototype: DisplayNames;
352+
353+
/**
354+
* Constructor creates [`Intl.DisplayNames`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
355+
* objects that enable the consistent translation of language, region and script display names.
356+
*
357+
* @param locales A string with a BCP 47 language tag, or an array of such strings.
358+
* 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)
359+
* page. The following Unicode extension key is allowed:
360+
* - `nu` The numbering system to be used. Possible values include: `"arab"`, `"arabext"`, `"bali"`, `"beng"`, `"deva"`, `"fullwide"`, `"gujr"`, `"guru"`, `"hanidec"`, `"khmr"`, `"knda"`, `"laoo"`, `"latn"`, `"limb"`, `"mlym"`, `"mong"`, `"mymr"`, `"orya"`, `"tamldec"`, `"telu"`, `"thai"`, `"tibt"`.
361+
*
362+
* @param options An object with some or all of the following properties:
363+
* - `localeMatcher` The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`.
364+
* For information about this option, see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) page.
365+
* - `style` The formatting style to use, the default is `"long"`. `"narrow"` `"short"` `"long"`
366+
* - `type` The type to use. `"language"` `"region"` `"script"` `"currency"`
367+
* - `fallback` The fallback to use, the default is `"code"`. `"code"` `"none"`
368+
*
369+
* @returns [Intl.DisplayNames](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object.
370+
*
371+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames).
372+
*
373+
* [Specification](https://tc39.es/ecma402/#sec-intl-displaynames-constructor).
374+
*/
375+
new(locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: Partial<DisplayNamesOptions>): DisplayNames;
376+
377+
/**
378+
* 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.
379+
*
380+
* @param locales A string with a BCP 47 language tag, or an array of such strings.
381+
* 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)
382+
* page.
383+
*
384+
* @param options An object that may have the following property:
385+
* - `localeMatcher` The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`.
386+
* For information about this option, see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) page.
387+
*
388+
* @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.
389+
*
390+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf).
391+
*
392+
* [Specification](https://tc39.es/ecma402/#sec-Intl.DisplayNames.supportedLocalesOf).
393+
*/
394+
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options: {localeMatcher: RelativeTimeFormatLocaleMatcher}): BCP47LanguageTag[];
395+
};
289396
}

0 commit comments

Comments
 (0)