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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cron-translate

v2.1.0

Published

Translates text to cron expression

Readme

cron-translate

CI npm version npm downloads types license

Translate plain English into cron expressions.

cron-translate turns the schedule you would describe out loud ("every weekday at 6pm", "every 15 minutes", "last friday of the month") into a 6-field cron expression for node-cron.

Usage

Install cron-translate

npm install --save cron-translate

ESM:

import { toCron } from 'cron-translate';

const cron = toCron('every day at 9am'); // "0 0 9 * * *"

CommonJS:

const { toCron } = require('cron-translate');

const cron = toCron('every day at 9am'); // "0 0 9 * * *"

The package ships both ESM and CommonJS builds plus TypeScript type declarations. Requires Node.js >= 20.

Output

toCron returns a 6-field node-cron expression:

second  minute  hour  day-of-month  month  day-of-week

Day-of-week is 0-6 with 0 = Sunday. Month and weekday names you write in the input are converted to numbers in the output.

Syntax

A schedule is a sentence with one required frequency and optional clauses:

every <frequency> [at <time>] [on <day>] [in <month>]

Frequency

  • every <unit>every minute, every hour, every day, every week, every month, every year
  • every <n> <unit>every 5 minutes, every 2 hours
  • every other <unit>every other day

Time of day

  • 12-hour: at 9am, at 6:30pm
  • 24-hour: at 14:30
  • words: at noon, at midnight
  • day-parts as a whole schedule: every morning, every evening, every night
  • multiple times: at 9am and 5pm
  • hour range: between 9am and 5pm

Days and months

  • weekdays: every monday, on friday, every weekday, every weekend
  • day-of-month: on day 15, the 15th of every month
  • months: in march, every january
  • ordinals (node-cron L / #): last friday of the month, first monday of the month, last day of the month (an every or the prefix works too)

Values, lists, and ranges

Any field can take a single value, a list, or a range. Address a field by name (second, minute, hour, day, month) or by weekday/month name:

| | example | result | |---|---|---| | single | at second 30 | 30 * * * * * | | list | at minutes 0, 15, 30 and 45 | 0 0,15,30,45 * * * * | | range | at minute 1 to 30 | 0 1-30 * * * * | | day range | on day 1 to 10 | 0 0 0 1-10 * * | | month list | in march and june | 0 0 0 1 3,6 * | | weekday range | on monday to friday | 0 0 0 * * 1-5 |

Lists use , / and; ranges use to / through. Names and abbreviations both work (january / jan, monday / mon).

Combining clauses

Clauses for different fields compose:

  • every weekday at 6pm0 0 18 * * 1-5
  • every 5 minutes at 9am0 */5 9 * * *
  • every 30 minutes between 9am and 5pm on weekdays0 */30 9-17 * * 1-5
  • first monday of the month at 9am0 0 9 * * 1#1

Examples

| Input | Cron | |---|---| | every minute | 0 * * * * * | | every 15 minutes | 0 */15 * * * * | | every hour | 0 0 * * * * | | every day at noon | 0 0 12 * * * | | every monday at 9am | 0 0 9 * * 1 | | every weekend | 0 0 0 * * 0,6 | | every january | 0 0 0 1 1 * | | last friday of the month | 0 0 0 * * 5L |

Reverse: describe a cron expression

toHuman goes the other way, turning a cron expression (5 or 6 fields) back into plain English. It's the readback for a toCron call: "you wrote X, here is the cron, which reads as Y."

import { toHuman } from 'cron-translate';

toHuman('0 0 9 * * *');        // "at 9am"
toHuman('0 0 18 * * 1-5');     // "at 6pm on monday to friday"
toHuman('0 */5 9 * * *');      // "every 5 minutes at 9am"
toHuman('0 0 0 * * 5L');       // "last friday of the month"

The output is phrased so that toCron parses it back to the same expression: toCron(toHuman(cron)) returns the original cron. The English may read differently from the phrase you started with, but it describes the same schedule.

Errors

toCron throws a CronTranslateError when the phrase can't be turned into a valid cron expression: unrecognized words, malformed input, conflicting values for the same field, or values out of range (minute 0-59, day 1-31, an interval below 1, and so on). The error carries a hint pointing at the node-cron syntax reference.

import { toCron, CronTranslateError } from 'cron-translate';

try {
  toCron('the weekday nearest the 15th');
} catch (err) {
  if (err instanceof CronTranslateError) {
    console.error(err.message, err.hint);
  }
}

Things cron itself (or node-cron) can't express are rejected on purpose rather than guessed: the W nearest-weekday character, counted recurrence (until, for N times), and arbitrary natural language. For those, write the cron directly with the help of the node-cron syntax docs.