2
0

ListFormat.hx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C)2005-2021 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package js.lib.intl;
  23. /**
  24. The `Intl.ListFormat` object enables language-sensitive list formatting.
  25. **/
  26. @:native("Intl.ListFormat")
  27. extern class ListFormat {
  28. /**
  29. Creates a new `Intl.ListFormat` object.
  30. **/
  31. @:overload(function(?locales: Array<String>, ?options: ListFormatOptions): Void {})
  32. function new(?locales: String, ?options: ListFormatOptions);
  33. /**
  34. Returns a language-specific formatted string representing the elements of the list.
  35. **/
  36. function format(?list: Array<String>): String;
  37. /**
  38. Returns an array of objects representing the different components
  39. that can be used to format a list of values in a locale-aware fashion.
  40. **/
  41. function formatToParts(?list: Array<String>): Array<ListFormatPart>;
  42. /**
  43. Returns an array containing those of the provided locales that are supported
  44. without having to fall back to the runtime's default locale.
  45. **/
  46. @:overload(function(locales: Array<String>, ?options: ListFormatSupportedLocalesOfOptions): Array<String> {})
  47. static function supportedLocalesOf(locales: String, ?options: ListFormatSupportedLocalesOfOptions): Array<String>;
  48. }
  49. typedef ListFormatOptions = {
  50. /**
  51. The locale matching algorithm to use.
  52. The default is `BestFit`.
  53. **/
  54. var ?localeMatcher: LocaleMatcher;
  55. /**
  56. The length of the formatted message.
  57. The default is `Long`.
  58. **/
  59. var ?style: ListFormatStyle;
  60. /**
  61. The format of output message.
  62. **/
  63. var ?type: ListFormatType;
  64. }
  65. typedef ListFormatPart = {
  66. final type: ListFormatPartType;
  67. final value: String;
  68. }
  69. enum abstract ListFormatPartType(String) {
  70. /**
  71. A value from the list.
  72. **/
  73. var Element = "element";
  74. /**
  75. A linguistic construct.
  76. **/
  77. var Literal = "literal";
  78. }
  79. enum abstract ListFormatStyle(String) {
  80. var Long = "long";
  81. var Narrow = "narrow";
  82. var Short = "short";
  83. }
  84. typedef ListFormatSupportedLocalesOfOptions = {
  85. /**
  86. The locale matching algorithm to use.
  87. The default is `BestFit`.
  88. */
  89. var ?localeMatcher: LocaleMatcher;
  90. }
  91. enum abstract ListFormatType(String) {
  92. /**
  93. Stands for "and"-based lists.
  94. **/
  95. var Conjunction = "conjunction";
  96. /**
  97. Stands for "or"-based lists.
  98. **/
  99. var Disjunction = "disjunction";
  100. /**
  101. Stands for lists of values with units.
  102. **/
  103. var Unit = "unit";
  104. }