lib.es2021.intl.d.ts (8245B)
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 6 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. 11 12 See the Apache Version 2.0 License for specific language governing permissions 13 and limitations under the License. 14 ***************************************************************************** */ 15 16 17 /// <reference no-default-lib="true"/> 18 19 declare namespace Intl { 20 interface DateTimeFormatPartTypesRegistry { 21 fractionalSecond: any; 22 } 23 24 interface DateTimeFormatOptions { 25 formatMatcher?: "basic" | "best fit" | "best fit" | undefined; 26 dateStyle?: "full" | "long" | "medium" | "short" | undefined; 27 timeStyle?: "full" | "long" | "medium" | "short" | undefined; 28 dayPeriod?: "narrow" | "short" | "long" | undefined; 29 fractionalSecondDigits?: 1 | 2 | 3 | undefined; 30 } 31 32 interface DateTimeRangeFormatPart extends DateTimeFormatPart { 33 source: "startRange" | "endRange" | "shared"; 34 } 35 36 interface DateTimeFormat { 37 formatRange(startDate: Date | number | bigint, endDate: Date | number | bigint): string; 38 formatRangeToParts(startDate: Date | number | bigint, endDate: Date | number | bigint): DateTimeRangeFormatPart[]; 39 } 40 41 interface ResolvedDateTimeFormatOptions { 42 formatMatcher?: "basic" | "best fit" | "best fit"; 43 dateStyle?: "full" | "long" | "medium" | "short"; 44 timeStyle?: "full" | "long" | "medium" | "short"; 45 hourCycle?: "h11" | "h12" | "h23" | "h24"; 46 dayPeriod?: "narrow" | "short" | "long"; 47 fractionalSecondDigits?: 1 | 2 | 3; 48 } 49 50 /** 51 * The locale matching algorithm to use. 52 * 53 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters). 54 */ 55 type ListFormatLocaleMatcher = "lookup" | "best fit"; 56 57 /** 58 * The format of output message. 59 * 60 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters). 61 */ 62 type ListFormatType = "conjunction" | "disjunction" | "unit"; 63 64 /** 65 * The length of the formatted message. 66 * 67 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters). 68 */ 69 type ListFormatStyle = "long" | "short" | "narrow"; 70 71 /** 72 * An object with some or all properties of the `Intl.ListFormat` constructor `options` parameter. 73 * 74 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters). 75 */ 76 interface ListFormatOptions { 77 /** 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). */ 78 localeMatcher?: ListFormatLocaleMatcher | undefined; 79 /** The format of output message. */ 80 type?: ListFormatType | undefined; 81 /** The length of the internationalized message. */ 82 style?: ListFormatStyle | undefined; 83 } 84 85 interface ResolvedListFormatOptions { 86 locale: string; 87 style: ListFormatStyle; 88 type: ListFormatType; 89 } 90 91 interface ListFormat { 92 /** 93 * Returns a string with a language-specific representation of the list. 94 * 95 * @param list - An iterable object, such as an [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array). 96 * 97 * @throws `TypeError` if `list` includes something other than the possible values. 98 * 99 * @returns {string} A language-specific formatted string representing the elements of the list. 100 * 101 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format). 102 */ 103 format(list: Iterable<string>): string; 104 105 /** 106 * Returns an Array of objects representing the different components that can be used to format a list of values in a locale-aware fashion. 107 * 108 * @param list - An iterable object, such as an [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array), to be formatted according to a locale. 109 * 110 * @throws `TypeError` if `list` includes something other than the possible values. 111 * 112 * @returns {{ type: "element" | "literal", value: string; }[]} An Array of components which contains the formatted parts from the list. 113 * 114 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts). 115 */ 116 formatToParts(list: Iterable<string>): { type: "element" | "literal"; value: string; }[]; 117 118 /** 119 * Returns a new object with properties reflecting the locale and style 120 * formatting options computed during the construction of the current 121 * `Intl.ListFormat` object. 122 * 123 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions). 124 */ 125 resolvedOptions(): ResolvedListFormatOptions; 126 } 127 128 const ListFormat: { 129 prototype: ListFormat; 130 131 /** 132 * Creates [Intl.ListFormat](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat) objects that 133 * enable language-sensitive list formatting. 134 * 135 * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings. 136 * For the general form and interpretation of the `locales` argument, 137 * see the [`Intl` page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation). 138 * 139 * @param options - An [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters) 140 * with some or all options of `ListFormatOptions`. 141 * 142 * @returns [Intl.ListFormatOptions](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat) object. 143 * 144 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat). 145 */ 146 new (locales?: LocalesArgument, options?: ListFormatOptions): ListFormat; 147 148 /** 149 * Returns an array containing those of the provided locales that are 150 * supported in list formatting without having to fall back to the runtime's default locale. 151 * 152 * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings. 153 * For the general form and interpretation of the `locales` argument, 154 * see the [`Intl` page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation). 155 * 156 * @param options - An [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf#parameters). 157 * with some or all possible options. 158 * 159 * @returns An array of strings representing a subset of the given locale tags that are supported in list 160 * formatting without having to fall back to the runtime's default locale. 161 * 162 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf). 163 */ 164 supportedLocalesOf(locales: LocalesArgument, options?: Pick<ListFormatOptions, "localeMatcher">): UnicodeBCP47LocaleIdentifier[]; 165 }; 166 }