1.0.1 • Published 3 years ago

cron-quartz-validator v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

typescript

cron-quartz-validator

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

Installation

npm install cron-quartz-validator

Usage

test method require string (cron expression) as parameter and returns boolean value

import CronQuartz from "cron-quartz-validator";
const quartzValidator = new CronQuartz("* * * * * ? *");
if (quartzValidator.test()) {
  // returns true
  // Your code
}
if (quartzValidator.test("* * * * * * *")) {
  // returns false
}

Optional second param if you want to get error message

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

if(quartzValidator.test("* * * * 25/2 ? *", { verbose: true }) {
/** returns {
/* 		valid: false,
/* 		errors: [... 
/*    ]
/*	}
**/
}
if(quartzValidator.test("* * * ? * * 123/555", { verbose: true }) {
/** returns {
/* 		valid: false,
/* 		erros: [...
/*		]
/*	}
**/
}
if(quartzValidator.test("0 0 12 1/2 * ? *", { verbose: 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

Based on https://github.com/anushaihalapathirana/cron-expression-validator#readme