(s: string, min: number, max: number)
| 43 | |
| 44 | // Returns true if s is a valid integer in [min, max] or a valid range "start-end" |
| 45 | const isValidRangeOrNumber = (s: string, min: number, max: number): boolean => { |
| 46 | const dashIdx = s.indexOf('-') |
| 47 | if (dashIdx !== -1) { |
| 48 | const startStr = s.slice(0, dashIdx) |
| 49 | const endStr = s.slice(dashIdx + 1) |
| 50 | if (!/^\d+$/.test(startStr) || !/^\d+$/.test(endStr)) return false |
| 51 | const start = parseInt(startStr, 10) |
| 52 | const end = parseInt(endStr, 10) |
| 53 | return start >= min && start <= max && end >= min && end <= max && start <= end |
| 54 | } |
| 55 | if (!/^\d+$/.test(s)) return false |
| 56 | const n = parseInt(s, 10) |
| 57 | return n >= min && n <= max |
| 58 | } |
| 59 | |
| 60 | // Validate a single cron field: supports *, numbers, ranges (n-m), steps (*/s, n/s, n-m/s), and comma-separated lists. |
| 61 | // When `allowL` is true, also accepts the standalone `L` token (used for the day-of-month field to mean "last day of month"). |
no test coverage detected