isRFC3339.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isRFC3339;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. /* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */
  9. var dateFullYear = /[0-9]{4}/;
  10. var dateMonth = /(0[1-9]|1[0-2])/;
  11. var dateMDay = /([12]\d|0[1-9]|3[01])/;
  12. var timeHour = /([01][0-9]|2[0-3])/;
  13. var timeMinute = /[0-5][0-9]/;
  14. var timeSecond = /([0-5][0-9]|60)/;
  15. var timeSecFrac = /(\.[0-9]+)?/;
  16. var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source));
  17. var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")"));
  18. var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source));
  19. var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source));
  20. var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source));
  21. var rfc3339 = new RegExp("^".concat(fullDate.source, "[ tT]").concat(fullTime.source, "$"));
  22. function isRFC3339(str) {
  23. (0, _assertString.default)(str);
  24. return rfc3339.test(str);
  25. }
  26. module.exports = exports.default;
  27. module.exports.default = exports.default;