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