index.js 4.1 KB

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