match.cjs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. "use strict";
  2. exports.match = void 0;
  3. var _index = require("../../_lib/buildMatchFn.cjs");
  4. var _index2 = require("../../_lib/buildMatchPatternFn.cjs");
  5. const matchOrdinalNumberPattern = /^(\d+)/i;
  6. const parseOrdinalNumberPattern = /\d+/i;
  7. const matchEraPatterns = {
  8. narrow: /^(tcn|scn)/i,
  9. abbreviated: /^(trước CN|sau CN)/i,
  10. wide: /^(trước Công Nguyên|sau Công Nguyên)/i,
  11. };
  12. const parseEraPatterns = {
  13. any: [/^t/i, /^s/i],
  14. };
  15. const matchQuarterPatterns = {
  16. narrow: /^([1234]|i{1,3}v?)/i,
  17. abbreviated: /^q([1234]|i{1,3}v?)/i,
  18. wide: /^quý ([1234]|i{1,3}v?)/i,
  19. };
  20. const parseQuarterPatterns = {
  21. any: [/(1|i)$/i, /(2|ii)$/i, /(3|iii)$/i, /(4|iv)$/i],
  22. };
  23. const matchMonthPatterns = {
  24. // month number may contain leading 0, 'thg' prefix may have space, underscore or empty before number
  25. // note the order of '1' since it is a sub-string of '10', so must be lower priority
  26. narrow: /^(0?[2-9]|10|11|12|0?1)/i,
  27. // note the order of 'thg 1' since it is sub-string of 'thg 10', so must be lower priority
  28. abbreviated: /^thg[ _]?(0?[1-9](?!\d)|10|11|12)/i,
  29. // note the order of 'Mười' since it is sub-string of Mười Một, so must be lower priority
  30. wide: /^tháng ?(Một|Hai|Ba|Tư|Năm|Sáu|Bảy|Tám|Chín|Mười|Mười ?Một|Mười ?Hai|0?[1-9](?!\d)|10|11|12)/i,
  31. };
  32. const parseMonthPatterns = {
  33. narrow: [
  34. /0?1$/i,
  35. /0?2/i,
  36. /3/,
  37. /4/,
  38. /5/,
  39. /6/,
  40. /7/,
  41. /8/,
  42. /9/,
  43. /10/,
  44. /11/,
  45. /12/,
  46. ],
  47. abbreviated: [
  48. /^thg[ _]?0?1(?!\d)/i,
  49. /^thg[ _]?0?2/i,
  50. /^thg[ _]?0?3/i,
  51. /^thg[ _]?0?4/i,
  52. /^thg[ _]?0?5/i,
  53. /^thg[ _]?0?6/i,
  54. /^thg[ _]?0?7/i,
  55. /^thg[ _]?0?8/i,
  56. /^thg[ _]?0?9/i,
  57. /^thg[ _]?10/i,
  58. /^thg[ _]?11/i,
  59. /^thg[ _]?12/i,
  60. ],
  61. wide: [
  62. /^tháng ?(Một|0?1(?!\d))/i,
  63. /^tháng ?(Hai|0?2)/i,
  64. /^tháng ?(Ba|0?3)/i,
  65. /^tháng ?(Tư|0?4)/i,
  66. /^tháng ?(Năm|0?5)/i,
  67. /^tháng ?(Sáu|0?6)/i,
  68. /^tháng ?(Bảy|0?7)/i,
  69. /^tháng ?(Tám|0?8)/i,
  70. /^tháng ?(Chín|0?9)/i,
  71. /^tháng ?(Mười|10)/i,
  72. /^tháng ?(Mười ?Một|11)/i,
  73. /^tháng ?(Mười ?Hai|12)/i,
  74. ],
  75. };
  76. const matchDayPatterns = {
  77. narrow: /^(CN|T2|T3|T4|T5|T6|T7)/i,
  78. short: /^(CN|Th ?2|Th ?3|Th ?4|Th ?5|Th ?6|Th ?7)/i,
  79. abbreviated: /^(CN|Th ?2|Th ?3|Th ?4|Th ?5|Th ?6|Th ?7)/i,
  80. wide: /^(Chủ ?Nhật|Chúa ?Nhật|thứ ?Hai|thứ ?Ba|thứ ?Tư|thứ ?Năm|thứ ?Sáu|thứ ?Bảy)/i,
  81. };
  82. const parseDayPatterns = {
  83. narrow: [/CN/i, /2/i, /3/i, /4/i, /5/i, /6/i, /7/i],
  84. short: [/CN/i, /2/i, /3/i, /4/i, /5/i, /6/i, /7/i],
  85. abbreviated: [/CN/i, /2/i, /3/i, /4/i, /5/i, /6/i, /7/i],
  86. wide: [/(Chủ|Chúa) ?Nhật/i, /Hai/i, /Ba/i, /Tư/i, /Năm/i, /Sáu/i, /Bảy/i],
  87. };
  88. const matchDayPeriodPatterns = {
  89. narrow: /^(a|p|nửa đêm|trưa|(giờ) (sáng|chiều|tối|đêm))/i,
  90. abbreviated: /^(am|pm|nửa đêm|trưa|(giờ) (sáng|chiều|tối|đêm))/i,
  91. wide: /^(ch[^i]*|sa|nửa đêm|trưa|(giờ) (sáng|chiều|tối|đêm))/i,
  92. };
  93. const parseDayPeriodPatterns = {
  94. any: {
  95. am: /^(a|sa)/i,
  96. pm: /^(p|ch[^i]*)/i,
  97. midnight: /nửa đêm/i,
  98. noon: /trưa/i,
  99. morning: /sáng/i,
  100. afternoon: /chiều/i,
  101. evening: /tối/i,
  102. night: /^đêm/i,
  103. },
  104. };
  105. const match = (exports.match = {
  106. ordinalNumber: (0, _index2.buildMatchPatternFn)({
  107. matchPattern: matchOrdinalNumberPattern,
  108. parsePattern: parseOrdinalNumberPattern,
  109. valueCallback: (value) => parseInt(value, 10),
  110. }),
  111. era: (0, _index.buildMatchFn)({
  112. matchPatterns: matchEraPatterns,
  113. defaultMatchWidth: "wide",
  114. parsePatterns: parseEraPatterns,
  115. defaultParseWidth: "any",
  116. }),
  117. quarter: (0, _index.buildMatchFn)({
  118. matchPatterns: matchQuarterPatterns,
  119. defaultMatchWidth: "wide",
  120. parsePatterns: parseQuarterPatterns,
  121. defaultParseWidth: "any",
  122. valueCallback: (index) => index + 1,
  123. }),
  124. month: (0, _index.buildMatchFn)({
  125. matchPatterns: matchMonthPatterns,
  126. defaultMatchWidth: "wide",
  127. parsePatterns: parseMonthPatterns,
  128. defaultParseWidth: "wide",
  129. }),
  130. day: (0, _index.buildMatchFn)({
  131. matchPatterns: matchDayPatterns,
  132. defaultMatchWidth: "wide",
  133. parsePatterns: parseDayPatterns,
  134. defaultParseWidth: "wide",
  135. }),
  136. dayPeriod: (0, _index.buildMatchFn)({
  137. matchPatterns: matchDayPeriodPatterns,
  138. defaultMatchWidth: "wide",
  139. parsePatterns: parseDayPeriodPatterns,
  140. defaultParseWidth: "any",
  141. }),
  142. });