Gathering detailed insights and metrics for cron-validate
Gathering detailed insights and metrics for cron-validate
Gathering detailed insights and metrics for cron-validate
Gathering detailed insights and metrics for cron-validate
cron-expression-validator
Validate cron expressions
@lobaro/lobaro-cron-validate
lobaro modifyed cron-validate is a cron-expression validator written in TypeScript.
aws-cron-validate
cron-expression validator written in TypeScript.
cron-input-ui
Input component to generate cron expressions easily and intuitively
A cron-expression validator for TypeScript/JavaScript projects.
npm install cron-validate
Typescript
Module System
Node Version
NPM Version
TypeScript (99.81%)
JavaScript (0.19%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
75 Stars
425 Commits
15 Forks
1 Watchers
14 Branches
9 Contributors
Updated on May 13, 2025
Latest Version
1.5.2
Package Id
cron-validate@1.5.2
Unpacked Size
63.13 kB
Size
13.56 kB
File Count
29
NPM Version
10.9.2
Node Version
23.3.0
Published on
Mar 14, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
22
Cron-validate is a cron-expression validator written in TypeScript. The validation options are customizable and cron fields like seconds and years are supported.
Package is available on npm:
npm install -S cron-validate
1import cron from 'cron-validate' 2 3const cronResult = cron('* * * * *') 4if (cronResult.isValid()) { 5 // !cronResult.isError() 6 // valid code 7} else { 8 // error code 9}
The cron
function returns a Result-type, which is either Valid<T, E>
or Err<T, E>
.
For checking the returned result, just use result.isValid()
or result.isError()
Both result types contain values:
1import cron from 'cron-validate' 2 3const cronResult = cron('* * * * *') 4if (cronResult.isValid()) { 5 const validValue = cronResult.getValue() 6 7 // The valid value is a object containing all cron fields 8 console.log(validValue) 9 // In this case, it would be: 10 // { seconds: undefined, minutes: '*', hours: '*', daysOfMonth: '*', months: '*', daysOfWeek: '*', years: undefiend } 11} else { 12 const errorValue = cronResult.getError() 13 14 // The error value contains an array of strings, which represent the cron validation errors. 15 console.log(errorValue) // string[] of error messages 16}
Make sure to test the result type beforehand, because getValue()
only works on Valid
and getError()
only works on Err
. If you don't check, it will throw an error.
For further information, you can check out https://github.com/gDelgado14/neverthrow, because I used and modified his code for this package. (Therefor not every documented function on his package is available on this package.)
To configure the validator, cron-validate uses a preset system. There are already defined presets (default, npm-node-cron or aws), but you can also define your own preset to use for your system. You can also use the override property to set certain option on single cron validates.
The following presets are already defined by cron-validate:
To select a preset for your validation, you can simply do this:
1cron('* * * * *', { 2 preset: 'npm-cron-schedule', 3})
To define your own preset, use this:
1registerOptionPreset('YOUR-PRESET-ID', { 2 presetId: 'YOUR-PRESET-ID', 3 useSeconds: false, 4 useYears: false, 5 useAliases: false, // optional, default to false 6 useBlankDay: false, 7 allowOnlyOneBlankDayField: false, 8 allowStepping: true, // optional, defaults to true 9 mustHaveBlankDayField: false, // optional, default to false 10 useLastDayOfMonth: false, // optional, default to false 11 useLastDayOfWeek: false, // optional, default to false 12 useNearestWeekday: false, // optional, default to false 13 useNthWeekdayOfMonth: false, // optional, default to false 14 seconds: { 15 minValue: 0, 16 maxValue: 59, 17 lowerLimit: 0, // optional, default to minValue 18 upperLimit: 59, // optional, default to maxValue 19 }, 20 minutes: { 21 minValue: 0, 22 maxValue: 59, 23 lowerLimit: 0, // optional, default to minValue 24 upperLimit: 59, // optional, default to maxValue 25 }, 26 hours: { 27 minValue: 0, 28 maxValue: 23, 29 lowerLimit: 0, // optional, default to minValue 30 upperLimit: 23, // optional, default to maxValue 31 }, 32 daysOfMonth: { 33 minValue: 1, 34 maxValue: 31, 35 lowerLimit: 1, // optional, default to minValue 36 upperLimit: 31, // optional, default to maxValue 37 }, 38 months: { 39 minValue: 0, 40 maxValue: 12, 41 lowerLimit: 0, // optional, default to minValue 42 upperLimit: 12, // optional, default to maxValue 43 }, 44 daysOfWeek: { 45 minValue: 1, 46 maxValue: 7, 47 lowerLimit: 1, // optional, default to minValue 48 upperLimit: 7, // optional, default to maxValue 49 }, 50 years: { 51 minValue: 1970, 52 maxValue: 2099, 53 lowerLimit: 1970, // optional, default to minValue 54 upperLimit: 2099, // optional, default to maxValue 55 }, 56})
The preset properties explained:
presetId: string
useSeconds: boolean
useYears: boolean
useAliases: boolean
useBlankDay: boolean
allowOnlyOneBlankDayField: boolean
allowStepping: boolean
mustHaveBlankDayField: boolean
allowOnlyOneBlankDayField
, it means that there will always be either day or day of week as ?
useLastDayOfMonth: boolean
L-2
would me the 2nd to last day of the month.useLastDayOfWeek: boolean
5L
would mean the last friday of the month.useNearestWeekday: boolean
15W
would mean the weekday (mon-fri) closest to the 15th when the 15th is on sat-sun.useNthWeekdayOfMonth: boolean
6#3
would mean the 3rd friday of the month (assuming 6 = friday).minValue: number
maxValue: number
lowerLimit?: number
upperLimit?: number
If you want to override a option for single cron validations, you can use the override
property:
1console.log(cron('* * * * * *', { 2 preset: 'default', // second field not supported in default preset 3 override: { 4 useSeconds: true // override preset option 5 } 6})) 7 8console.log(cron('* 10-20 * * * *', { 9 preset: 'default', 10 override: { 11 minutes: { 12 lowerLimit: 10, // override preset option 13 upperLimit: 20 // override preset option 14 } 15 } 16}))
1import cron from 'cron-validate' 2 3console.log(cron('* * * * *').isValid()) // true 4 5console.log(cron('* * * * *').isError()) // false 6 7console.log(cron('* 2,3,4 * * *').isValid()) // true 8 9console.log(cron('0 */2 */5 * *').isValid()) // true 10 11console.log(cron('* * * * * *', { override: { useSeconds: true } }).isValid()) // true 12 13console.log(cron('* * * * * *', { override: { useYears: true } }).isValid()) // true 14 15console.log( 16 cron('30 * * * * *', { 17 override: { 18 useSeconds: true, 19 seconds: { 20 lowerLimit: 20, 21 upperLimit: 40, 22 }, 23 }, 24 }).isValid() 25) // true 26 27console.log( 28 cron('* 3 * * *', { 29 override: { 30 hours: { 31 lowerLimit: 0, 32 upperLimit: 2, 33 }, 34 }, 35 }).isValid() 36) // false 37 38console.log( 39 cron('* * ? * *', { 40 override: { 41 useBlankDay: true, 42 }, 43 }).isValid() 44) // true 45 46console.log( 47 cron('* * ? * ?', { 48 override: { 49 useBlankDay: true, 50 allowOnlyOneBlankDayField: true, 51 }, 52 }).isValid() 53) // false
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/8 approved changesets -- score normalized to 5
Reason
5 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More