diff --git a/README.md b/README.md index 73e4845..6d8851e 100755 --- a/README.md +++ b/README.md @@ -93,6 +93,39 @@ console.log('cron string:', converted) cron string: '1 2 * * *' ``` +The converter can also be helpful for parsing a string. Note that Sunday is represented as 0 in the output array but can be either 0 or 7 in the cron expression. + +```jsx +import { converter } from 'react-js-cron' + +const [ + minutes, + hours, + daysOfMonth, + months, + daysOfWeek +] = converter.parseCronString('0 2,14 * * 1-5'); + +console.log('parsed cron:', { + minutes, + hours, + daysOfMonth, + months, + daysOfWeek +}) +``` + +``` +parsed cron: { + minutes: [0], + hours: [2, 14], + daysOfMonth: [], + months: [], + daysOfWeek: [1, 2, 3, 4, 5] +} +``` + + ## Examples Learn more with [dynamic settings](https://xrutayisire.github.io/react-js-cron/?path=/story/reactjs-cron--dynamic-settings). diff --git a/src/converter.ts b/src/converter.ts index fcd2061..e7927c1 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -303,7 +303,7 @@ function getPeriodFromCronParts(cronParts: number[][]): PeriodType { /** * Parses a cron string to an array of parts */ -function parseCronString(str: string) { +export function parseCronString(str: string) { if (typeof str !== 'string') { throw new Error('Invalid cron string') }