Gathering detailed insights and metrics for cron-parser
Gathering detailed insights and metrics for cron-parser
Gathering detailed insights and metrics for cron-parser
Gathering detailed insights and metrics for cron-parser
Node.js library for parsing crontab instructions
npm install cron-parser
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,330 Stars
353 Commits
156 Forks
16 Watching
5 Branches
46 Contributors
Updated on 19 Nov 2024
Minified
Minified + Gzipped
JavaScript (93.19%)
TypeScript (6.81%)
Cumulative downloads
Total Downloads
Last day
-4.6%
749,442
Compared to previous day
Last week
1.2%
3,966,926
Compared to previous week
Last month
12.1%
16,602,579
Compared to previous month
Last year
30.7%
157,913,153
Compared to previous year
Node.js library for parsing and manipulating crontab instructions. It includes support for timezones and DST transitions.
Compatibility
Node >= 12.0.0
TypeScript >= 4.2
1npm install cron-parser
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31, L)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, optional)
Supports mixed use of ranges and range increments (W character not supported currently). See tests for examples.
Simple expression.
1var parser = require('cron-parser'); 2 3try { 4 var interval = parser.parseExpression('*/2 * * * *'); 5 6 console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET) 7 console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:44:00 GMT+0200 (EET) 8 9 console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET) 10 console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:40:00 GMT+0200 (EET) 11} catch (err) { 12 console.log('Error: ' + err.message); 13} 14
Iteration with limited timespan. Also returns ES6 compatible iterator (when iterator flag is set to true).
1var parser = require('cron-parser'); 2 3var options = { 4 currentDate: new Date('Wed, 26 Dec 2012 12:38:53 UTC'), 5 endDate: new Date('Wed, 26 Dec 2012 14:40:00 UTC'), 6 iterator: true 7}; 8 9try { 10 var interval = parser.parseExpression('*/22 * * * *', options); 11 12 while (true) { 13 try { 14 var obj = interval.next(); 15 console.log('value:', obj.value.toString(), 'done:', obj.done); 16 } catch (e) { 17 break; 18 } 19 } 20 21 // value: Wed Dec 26 2012 14:44:00 GMT+0200 (EET) done: false 22 // value: Wed Dec 26 2012 15:00:00 GMT+0200 (EET) done: false 23 // value: Wed Dec 26 2012 15:22:00 GMT+0200 (EET) done: false 24 // value: Wed Dec 26 2012 15:44:00 GMT+0200 (EET) done: false 25 // value: Wed Dec 26 2012 16:00:00 GMT+0200 (EET) done: false 26 // value: Wed Dec 26 2012 16:22:00 GMT+0200 (EET) done: true 27} catch (err) { 28 console.log('Error: ' + err.message); 29} 30
Timezone support
1var parser = require('cron-parser'); 2 3var options = { 4 currentDate: '2016-03-27 00:00:01', 5 tz: 'Europe/Athens' 6}; 7 8try { 9 var interval = parser.parseExpression('0 * * * *', options); 10 11 console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 01:00:00 GMT+0200 12 console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 02:00:00 GMT+0200 13 console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 04:00:00 GMT+0300 (Notice DST transition) 14} catch (err) { 15 console.log('Error: ' + err.message); 16}
Manipulation
1var parser = require('cron-parser'); 2 3var interval = parser.parseExpression('0 7 * * 0-4'); 4var fields = JSON.parse(JSON.stringify(interval.fields)); // Fields is immutable 5fields.hour = [8]; 6fields.minute = [29]; 7fields.dayOfWeek = [1,3,4,5,6,7]; 8var modifiedInterval = parser.fieldsToExpression(fields); 9var cronString = modifiedInterval.stringify(); 10console.log(cronString); // "29 8 * * 1,3-7"
currentDate
and endDate
accept string
, integer
and Date
as input.
In case of using string
as input, not every string format accepted
by the Date
constructor will work correctly.
The supported formats are:
The reason being that those are the formats accepted by the
luxon
library which is being used to handle dates.
Using Date
as an input can be problematic specially when using the tz
option. The issue being that, when creating a new Date
object without
any timezone information, it will be created in the timezone of the system that is running the code. This (most of times) won't be what the user
will be expecting. Using one of the supported string
formats will solve the issue(see timezone example).
utc
is enabledThis library supports parsing the range 0L - 7L
in the weekday
position of
the cron expression, where the L
means "last occurrence of this weekday for
the month in progress".
For example, the following expression will run on the last monday of the month at midnight:
0 0 0 * * 1L
The library also supports combining L
expressions with other weekday
expressions. For example, the following cron will run every Monday as well
as the last Wednesday of the month:
0 0 0 * * 1,3L
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
9 existing vulnerabilities detected
Details
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
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 2024-11-18
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