typia
Version:
Superfast runtime validators with only one line
20 lines • 731 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._isFormatDate = void 0;
const _isFormatDate = (str) => {
const match = PATTERN.exec(str);
if (match === null)
return false;
const year = Number(match[1]);
const month = Number(match[2]);
const day = Number(match[3]);
const maximum = DAYS[month - 1] +
(month === 2 && (year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0))
? 1
: 0);
return day <= maximum;
};
exports._isFormatDate = _isFormatDate;
const PATTERN = /^([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
const DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
//# sourceMappingURL=_isFormatDate.js.map