feat: cron.parse and cron.validateDetailed (expression introspection) by merencia · Pull Request #548 · node-cron/node-cron · GitHub
Skip to content

feat: cron.parse and cron.validateDetailed (expression introspection)#548

Merged
merencia merged 1 commit into
mainfrom
feat/expression-introspection
Jun 17, 2026
Merged

feat: cron.parse and cron.validateDetailed (expression introspection)#548
merencia merged 1 commit into
mainfrom
feat/expression-introspection

Conversation

@merencia

Copy link
Copy Markdown
Member

Phase 1 — expression introspection (DX / tooling).

  • cron.validateDetailed(expression){ valid, fields?, errors }. Unlike validate() (boolean), it collects every problem with { field, value, message }, and returns the decomposed fields when valid.
  • cron.parse(expression) → the decomposed fields ({ second, minute, hour, dayOfMonth, month, dayOfWeek }), or throws with a useful message (which field, which value) for the first problem.

Both reuse the existing per-field validators — validate() (boolean) is untouched, so no behavior change there. Handles 5/6-field forms, the L token in day-of-month, illegal characters, wrong field count, and non-string input.

cron.validateDetailed('0 30 9 * * 1-5');
// { valid: true, fields: { ..., dayOfWeek: [1,2,3,4,5] }, errors: [] }

cron.validateDetailed('99 * * * * *');
// { valid: false, errors: [{ field: 'second', value: '99', message: '99 is a invalid expression for second' }] }

cron.parse('0 30 9 * * *'); // { second:[0], minute:[30], hour:[9], ... }

New exported types: ParsedFields, DetailedValidation, CronFieldError. Full suite green (327 tests).

Expression introspection for tooling and DX:

- `cron.validateDetailed(expression)` returns `{ valid, fields?, errors }`,
  collecting every problem (field name, offending value, reason) instead of a
  plain boolean — and the decomposed fields when valid.
- `cron.parse(expression)` returns the decomposed fields or throws with a
  useful message for the first problem.

Both reuse the existing per-field validators; `validate()` (boolean) is
unchanged.
@merencia merencia merged commit cbe36bc into main Jun 17, 2026
6 checks passed
@merencia merencia mentioned this pull request Jun 18, 2026
merencia added a commit that referenced this pull request Jun 18, 2026
Promote the Unreleased section to 4.4.0 and bump the version.

Highlights (all additive, backwards-compatible):
- Task introspection: getNextRuns, match, msToNext, isBusy, runsLeft, getPattern (#547)
- cron.parse and cron.validateDetailed (#548)
- Distributed run coordination: distributed:true + NODE_CRON_RUN default + RunCoordinator (#549)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant