Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to validate a cron expression using Later.js

Tags:

javascript

I want to validate a cron expression using javascript. Here is a library that deals with cron expression http://bunkat.github.io/later/

From the documentation I am not able to found how to validate a cron expression. Whatever I am passing to var cronSched = later.parse.cron('$%#'); Its always filling cronSched with an object. So How to get some true/false value for a cron expression?

like image 985
FarazShuja Avatar asked Feb 15 '26 11:02

FarazShuja


1 Answers

Had the same needs and this tool appears to handle the job:

https://github.com/harrisiirak/cron-parser

Here is an solution, using lodash:

try{
    var validacao = cronParse.parseString(valor.cron);
    if (_.isEmpty(validacao.errors)){
        return true;
    }
    throw "Invalid Cron!"
}
catch(ex){
    return false;
}

Then you can test your return value to fullfill your needs. Hope it helps!

like image 156
netrevisanto Avatar answered Feb 17 '26 00:02

netrevisanto