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

nl-cron

v0.2.1

Published

Parse natural-language schedule phrases ("every monday at 9am") into 5-field cron expressions. Zero dependencies.

Readme

nl-cron

ci

npm downloads bundle

Parse natural-language schedule phrases into 5-field cron expressions. Zero runtime dependencies.

import { parse } from "nl-cron";

parse("every morning at 9");        // { cron: "0 9 * * *" }
parse("every monday at 3pm");       // { cron: "0 15 * * 1" }
parse("every 5 minutes");           // { cron: "*/5 * * * *" }
parse("the 1st of january");        // { cron: "0 0 1 1 *" }
parse("complete gibberish");        // null

Install

npm install nl-cron

Works with Node 20+, browsers, Bun, Deno. ESM + CJS.

Why

You're building a feature where a user types "every monday at 9am" and you need a cron expression. Most schedule libraries go the other direction (cron → human description). Going human → cron is rarely covered, and when it is, the parser is either too permissive (accepts garbage) or buried inside a 50KB date library.

nl-cron is deliberately predictable:

  • Returns null for anything it can't unambiguously parse — so you can fall back to letting the user paste raw cron without false success.
  • Never throws — safe to call on any string.
  • Zero dependencies, ~250 lines.

Recipes

Two-step form: NL input with cron fallback

import { parse } from "nl-cron";

function userInputToCron(input: string): string | null {
  const r = parse(input);
  if (r) return r.cron;

  // Fall back: treat input as raw cron (validate with cron-describe if needed)
  if (/^[\d*/\-,a-z\s]+$/i.test(input)) return input.trim();
  return null;
}

Reminder app

import { parse } from "nl-cron";

const reminders = [
  "every weekday at 9am",
  "every friday at 5pm",
  "the 1st of every month",  // ← not supported, returns null
];

for (const r of reminders) {
  const parsed = parse(r);
  if (parsed) scheduleJob(parsed.cron, () => notify(r));
  else        console.warn(`could not parse: ${r}`);
}

Multiple days of week

parse("monday, wednesday and friday at 10:30");
// { cron: "30 10 * * 1,3,5" }

parse("every weekday at 9am");
// { cron: "0 9 * * 1-5" }

parse("every weekend at 10");
// { cron: "0 10 * * 0,6" }

Combining with cron-describe for round-trip

import { parse } from "nl-cron";
import { describe } from "cron-describe";

const r = parse(userInput);
if (r) {
  const d = describe(r.cron);
  if (d.valid) confirmWithUser(`I'll schedule "${userInput}" — that means ${d.description}.`);
}

API

parse(input: string, opts?: ParseOptions): { cron: string } | null

Returns a { cron } object for input it can interpret, or null for anything it cannot. Never throws.

The returned cron string is the standard 5-field form: minute hour day-of-month month day-of-week.

Supported forms (case-insensitive)

| Form | Example | Output | |---|---|---| | Aliases | hourly, daily, weekly, monthly, yearly, midnight, noon, annually | 0 * * * *, ... | | Every-N | every 5 minutes, every 2 hours, every 3 days | */5 * * * *, ... | | Every-unit | every minute, every hour, every week, every month, every year | * * * * *, ... | | Named time of day | every morning (9am), every afternoon (3pm), every evening (6pm), every night (10pm) | 0 9 * * *, ... | | Time-only | at 9am, at 14:00, at 9:30pm, at noon, at midnight | 0 9 * * *, ... | | Day-of-week | every monday at 3pm, mon, wed and fri at 10:30 | 0 15 * * 1, ... | | Weekday/weekend | every weekday at 9am, every weekend at 10 | 0 9 * * 1-5, ... | | Calendar date | the 1st of january, the 15th of mar at noon, the 1st of jan, jun and dec at 9am | 0 0 1 1 *, ... |

Day names accepted: full (monday, tuesday, …) and short (mon, tue, tues, wed, thu, thurs, fri, sat, sun). Month names accepted: full and short (jan, feb, …, dec).

ParseOptions

| Field | Type | Default | Meaning | |---|---|---|---| | assume24h | boolean | false | If true, bare at 9 is interpreted as 09:00 (24h). If false, ambiguous bare integers are kept as-is. |

Caveats

  • No DST handling. This is a cron-string generator. Whatever runs the cron handles DST (typically by skipping or duplicating the hour twice a year).
  • No "the Nth weekday of the month". E.g. "the second tuesday of every month" is not supported because plain 5-field cron can't express it. Use cron-next directly or a 6-field Quartz-style cron library if you need this.
  • First-of-each-month abbreviation isn't recognized. Write "the 1st of every month" and you'll get null. Use "the 1st of january, february, march, …" or fall back to raw cron 0 0 1 * *.
  • English-only. No i18n; phrases like "all luni la 9" won't parse.

License

Apache-2.0 © Vlad Bordei