isValidPreCandidate.js 1.0 KB

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