isValidPreCandidate.js 962 B

123456789101112131415161718192021222324252627
  1. // Matches strings that look like dates using "/" as a separator.
  2. // Examples: 3/10/2011, 31/10/96 or 08/31/95.
  3. var SLASH_SEPARATED_DATES = /(?:(?:[0-3]?\d\/[01]?\d)|(?:[01]?\d\/[0-3]?\d))\/(?:[12]\d)?\d{2}/; // Matches timestamps.
  4. // Examples: "2012-01-02 08:00".
  5. // Note that the reg-ex does not include the
  6. // trailing ":\d\d" -- that is covered by TIME_STAMPS_SUFFIX.
  7. var TIME_STAMPS = /[12]\d{3}[-/]?[01]\d[-/]?[0-3]\d +[0-2]\d$/;
  8. var TIME_STAMPS_SUFFIX_LEADING = /^:[0-5]\d/;
  9. export default function isValidPreCandidate(candidate, offset, text) {
  10. // Skip a match that is more likely to be a date.
  11. if (SLASH_SEPARATED_DATES.test(candidate)) {
  12. return false;
  13. } // Skip potential time-stamps.
  14. if (TIME_STAMPS.test(candidate)) {
  15. var followingText = text.slice(offset + candidate.length);
  16. if (TIME_STAMPS_SUFFIX_LEADING.test(followingText)) {
  17. return false;
  18. }
  19. }
  20. return true;
  21. }
  22. //# sourceMappingURL=isValidPreCandidate.js.map