Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down