New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

friendly-node-cron

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

friendly-node-cron

Friendlier, human readable expressions for node-cron

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Friendly Node Cron

semantic-release publish

NPM

Friendlier, human readable expressions for node-cron
Cron Expressions are doublechecked with crontab.guru

Inspired by https://github.com/jkriss/friendly-cron

How to install:

npm install friendly-node-cron

Usage:

const translate = require('friendly-node-cron');
const cron = require('node-cron');

cron.schedule(translate('at 9:04:52 every mondays in december'), () => {
  console.log('running job...')
});
// Generated Expression: 52 4 9 * 12 1

cron.schedule(translate('on mondays in december all 15 minutes'), () => {
  console.log('running job...')
});
// Generated Expression: 0 */15 * * 12 1

translate('invalid expr');
// returns null
// Also all Patterns which are resulting in '* * * * * *' will automatically return null.

Tested complex examples

Look into ./test.js for more examples and the parsed cron expressions.

at 00:00 on dec 24
every 20 seconds mondays tuesdays wednesdays
at 13:37 on fridays tuesdays and thursdays
At 12:10 on Monday and Tuesday in December
onN saturDas In deCmbeR aT 06:01
at 9:04:52 every mondays in december
on saturdays every 10 minutes
very mondays in december all 15 minutes
on jan feb mar only mondays tuesdays and saturdays at 9:30
every 15 minutes from 5 through 15 of december and january
on march and april from 15 through 25 on every 2 hours
weekly in 15 minute intervals on january
quarterly at 9:30 on mondays

Speech Rules

Days:

Days will always translate in numbers. weekends translates to 6,0 and workdays will translate to 1-5.

You can also write the full words like on saturday at 9:30

Tokens

mon, tue, wed, thu, fri, sat, sun, weekends, workdays

Examples:

on mon tue wed every 15 minutes
in december on mondays and saturdays at 9:30
on mondays at 10:30

Dates/Months:

You can either use exact dates like in dec 9 at 9:30 or only months in dec at 9:30
You can also write the full words like in december at 9:30
Multiple Months are supported
You can also use the expression from <num> through <num> to define a day interval

Tokens

jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
from <num> through <num>

Examples:

on jan feb mar only mondays tuesdays and saturdays at 9:30
on dec mar apr at 13:37
on march and april from 15 through 25 on every 2 hours

Times:

Times will get sanitized and seconds are optional, to use times the token at is needed. Timeformat is 24 hours and not AM/PM.

Examples:

every saturday at 10:32:32
in december on mondays and fridays at 08:05:01
at 18:15 on fri mon tue wed

Intervals:

Be sure when you want to use intervals that you dont use the at token in your expression.

Tokens:

second, minute, hour, day, month

Examples:

on Saturdays every 15 minutes
on december every 1 hour
every 12 hours

Special Tokens

Yearly

Always will run on first of january at 0:00 if no time is given.
Weekdays are not possible with this expression and will be overwritten.

Examples:

yearly
yearly at 9:30

Weekly

Weekly will run on every 7th day of month (*/7) at 0:00 if no time is given.
Weekdays are not possible with this expression and will be overwritten.

Examples:

weekly at 9:30
weekly in 15 minute intervals on january

Monthly

Monthly will run on every first day of month (*/1) at 0:00 if no time or day is given. Weekdays are possible

Examples:

monthly on fidays at 9:30
monthly at 10:30
monthly in 30 minute intervals

Quarterly

Quarterly will run on every 3rd month of year (*/3) at 0:00 if no time is given.
Weekdays are possible

Examples:

quarterly at 9:30
quarterly at 9:30 on mondays

Keywords

FAQs

Package last updated on 04 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc