JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21439
  • Score
    100M100P100Q147326F
  • License ISC

Validate cron expressions

Package Exports

  • cron-expression-validator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cron-expression-validator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

typescript

cron-expression-validator

cron-expression-validator is a Node.JS library (support typescript) to validate quartz cron expressions

Installation

npm install cron-expression-validator

Usage

isValidCronExpression method reqire string (cron expression) as parameter and returns boolean value

var cronValidator = require('cron-expression-validator');
var isValid = cronValidator.isValidCronExpression("* * * * * ? *"); // returns true
if(cronValidator.isValidCronExpression("* * * * * ? *")) { // returns true
    // Your code
}
if(cronValidator.isValidCronExpression("* * * * * * *")) { 
    // returns false
}

Optional second param if you want to get error message

Can get error message by passing { error: true } as second parameter

if(cronValidator.isValidCronExpression("* * * * 25/2 ? *", {error: true}) {
/** returns {
/* 		isValid: false,
/* 		errorMessage: [ 'Month values must be between 1 and 12' ]
/*	}
**/
}
if(cronValidator.isValidCronExpression("* * * ? * * 123/555", {error: true}) {
/** returns {
/* 		isValid: false,
/* 		errorMessage: [ '(Year) - Unsupported value 123 for field. Possible values are 1970-2099 , - * /',
/*				'(Year) - Expression 555 is not a valid increment value. Accepted values are 0-129' 
/*				]
/*	}
**/
}
if(cronValidator.isValidCronExpression("0 0 12 1/2 * ? *", {error: false}) { // returns true
    // Your code
}

Cron accepted values

Seconds: 0-59 * , -
Minutes: 0-59 * , -
Hours: 0-23 * , -
Day of Month: 1-31 * , - ? L LW
Months: (JAN-DEC or 1-12) * , -	
Day of Week: (SUN-SAT or 1-7) * , L - ? #
Year: 1970-2099 * , -

License

MIT