crontext
v0.2.11
Published
Simple utility for parsing human text into a cron schedule.
Downloads
4
Maintainers
Readme
Crontext
:warning: This package is currently under development. Not meant for production use.
Parses natural text to a cron schedule format.
Try it out live here: https://www.crontext.io
npm install crontext
Usage
import { parseText, nextDate } from 'crontext';
const cron = parseText('Every weekday');
// 0 9 * * 1-5
const nextOccurence = nextDate(cron, new Date());
Custom Options
import { parseText } from 'crontext';
parseText('Every Monday', { defaultHour: '8', defaultMinute: '30' });
// 30 8 * * 1
// aka 8:30am every Monday
parseText('Every weekday', { preset: 'system' });
// 0 0 * * 1-5
// 'system' is the same as: { defaultHour: 0, defaultMinute: 0 }
Configuration
All configurations are optional. The default start of day is 9am. A 'weekday' is considered Monday-Friday and 'weekend' is Saturday or Sunday.
| Option | Description | Default |
| --------------- | ------------------------------------------------------------------------------------------------------------------ | ---------------------------- |
| preset
| 'system'
as a preset will use 00:00 as the start of the day. | n/a |
| defaultHour
| What hour should each day start on. This is the default used when using non specific times like 'Every Monday'
| '9'
|
| defaultMinute
| What minute should each day start on. This is the default used when using non specific times like 'Every Monday'
| '0'
|
| startDate
| What starting date to use for relative schedules like "tomorrow"
, "next month"
, etc. | Right now - aka new Date()
|
| startOfWeek
| Which day starts the week. Used for relative schedules like "next week"
| '1'
|
Interested in Contributing? Check out the Contribution guide.