https://github.com/rawnly/crontab-sentence
Parse a sentence to cron expression
https://github.com/rawnly/crontab-sentence
cron react regex typescript
Last synced: 21 days ago
JSON representation
Parse a sentence to cron expression
- Host: GitHub
- URL: https://github.com/rawnly/crontab-sentence
- Owner: rawnly
- Created: 2022-03-29T22:51:35.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-23T10:56:25.000Z (about 3 years ago)
- Last Synced: 2025-08-02T11:49:37.887Z (10 months ago)
- Topics: cron, react, regex, typescript
- Language: TypeScript
- Homepage: https://crontab-sentence.fedevitale.dev
- Size: 813 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Crontab Sentence
> A simple function that transforms sentences into cron expressions.
> Sentences syntax is partially inspired by [crontab.guru](https://crontab.guru)
## Installation
```sh
yarn add crontab-sentence
```
## Usage
For syntax reference [check-out tests](/apps/syntax/__tests__/sentence-to-cron.test.ts)
```ts
import { parseSentence } from 'crontab-sentence'
// Weeks aliased to days
console.log(parseSentence('At 23:59 every 2 weeks in March')) //=> 59 23 */14 3 *
console.log(parseSentence('At 23:59 every 14 days in June')) //=> 59 23 */14 6 *
```
### Supported Units
All weekdays and months are supported in both extended and short way (ex: Mon -> Monday, Jan -> January etc)
- **HOURS**
- `hours`
- `hour`
- `hr`
- `hrs`
- **MINUTES**
- `minutes`
- `minute`
- `min`
- `mins`
- `m`
- **WEEKS**
- `weeks`
- `week`
- `wk`
- `wks`
- **MONTHS**
- `months`
- `month`
### Example Sentences
> The module is not case sensitive
- `At 22:00 on Friday`
- `At 22:00 every Monday`
- `At 1pm on Friday`
- `At 12pm on Monday`
- `At 23 every 2 months`
- `Every Tuesday in June`
- `At 23:59 every 14 days in March`
- `At 3pm every 2 weeks in April`
## ⚠️ Disclaimer
This module is not intended to be used in a production environment.
It is buggy and may not correctly parse every "sentence"