match.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { buildMatchFn } from "../../_lib/buildMatchFn.js";
  2. import { buildMatchPatternFn } from "../../_lib/buildMatchPatternFn.js";
  3. const matchOrdinalNumberPattern = /^(\d+)(వ)?/i;
  4. const parseOrdinalNumberPattern = /\d+/i;
  5. const matchEraPatterns = {
  6. narrow: /^(క్రీ\.పూ\.|క్రీ\.శ\.)/i,
  7. abbreviated:
  8. /^(క్రీ\.?\s?పూ\.?|ప్ర\.?\s?శ\.?\s?పూ\.?|క్రీ\.?\s?శ\.?|సా\.?\s?శ\.?)/i,
  9. wide: /^(క్రీస్తు పూర్వం|ప్రస్తుత శకానికి పూర్వం|క్రీస్తు శకం|ప్రస్తుత శకం)/i,
  10. };
  11. const parseEraPatterns = {
  12. any: [/^(పూ|శ)/i, /^సా/i],
  13. };
  14. const matchQuarterPatterns = {
  15. narrow: /^[1234]/i,
  16. abbreviated: /^త్రై[1234]/i,
  17. wide: /^[1234](వ)? త్రైమాసికం/i,
  18. };
  19. const parseQuarterPatterns = {
  20. any: [/1/i, /2/i, /3/i, /4/i],
  21. };
  22. const matchMonthPatterns = {
  23. narrow: /^(జూ|జు|జ|ఫి|మా|ఏ|మే|ఆ|సె|అ|న|డి)/i,
  24. abbreviated: /^(జన|ఫిబ్ర|మార్చి|ఏప్రి|మే|జూన్|జులై|ఆగ|సెప్|అక్టో|నవ|డిసె)/i,
  25. wide: /^(జనవరి|ఫిబ్రవరి|మార్చి|ఏప్రిల్|మే|జూన్|జులై|ఆగస్టు|సెప్టెంబర్|అక్టోబర్|నవంబర్|డిసెంబర్)/i,
  26. };
  27. const parseMonthPatterns = {
  28. narrow: [
  29. /^జ/i,
  30. /^ఫి/i,
  31. /^మా/i,
  32. /^ఏ/i,
  33. /^మే/i,
  34. /^జూ/i,
  35. /^జు/i,
  36. /^ఆ/i,
  37. /^సె/i,
  38. /^అ/i,
  39. /^న/i,
  40. /^డి/i,
  41. ],
  42. any: [
  43. /^జన/i,
  44. /^ఫి/i,
  45. /^మా/i,
  46. /^ఏ/i,
  47. /^మే/i,
  48. /^జూన్/i,
  49. /^జులై/i,
  50. /^ఆగ/i,
  51. /^సె/i,
  52. /^అ/i,
  53. /^న/i,
  54. /^డి/i,
  55. ],
  56. };
  57. const matchDayPatterns = {
  58. narrow: /^(ఆ|సో|మ|బు|గు|శు|శ)/i,
  59. short: /^(ఆది|సోమ|మం|బుధ|గురు|శుక్ర|శని)/i,
  60. abbreviated: /^(ఆది|సోమ|మం|బుధ|గురు|శుక్ర|శని)/i,
  61. wide: /^(ఆదివారం|సోమవారం|మంగళవారం|బుధవారం|గురువారం|శుక్రవారం|శనివారం)/i,
  62. };
  63. const parseDayPatterns = {
  64. narrow: [/^ఆ/i, /^సో/i, /^మ/i, /^బు/i, /^గు/i, /^శు/i, /^శ/i],
  65. any: [/^ఆది/i, /^సోమ/i, /^మం/i, /^బుధ/i, /^గురు/i, /^శుక్ర/i, /^శని/i],
  66. };
  67. const matchDayPeriodPatterns = {
  68. narrow:
  69. /^(పూర్వాహ్నం|అపరాహ్నం|అర్ధరాత్రి|మిట్టమధ్యాహ్నం|ఉదయం|మధ్యాహ్నం|సాయంత్రం|రాత్రి)/i,
  70. any: /^(పూర్వాహ్నం|అపరాహ్నం|అర్ధరాత్రి|మిట్టమధ్యాహ్నం|ఉదయం|మధ్యాహ్నం|సాయంత్రం|రాత్రి)/i,
  71. };
  72. const parseDayPeriodPatterns = {
  73. any: {
  74. am: /^పూర్వాహ్నం/i,
  75. pm: /^అపరాహ్నం/i,
  76. midnight: /^అర్ధ/i,
  77. noon: /^మిట్ట/i,
  78. morning: /ఉదయం/i,
  79. afternoon: /మధ్యాహ్నం/i,
  80. evening: /సాయంత్రం/i,
  81. night: /రాత్రి/i,
  82. },
  83. };
  84. export const match = {
  85. ordinalNumber: buildMatchPatternFn({
  86. matchPattern: matchOrdinalNumberPattern,
  87. parsePattern: parseOrdinalNumberPattern,
  88. valueCallback: (value) => parseInt(value, 10),
  89. }),
  90. era: buildMatchFn({
  91. matchPatterns: matchEraPatterns,
  92. defaultMatchWidth: "wide",
  93. parsePatterns: parseEraPatterns,
  94. defaultParseWidth: "any",
  95. }),
  96. quarter: buildMatchFn({
  97. matchPatterns: matchQuarterPatterns,
  98. defaultMatchWidth: "wide",
  99. parsePatterns: parseQuarterPatterns,
  100. defaultParseWidth: "any",
  101. valueCallback: (index) => index + 1,
  102. }),
  103. month: buildMatchFn({
  104. matchPatterns: matchMonthPatterns,
  105. defaultMatchWidth: "wide",
  106. parsePatterns: parseMonthPatterns,
  107. defaultParseWidth: "any",
  108. }),
  109. day: buildMatchFn({
  110. matchPatterns: matchDayPatterns,
  111. defaultMatchWidth: "wide",
  112. parsePatterns: parseDayPatterns,
  113. defaultParseWidth: "any",
  114. }),
  115. dayPeriod: buildMatchFn({
  116. matchPatterns: matchDayPeriodPatterns,
  117. defaultMatchWidth: "any",
  118. parsePatterns: parseDayPeriodPatterns,
  119. defaultParseWidth: "any",
  120. }),
  121. };