lib.es2022.intl.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /**
  16. * An object with some or all properties of the `Intl.Segmenter` constructor `options` parameter.
  17. *
  18. * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#parameters)
  19. */
  20. interface SegmenterOptions {
  21. /** 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). */
  22. localeMatcher?: "best fit" | "lookup" | undefined;
  23. /** The type of input to be split */
  24. granularity?: "grapheme" | "word" | "sentence" | undefined;
  25. }
  26. interface Segmenter {
  27. /**
  28. * Returns `Segments` object containing the segments of the input string, using the segmenter's locale and granularity.
  29. *
  30. * @param input - The text to be segmented as a `string`.
  31. *
  32. * @returns A new iterable Segments object containing the segments of the input string, using the segmenter's locale and granularity.
  33. */
  34. segment(input: string): Segments;
  35. resolvedOptions(): ResolvedSegmenterOptions;
  36. }
  37. interface ResolvedSegmenterOptions {
  38. locale: string;
  39. granularity: "grapheme" | "word" | "sentence";
  40. }
  41. interface Segments {
  42. /**
  43. * Returns an object describing the segment in the original string that includes the code unit at a specified index.
  44. *
  45. * @param codeUnitIndex - A number specifying the index of the code unit in the original input string. If the value is omitted, it defaults to `0`.
  46. */
  47. containing(codeUnitIndex?: number): SegmentData;
  48. /** Returns an iterator to iterate over the segments. */
  49. [Symbol.iterator](): IterableIterator<SegmentData>;
  50. }
  51. interface SegmentData {
  52. /** A string containing the segment extracted from the original input string. */
  53. segment: string;
  54. /** The code unit index in the original input string at which the segment begins. */
  55. index: number;
  56. /** The complete input string that was segmented. */
  57. input: string;
  58. /**
  59. * A boolean value only if granularity is "word"; otherwise, undefined.
  60. * If granularity is "word", then isWordLike is true when the segment is word-like (i.e., consists of letters/numbers/ideographs/etc.); otherwise, false.
  61. */
  62. isWordLike?: boolean;
  63. }
  64. const Segmenter: {
  65. prototype: Segmenter;
  66. /**
  67. * Creates a new `Intl.Segmenter` object.
  68. *
  69. * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
  70. * For the general form and interpretation of the `locales` argument,
  71. * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
  72. *
  73. * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#parameters)
  74. * with some or all options of `SegmenterOptions`.
  75. *
  76. * @returns [Intl.Segmenter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segments) object.
  77. *
  78. * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter).
  79. */
  80. new(locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: SegmenterOptions): Segmenter;
  81. /**
  82. * Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.
  83. *
  84. * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
  85. * For the general form and interpretation of the `locales` argument,
  86. * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
  87. *
  88. * @param options An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf#parameters).
  89. * with some or all possible options.
  90. *
  91. * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
  92. */
  93. supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<SegmenterOptions, "localeMatcher">): BCP47LanguageTag[];
  94. };
  95. }