@aikidosec/firewall
Version:
Zen by Aikido is an embedded Web Application Firewall that autonomously protects Node.js apps against common and critical attacks
21 lines (20 loc) • 567 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = isDateString;
/**
* Checks if the string is a date according to RFC3339
* https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
*/
function isDateString(str) {
if (str.length !== 10) {
return false;
}
if (!/^\d{4}-\d{2}-\d{2}$/.test(str)) {
return false;
}
const [year, month, day] = str.split("-").map(Number);
if (month < 1 || month > 12 || day < 1 || day > 31 || year < 0) {
return false;
}
return true;
}