Gathering detailed insights and metrics for cron-validator
Gathering detailed insights and metrics for cron-validator
Gathering detailed insights and metrics for cron-validator
Gathering detailed insights and metrics for cron-validator
npm install cron-validator
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
79 Stars
61 Commits
20 Forks
4 Watching
2 Branches
6 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
5.5%
50,314
Compared to previous day
Last week
-3.6%
240,369
Compared to previous week
Last month
23.3%
1,054,697
Compared to previous month
Last year
69.3%
11,218,072
Compared to previous year
7
Cron Validator is a util that allows you to validate a cron expression, similar to what crontab guru does, but in your code base.
npm install cron-validator
Require syntax:
1const cron = require('cron-validator'); 2 3if (cron.isValidCron('* * * * *')) { 4 // Do something 5}
Or import syntax with TypeScript:
1import { isValidCron } from 'cron-validator' 2 3if (isValidCron('* * * * *')) { 4 // Do something 5}
Support for seconds can be enabled by passing the seconds
flag as true in options:
1const cron = require('cron-validator'); 2 3cron.isValidCron('* * * * * *'); 4// false 5 6cron.isValidCron('* * * * * *', { seconds: true }); 7// true
The same goes to enable the alias
support for months and weekdays:
1const cron = require('cron-validator'); 2 3cron.isValidCron('* * * * mon'); 4// false 5 6cron.isValidCron('* * * * mon', { alias: true }); 7// true
Likewise, the allowBlankDay
flag can be enabled to mark days or weekdays blank with a ?
symbol:
1const cron = require('cron-validator'); 2 3cron.isValidCron('* * * * ?'); 4// false 5 6cron.isValidCron('* * * * ?', { allowBlankDay: true }); 7// true
The allowSevenAsSunday
flag can be enabled to enable support for digit 7 as Sunday:
1const cron = require('cron-validator'); 2 3cron.isValidCron('* * * * 7'); 4// false 5 6cron.isValidCron('* * * * 7', { allowSevenAsSunday: true }); 7// true
The allowNthWeekdayOfMonth
flag can be enabled to enable expressions denoting n-th weekday of the month:
1const cron = require('cron-validator'); 2 3cron.isValidCron('* * * * tue#2'); 4// false 5 6cron.isValidCron('* * * * tue#2', { allowNthWeekdayOfMonth: true }); // second Tuesday of each month 7// true
?
symbol.TUE#2
Many great cron libraries already exists on NPM, why this one?
Libraries like node-cron are primarily made to schedule jobs using a cron expression, not validate those cron expressions. They come with additional behaviors not always required. They also bring their own set of defaults which might be in conflicts with the defaults of other external systems. We needed something to validate an expression before sending it off to an external system, so we created this to be a little more strict and configurable, with a more specific behavior.
We decided to go for the naive approach first, which results in lenghty code and tests, but also making it easier to reason about cron expressions and their specific rules.
No vulnerabilities found.
No security vulnerabilities found.