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

cron-converter

v2.1.0

Published

Cron string converter

Downloads

97,212

Readme

cron-converter

Cron string parser for node and the browser

npm version Build status Coverage Status

Try the online demo and check the source code for the integration.

Install

yarn add cron-converter

or

npm install cron-converter --save

Compatibility

Version 2.1.0 introduces support for the non standard L character which represents the last day of the month. This feature is on by default and can be turned off by setting the enableLastDayOfMonth option to false.

Versions 2.x.x are not backwards compatible with versions 1.x.x.

| | 2.x.x | 1.x.x | | ---- | ------------- | ------------- | | API | Functional | Object-oriented | | Loader | ESM and CommonJS | CommonJS only | | Type definitions | Bundled | Install @types/cron-converter | | Date/time | Luxon | Moment.js | | Tree-shaking | ✅ | ❌ |

Import

import { stringToArray, arrayToString, getSchedule, getUnits } from "cron-converter";

Usage

Convert a string to an array

// Every 10 mins between 9am and 5pm on the 1st of every month
const arr = stringToArray("*/10 9-17 1 * *");

// Prints:
// [
//   [ 0, 10, 20, 30, 40, 50 ],
//   [ 9, 10, 11, 12, 13, 14, 15, 16, 17 ],
//   [ 1 ],
//   [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ],
//   [ 0, 1, 2, 3, 4, 5, 6 ]
// ]
console.log(arr);

Convert an array to a string

const str = arrayToString([[0], [1], [1], [5], [0, 2, 4, 6]]);

// Prints: '0 1 1 5 */2'
console.log(str);

Options

outputMonthNames

Default: false

const arr = [[1], [1], [1], [1, 2, 3], [1, 2, 3]];
const str = arrayToString(arr, { outputMonthNames: true });

// Prints: '1 1 1 JAN-MAR 1-3'
console.log(str);

outputWeekdayNames

Default: false

const arr = [[1], [1], [1], [1, 2, 3], [1, 2, 3]];
const str = arrayToString(arr, { outputWeekdayNames: true });

// Prints: '1 1 1 1-3 MON-WED'
console.log(str);

outputHashes

Default: false

const arr = [[1], [1], [1], [1, 6, 11], [0, 1, 2, 3, 4, 5, 6]];

// Prints: '1 1 1 H/5 H'
console.log(arrayToString(arr, { outputHashes: true }));

enableLastDayOfMonth

Default: true

const arr = [[1], [1], [1], [-1], [1]];

// Prints: '1 1 1 L 1'
console.log(arrayToString(arr, { enableLastDayOfMonth: true }));
const str = '1 1 1 L 1';

// Prints: [[1], [1], [1], [-1], [1]]
console.log(stringToArray(str, { enableLastDayOfMonth: true }));

Get the schedule execution times

// Convert a string to an array
const arr = stringToArray("*/5 * * * *");

// Get the iterator, initialised to now
let schedule = getSchedule(arr);

// Optionally pass a reference `Date` and a `timezone`
let reference = new Date(2013, 2, 8, 9, 32);
schedule = getSchedule(arr, reference, "Europe/London");

// Calls to `.next()` and `.prev()` return a Luxon `DateTime` object

// Prints: '2013-03-08T09:35:00+00:00''
console.log(schedule.next().format());
// Prints: '2013-03-08T09:40:00+00:00''
console.log(schedule.next().format());

// Reset
schedule.reset();

// Prints: '2013-03-08T09:30:00+00:00''
console.log(schedule.prev().format());
// Prints: '2013-03-08T09:25:00+00:00''
console.log(schedule.prev().format());

Get the units configuration

This is useful if you are creating a user interface. See units.ts.

const units = getUnits();

Test and build

git clone https://github.com/roccivic/cron-converter
cd cron-converter
yarn
yarn build
yarn test
yarn coverage