isTime.js 925 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isTime;
  6. var _merge = _interopRequireDefault(require("./util/merge"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. var default_time_options = {
  9. hourFormat: 'hour24',
  10. mode: 'default'
  11. };
  12. var formats = {
  13. hour24: {
  14. default: /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/,
  15. withSeconds: /^([01]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/
  16. },
  17. hour12: {
  18. default: /^(0?[1-9]|1[0-2]):([0-5][0-9]) (A|P)M$/,
  19. withSeconds: /^(0?[1-9]|1[0-2]):([0-5][0-9]):([0-5][0-9]) (A|P)M$/
  20. }
  21. };
  22. function isTime(input, options) {
  23. options = (0, _merge.default)(options, default_time_options);
  24. if (typeof input !== 'string') return false;
  25. return formats[options.hourFormat][options.mode].test(input);
  26. }
  27. module.exports = exports.default;
  28. module.exports.default = exports.default;