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

is-cron

v1.0.0

Published

Check if a string is a valid cron expression

Downloads

93

Readme

is-cron

Check if a string is a valid cron expression

npm version npm downloads bundle size license

A tiny, zero-dependency cron expression validator with TypeScript support.

Features

  • Zero dependencies - No bloat, no security risks
  • Tiny bundle - Less than 1KB minified + gzipped
  • TypeScript first - Full type definitions with type guards
  • ESM & CJS - Works everywhere
  • Standard & extended cron - Supports 5-field and 6-field (with seconds) formats
  • Aliases - Supports month (JAN-DEC) and day (SUN-SAT) aliases
  • Well tested - 100+ test cases covering edge cases from popular cron libraries

Installation

npm install is-cron
yarn add is-cron
pnpm add is-cron

Usage

import isCron from 'is-cron';

// Standard 5-field cron expressions
isCron('* * * * *');           // true - every minute
isCron('0 0 * * *');           // true - daily at midnight
isCron('*/15 * * * *');        // true - every 15 minutes
isCron('0 9-17 * * 1-5');      // true - hourly 9-5 on weekdays
isCron('0 0 1 JAN *');         // true - midnight on January 1st
isCron('0 17 * * FRI');        // true - every Friday at 5 PM

// Invalid expressions
isCron('invalid');             // false
isCron('60 * * * *');          // false - minute out of range
isCron('* * * * * *');         // false - 6 fields without seconds option

With Seconds (6-field format)

import isCron from 'is-cron';

// Enable 6-field format with seconds
isCron('* * * * * *', { seconds: true });     // true
isCron('0 * * * * *', { seconds: true });     // true - every minute at second 0
isCron('*/5 * * * * *', { seconds: true });   // true - every 5 seconds

Disable Aliases

import isCron from 'is-cron';

// Aliases enabled by default
isCron('0 0 * JAN *');                   // true
isCron('0 0 * * MON');                   // true

// Disable aliases for stricter validation
isCron('0 0 * JAN *', { alias: false }); // false
isCron('0 0 * 1 *', { alias: false });   // true

Helper Functions

import { isStandardCron, isExtendedCron } from 'is-cron';

// Standard 5-field cron
isStandardCron('* * * * *');     // true
isStandardCron('* * * * * *');   // false

// Extended 6-field cron with seconds
isExtendedCron('* * * * * *');   // true
isExtendedCron('* * * * *');     // false

TypeScript Type Guard

import isCron, { type CronExpression } from 'is-cron';

function scheduleJob(cron: CronExpression) {
  // ...
}

const userInput: unknown = getUserInput();

if (isCron(userInput)) {
  // TypeScript knows userInput is a valid CronExpression
  scheduleJob(userInput);
}

API

isCron(value, options?)

Check if a value is a valid cron expression.

Parameters

  • value - The value to check (any type)
  • options - Optional configuration object
    • seconds (boolean, default: false) - Enable 6-field format with seconds
    • alias (boolean, default: true) - Allow month/day aliases (JAN-DEC, SUN-SAT)

Returns

boolean - true if the value is a valid cron expression

isStandardCron(value)

Check if a value is a valid standard 5-field cron expression.

isExtendedCron(value)

Check if a value is a valid 6-field cron expression with seconds.

Cron Expression Format

Standard 5-field format

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12 or JAN-DEC)
│ │ │ │ ┌───────────── day of week (0-7 or SUN-SAT, 0 and 7 are Sunday)
│ │ │ │ │
* * * * *

Extended 6-field format (with seconds)

┌───────────── second (0-59)
│ ┌───────────── minute (0-59)
│ │ ┌───────────── hour (0-23)
│ │ │ ┌───────────── day of month (1-31)
│ │ │ │ ┌───────────── month (1-12 or JAN-DEC)
│ │ │ │ │ ┌───────────── day of week (0-7 or SUN-SAT)
│ │ │ │ │ │
* * * * * *

Supported syntax

| Syntax | Description | Example | |--------|-------------|---------| | * | Any value | * * * * * | | , | List separator | 1,15 * * * * | | - | Range | 1-5 * * * * | | / | Step | */15 * * * * | | ? | No specific value (day of month/week only) | 0 0 ? * MON |

License

Apache-2.0