cron-expression-validator
Advanced tools
Comparing version 1.0.11 to 1.0.13
exports.ERROR_MSGES = { | ||
DAY_OF_WEEK_ERROR_MSG_1: 'Day-of-Week values must be between 1 and 7', | ||
DAY_OF_WEEK_ERROR_MSG_2: 'Day-of-Week values must be SUN, MON, TUE, WED, THU, FRI, SAT OR between 1 and 7', | ||
DAY_OF_WEEK_ERROR_MSG_2: 'Day-of-Week values must be SUN, MON, TUE, WED, THU, FRI, SAT OR between 1 and 7, - * ? / L #', | ||
DAY_OF_WEEK_ERROR_MSG_3: '(Day of week) - Unsupported value for field. Possible values are 1-7 or SUN-SAT , - * ? / L #', | ||
@@ -9,9 +9,13 @@ DAY_OF_WEEK_ERROR_MSG_4: 'A numeric value between 1 and 5 must follow the # option', | ||
MONTH_ERROR_MSG: "Month values must be between 1 and 12", | ||
MONTH_LETTER_ERROR_MSG: "Month values must be JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC OR between 1 and 12", | ||
MONTH_ERROR_MSG: 'Month values must be between 1 and 12', | ||
MONTH_LETTER_ERROR_MSG: 'Month values must be JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC OR between 1 and 12', | ||
YEAR_ERROR_MSG: "Start year must be less than stop year", | ||
YEAR_UNSUPPORT_VAL_ERROR_MSG: "(Year) - Unsupported value for field. Possible values are '1970-2099 , - * /", | ||
YEAR_ERROR_MSG: 'Start year must be less than stop year', | ||
YEAR_UNSUPPORT_VAL_ERROR_MSG: '(Year) - Unsupported value for field. Possible values are 1970-2099 , - * /', | ||
TIME_ERROR_MSG: "Minute and Second values must be between 0 and 59 and Hour Values must be between 0 and 23", | ||
TIME_ERROR_MSG: 'Minute and Second values must be between 0 and 59 and Hour Values must be between 0 and 23', | ||
DAY_OF_MONTH_DAY_OF_WEEK_ERROR_MSG: '? can only be specfied for Day-of-Month -OR- Day-of-Week', | ||
UNEXPECTED_ERROR_MSG: 'Unexpected end of expression', | ||
} |
47
index.js
@@ -14,4 +14,26 @@ const CONSTANTS = require('./constants'); | ||
if(!/\s/g.test(cronExpression)) { | ||
if(errorObj && errorObj.error) { | ||
return { | ||
isValid: false, | ||
errorMessage: CONSTANTS.ERROR_MSGES.UNEXPECTED_ERROR_MSG, | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
let cronArray = cronExpression.split(" "); | ||
if(parseInt(cronArray.length) !== 6 && parseInt(cronArray.length) !== 7 ) { | ||
if(errorObj && errorObj.error) { | ||
return { | ||
isValid: false, | ||
errorMessage: CONSTANTS.ERROR_MSGES.UNEXPECTED_ERROR_MSG, | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
let seconds = cronArray[0].trim(); | ||
@@ -23,3 +45,3 @@ let minutes = cronArray[1].trim(); | ||
let dayOfWeek = cronArray[5].trim(); | ||
let year = cronArray[6].trim(); | ||
let year = cronArray[6] ? cronArray[6].trim() : null; | ||
@@ -32,3 +54,3 @@ let isValidSeconds = isValidTimeValue(seconds, MAX_MIN_SEC_VALUE); | ||
let isValidDayOfWeek = isValidDayOfWeekValue(dayOfWeek, dayOfMonth); | ||
let isValidYear = isValidYearValue(year); | ||
let isValidYear = year ? isValidYearValue(year): true; | ||
@@ -49,2 +71,4 @@ if(errorObj && errorObj.error && isError) { | ||
return true; | ||
} if(dayOfWeek === '*') { | ||
return dayOfMonth !== '*'; | ||
} else if(dayOfWeek.includes('/') && dayOfMonth === '?') { | ||
@@ -109,4 +133,4 @@ let startingDayOfWeekOptionArr = dayOfWeek.split('/'); | ||
isError = true; | ||
if(dayOfWeek === '*' && dayOfMonth === '*' || dayOfWeek === '?' && dayOfMonth === '?') { | ||
errorMsg.push('? can only be specfied for Day-of-Month -OR- Day-of-Week') | ||
if(isInvalidValues(dayOfWeek, dayOfMonth) && !isHasErrorMsg(errorMsg)) { | ||
errorMsg.push(CONSTANTS.ERROR_MSGES.DAY_OF_MONTH_DAY_OF_WEEK_ERROR_MSG) | ||
} else { | ||
@@ -119,2 +143,10 @@ errorMsg.push(CONSTANTS.ERROR_MSGES.DAY_OF_WEEK_ERROR_MSG_2+ " or * or /"); | ||
const isInvalidValues = function(dayOfWeek, dayOfMonth) { | ||
return ((dayOfWeek === '*' && dayOfMonth === '*') || (dayOfWeek === '?' && dayOfMonth === '?')); | ||
} | ||
const isHasErrorMsg = function(array) { | ||
return array.includes(CONSTANTS.ERROR_MSGES.DAY_OF_MONTH_DAY_OF_WEEK_ERROR_MSG); | ||
} | ||
const isValidDayOfMonthValue = function(dayOfMonth, dayOfWeek) { | ||
@@ -158,4 +190,4 @@ if((dayOfMonth === '*' && dayOfWeek !== '*') || (dayOfMonth === '?' && dayOfWeek !== '?')) { | ||
isError = true; | ||
if(dayOfWeek === '*' && dayOfMonth === '*' || dayOfWeek === '?' && dayOfMonth === '?') { | ||
errorMsg.push('? can only be specfied for Day-of-Month -OR- Day-of-Week') | ||
if(isInvalidValues(dayOfWeek, dayOfMonth) && !isHasErrorMsg(errorMsg)) { | ||
errorMsg.push(CONSTANTS.ERROR_MSGES.DAY_OF_MONTH_DAY_OF_WEEK_ERROR_MSG); | ||
} else { | ||
@@ -324,2 +356,3 @@ errorMsg.push(CONSTANTS.ERROR_MSGES.DAY_OF_MONTH_ERROR_MSG_1); | ||
}) | ||
} | ||
} | ||
{ | ||
"name": "cron-expression-validator", | ||
"version": "1.0.11", | ||
"version": "1.0.13", | ||
"description": "Validate cron expressions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19568
342