Skip to content

rheatkhs/cronwise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cronwise

A small, focused TypeScript library that validates standard 5-field cron expressions and converts supported patterns into human-readable English.

Installation

npm install cronwise

Features

  • Validates standard 5-field cron expressions (minute, hour, day-of-month, month, day-of-week).
  • Provides human-readable descriptions of supported cron expressions.
  • Zero dependencies. Lightweight and fast.
  • Written in TypeScript, with great TS support.
  • Fully tested.

Supported Syntax (v1)

cronwise currently supports standard 5-field cron expressions with the following field syntax:

  • * (every value)
  • Exact numerical values (e.g., 0, 15)
  • Step values (e.g., */15)

Unsupported Syntax

The following syntax is intentionally not supported in v1:

  • Ranges (e.g., 1-5)
  • Lists (e.g., 1,2,3)
  • Named months (e.g., JAN)
  • Named weekdays (e.g., MON)
  • 6-field or 7-field cron syntax (seconds or years)
  • Timezone handling

Usage

Validation

import { validateCron } from 'cronwise';

const result = validateCron('0 9 * * 1');
console.log(result.valid); // true
console.log(result.errors); // []

const invalid = validateCron('60 * * * *');
console.log(invalid.valid); // false
console.log(invalid.errors); // ["Minute must be between 0 and 59, or '*'"]

Explanation

import { explainCron } from 'cronwise';

console.log(explainCron('*/15 * * * *')); 
// "Every 15 minutes"

console.log(explainCron('0 9 * * *')); 
// "Every day at 09:00"

console.log(explainCron('0 9 * * 1')); 
// "At 09:00 on Monday"

If the cron expression is valid but not supported by the explainer yet, it returns: Valid cron expression, but no human-readable explanation is available yet.

Parsing (Validation + Explanation)

import { parseCron } from 'cronwise';

const result = parseCron('0 9 * * 1');
console.log(result.valid); // true
console.log(result.explanation); // "At 09:00 on Monday"

API

validateCron(expression: string): CronValidationResult

Validates a cron expression and returns a CronValidationResult object.

explainCron(expression: string): string | null

Returns a human-readable string explaining the cron expression. Returns null if invalid 5 fields.

parseCron(expression: string): CronParseResult

Parses and validates a cron expression, and returns the result with an explanation.

License

MIT

About

A small, focused TypeScript library that validates standard 5-field cron expressions and converts supported patterns into human-readable English.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors