index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _index = _interopRequireDefault(require("../../../_lib/buildMatchFn/index.js"));
  8. var _index2 = _interopRequireDefault(require("../../../_lib/buildMatchPatternFn/index.js"));
  9. var matchOrdinalNumberPattern = /^(第\s*)?\d+(日|时|分|秒)?/i;
  10. var parseOrdinalNumberPattern = /\d+/i;
  11. var matchEraPatterns = {
  12. narrow: /^(前)/i,
  13. abbreviated: /^(前)/i,
  14. wide: /^(公元前|公元)/i
  15. };
  16. var parseEraPatterns = {
  17. any: [/^(前)/i, /^(公元)/i]
  18. };
  19. var matchQuarterPatterns = {
  20. narrow: /^[1234]/i,
  21. abbreviated: /^第[一二三四]刻/i,
  22. wide: /^第[一二三四]刻钟/i
  23. };
  24. var parseQuarterPatterns = {
  25. any: [/(1|一)/i, /(2|二)/i, /(3|三)/i, /(4|四)/i]
  26. };
  27. var matchMonthPatterns = {
  28. narrow: /^(一|二|三|四|五|六|七|八|九|十[二一])/i,
  29. abbreviated: /^(一|二|三|四|五|六|七|八|九|十[二一]|\d|1[12])月/i,
  30. wide: /^(一|二|三|四|五|六|七|八|九|十[二一])月/i
  31. };
  32. var parseMonthPatterns = {
  33. narrow: [/^一/i, /^二/i, /^三/i, /^四/i, /^五/i, /^六/i, /^七/i, /^八/i, /^九/i, /^十(?!(一|二))/i, /^十一/i, /^十二/i],
  34. any: [/^一|1/i, /^二|2/i, /^三|3/i, /^四|4/i, /^五|5/i, /^六|6/i, /^七|7/i, /^八|8/i, /^九|9/i, /^十(?!(一|二))|10/i, /^十一|11/i, /^十二|12/i]
  35. };
  36. var matchDayPatterns = {
  37. narrow: /^[一二三四五六日]/i,
  38. short: /^[一二三四五六日]/i,
  39. abbreviated: /^周[一二三四五六日]/i,
  40. wide: /^星期[一二三四五六日]/i
  41. };
  42. var parseDayPatterns = {
  43. any: [/日/i, /一/i, /二/i, /三/i, /四/i, /五/i, /六/i]
  44. };
  45. var matchDayPeriodPatterns = {
  46. any: /^(上午?|下午?|午夜|[中正]午|早上?|下午|晚上?|凌晨|)/i
  47. };
  48. var parseDayPeriodPatterns = {
  49. any: {
  50. am: /^上午?/i,
  51. pm: /^下午?/i,
  52. midnight: /^午夜/i,
  53. noon: /^[中正]午/i,
  54. morning: /^早上/i,
  55. afternoon: /^下午/i,
  56. evening: /^晚上?/i,
  57. night: /^凌晨/i
  58. }
  59. };
  60. var match = {
  61. ordinalNumber: (0, _index2.default)({
  62. matchPattern: matchOrdinalNumberPattern,
  63. parsePattern: parseOrdinalNumberPattern,
  64. valueCallback: function valueCallback(value) {
  65. return parseInt(value, 10);
  66. }
  67. }),
  68. era: (0, _index.default)({
  69. matchPatterns: matchEraPatterns,
  70. defaultMatchWidth: 'wide',
  71. parsePatterns: parseEraPatterns,
  72. defaultParseWidth: 'any'
  73. }),
  74. quarter: (0, _index.default)({
  75. matchPatterns: matchQuarterPatterns,
  76. defaultMatchWidth: 'wide',
  77. parsePatterns: parseQuarterPatterns,
  78. defaultParseWidth: 'any',
  79. valueCallback: function valueCallback(index) {
  80. return index + 1;
  81. }
  82. }),
  83. month: (0, _index.default)({
  84. matchPatterns: matchMonthPatterns,
  85. defaultMatchWidth: 'wide',
  86. parsePatterns: parseMonthPatterns,
  87. defaultParseWidth: 'any'
  88. }),
  89. day: (0, _index.default)({
  90. matchPatterns: matchDayPatterns,
  91. defaultMatchWidth: 'wide',
  92. parsePatterns: parseDayPatterns,
  93. defaultParseWidth: 'any'
  94. }),
  95. dayPeriod: (0, _index.default)({
  96. matchPatterns: matchDayPeriodPatterns,
  97. defaultMatchWidth: 'any',
  98. parsePatterns: parseDayPeriodPatterns,
  99. defaultParseWidth: 'any'
  100. })
  101. };
  102. var _default = match;
  103. exports.default = _default;
  104. module.exports = exports.default;