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

dx-cron-builder

v0.3.1

Published

simple API for building cron expressions

Downloads

3

Readme

Build Status

cron-builder

The software utility cron is a time-based scheduler in Unix-like computer operating systems. A user may use cron to schedule jobs (commands or scripts) to run periodically at fixed times, dates, or intervals. A cron statement is composed of 5 fields separated by white space. The * character translates to "every", ie: "every minute" or "every day of the week".

cron-builder will manage the state of a cron expression, allowing a user to manipulate it through a simple API. It is decoupled from the DOM and doesn't have an opinion about where it's being called from. cron-builder considers this article its source of truth.

Install

cron-builder is available on npm and bower:

npm install cron-builder --save

or

bower install cron-builder --save

After installing, just require the package as you normally would:

var cb = require('/path/to/cron-builder.js');

API

To instantiate the cron builder:

// (default expression is set to "* * * * *")
var cronExp = new cb();

// optionally, pass in a cron expression to override the default:
var myCronExp = new cb('5 12 * * 1-5')

To return the cron expression at any given time:

cronExp.build();
// '* * * * *'

API includes basic getters and setters:

cronExp.get('minute');
// '*'
cronExp.set('minute', '5,35');
// '5,35'
cronExp.get('minute');
// '5,35'
cronExp.build();
// '5,35 * * * *'

Or if you'd prefer to add or remove values one at a time, use addValue and removeValue. These methods build or take away from what is currently set:

cronExp.addValue('hour', '2');
cronExp.addValue('monthOfTheYear', '4');
cronExp.addValue('monthOfTheYear', '10');
cronExp.build();
// '5,35 2 * 4,10 *'

cronExp.removeValue('minute', '5');
cronExp.build();
// '35 2 * 4,10 *'

If you prefer to work with the expression object directly, use getAll and setAll:

var exp = cronExp.getAll();
// {minute: ['35'], hour: ['2'], dayOfTheMonth: ['*'], monthOfTheYear: ['4','10'], ...}
exp.dayOfTheMonth = ['7','14','21','28'];
cronExp.setAll(exp);
cronExp.build();
// '35 2 7,14,21,28 4,10 *'
Notes:
  • cron-builder does not currently support using / syntax to indicate values that are repeated. Instead of using */15, use the verbose form 0,15,30,45.
  • cron-builder requires using numeric representations of days of the week and months of the year. So instead of using Feb,Mar,Apr just use 2,3,4.

Contribute

Easy!

npm install
npm test

Pull requests and issues appreciated!

TODO

  • more validation for things like adding values that are already included in a range, better range validations...
  • sorting of values for a given measure of time

License

The MIT License (MIT)