Skip to content

Commit 2f4b68d

Browse files
authored
feat(converter): export parseCronString to allow third party use (#78)
1 parent 08782bd commit 2f4b68d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,39 @@ console.log('cron string:', converted)
9393
cron string: '1 2 * * *'
9494
```
9595

96+
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.
97+
98+
```jsx
99+
import { converter } from 'react-js-cron'
100+
101+
const [
102+
minutes,
103+
hours,
104+
daysOfMonth,
105+
months,
106+
daysOfWeek
107+
] = converter.parseCronString('0 2,14 * * 1-5');
108+
109+
console.log('parsed cron:', {
110+
minutes,
111+
hours,
112+
daysOfMonth,
113+
months,
114+
daysOfWeek
115+
})
116+
```
117+
118+
```
119+
parsed cron: {
120+
minutes: [0],
121+
hours: [2, 14],
122+
daysOfMonth: [],
123+
months: [],
124+
daysOfWeek: [1, 2, 3, 4, 5]
125+
}
126+
```
127+
128+
96129
## Examples
97130

98131
Learn more with [dynamic settings](https://xrutayisire.github.io/react-js-cron/?path=/story/reactjs-cron--dynamic-settings).

src/converter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function getPeriodFromCronParts(cronParts: number[][]): PeriodType {
303303
/**
304304
* Parses a cron string to an array of parts
305305
*/
306-
function parseCronString(str: string) {
306+
export function parseCronString(str: string) {
307307
if (typeof str !== 'string') {
308308
throw new Error('Invalid cron string')
309309
}

0 commit comments

Comments
 (0)