JSPM

croner

1.0.9
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2360696
  • Score
    100M100P100Q198249F
  • License MIT

Isomorphic JavaScript cron parser and scheduler.

Package Exports

  • croner

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (croner) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Croner

Build status npm version

Pure JavaScript Isomorphic cron parser and scheduler without dependencies.

Installation

Node.js

npm install croner

Browser (AMD and regular usage)

Download lib/croner.js and import with script-tag or AMD as usual.

Usage

var o = cron( <string pattern> );
o.next( [ <date previous> ] );
o.msToNext();
var job = o.schedule( [ { startAt: <date>, stopAt: <date>, maxRuns: <integer> } ,] callback);
job.pause();
job.resume();
job.stop();

Examples

Parsing only

// Parse 14:00:00 at next sunday
var parser = cron('0 0 14 * * 7');

// Log the actual date object of next run
console.log(parser.next());

// Log number of milliseconds to next run
console.log(parser.msToNext());`

Basic scheduling

// Run every minute
var scheduler = cron('0 * * * * *');

scheduler.schedule(function() {
    console.log('This will run every minute.');
});

Scheduling with options

// Run every minute
var scheduler = cron('0 * * * * *');

// Schedule with options (all options are optional)
scheduler.schedule({ maxRuns: 5 }, function() {
    console.log('This will run every minute.');
});

Pattern

┌──────────────── sec (0 - 59)
│ ┌────────────── min (0 - 59)
│ │ ┌──────────── hour (0 - 23)
│ │ │ ┌────────── day of month (1 - 31)
│ │ │ │ ┌──────── month (1 - 12)
│ │ │ │ │ ┌────── day of week (0 - 6) 
│ │ │ │ │ │       (0 to 6 are Sunday to Saturday; 7 is Sunday, the same as 0)
│ │ │ │ │ │
* * * * * *

License

MIT