Cronverter is a utility tool designed to convert crontab entries to and from JSON format. This tool provides a convenient way to work with crontab schedules in a structured and easily manipulatable format like JSON.
- Convert a crontab string to an array of JSON objects.
- Convert an array of JSON objects to a crontab string.
- Validate the format of the crontab and JSON inputs to ensure accuracy.
- Package manager pnpm, safe and fast
- Bundle with tsup
- Test with Vitest
You can install Cronverter via npm or yarn:
npm i cronverter
or
yarn add cronverter
Import Cronverter
in your JavaScript or TypeScript project:
import CrontabConverter from 'cronverter';
const crontab = `0 5 * * * /path/to/command1
30 6 * * * /path/to/command2
15 14 1 * * /path/to/command3`;
const json = CrontabConverter.crontabToJson(crontab);
console.log(json);
Output:
[
{ "schedule": "0 5 * * *", "task": "/path/to/command1" },
{ "schedule": "30 6 * * *", "task": "/path/to/command2" },
{ "schedule": "15 14 1 * *", "task": "/path/to/command3" }
]
const json = [
{ "schedule": "0 5 * * *", "task": "/path/to/command1" },
{ "schedule": "30 6 * * *", "task": "/path/to/command2" },
{ "schedule": "15 14 1 * *", "task": "/path/to/command3" }
];
const crontab = CrontabConverter.jsonToCrontab(json);
console.log(crontab);
Output:
0 5 * * * /path/to/command1
30 6 * * * /path/to/command2
15 14 1 * * /path/to/command3
Contributions to Cronverter are welcome. Please feel free to submit pull requests or create issues for bugs and feature requests.