lib.es2021.intl.d.ts 7.6 KB

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