mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
fix(Cron Generator): better cron validation
Double check with cron-parser and cronstrue for cron expresson validity Fix #26
This commit is contained in:
1 parent
0a0ebddb5d
commit
22f2ce661e
2 files changed
+3
No files matched your search
@@ -33,6 +33,7 @@ describe('crontab-generator', () => {
|
||||
it('should return false for all invalid formats', () => {
|
||||
expect(isCronValid('aert')).toBe(false);
|
||||
expect(isCronValid('40 *')).toBe(false);
|
||||
expect(isCronValid('* * * *')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { parseExpression } from 'cron-parser';
|
||||
import cronstrue from 'cronstrue';
|
||||
import EventCronParser from 'event-cron-parser';
|
||||
|
||||
export type CronType = 'standard' | 'aws';
|
||||
@@ -32,6 +33,7 @@ export function isCronValid(cronExpression: string, cronType: CronType | 'any' =
|
||||
export function getCronType(cronExpression: string) {
|
||||
try {
|
||||
parseExpression(cronExpression);
|
||||
cronstrue.toString(cronExpression, { throwExceptionOnParseError: true });
|
||||
return 'standard';
|
||||
}
|
||||
catch (_) {
|
||||
|
||||
Reference in new issue
Block a user