lib.es2021.intl.d.ts 8.2 KB

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