npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

friendly-node-cron

v1.5.0

Published

Friendlier, human readable expressions for node-cron

Downloads

671

Readme

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