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