Skip to content

feat(isCron): add cron expression validator - #2837

Open
Dueen wants to merge 3 commits into
validatorjs:masterfrom
Dueen:feat/is-cron-validator
Open

feat(isCron): add cron expression validator#2837
Dueen wants to merge 3 commits into
validatorjs:masterfrom
Dueen:feat/is-cron-validator

Conversation

@Dueen

@Dueen Dueen commented Aug 5, 2026

Copy link
Copy Markdown

Summary

  • add an isCron validator for common five-field Unix cron expressions
  • support lists, ranges, positive steps, month and weekday names, and standard aliases
  • optionally accept a leading seconds field with { allow_seconds: true }
  • document the supported dialect and add focused valid/invalid coverage

Motivation

Closes #2301.

This follows the discussion in #2301 and the earlier attempt in #2306. The validator defaults to the common five-field Unix format and keeps the six-field leading-seconds form opt-in so it does not silently mix Unix and Quartz cron dialects. Quartz-only tokens such as ?, L, W, and # are intentionally rejected.

Validation

  • npm test (build, lint, and 325 passing tests)

References

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

Comment thread src/lib/isCron.js Fixed
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d4e02ee) to head (58b1d46).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2837   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       115    +1     
  Lines         2598      2662   +64     
  Branches       658       676   +18     
=========================================
+ Hits          2598      2662   +64     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Dueen
Dueen marked this pull request as ready for review August 5, 2026 10:06
@rubiin
rubiin requested a lite review from Copilot August 5, 2026 11:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new public validator, isCron, to validator.js for validating common five-field Unix cron expressions (with optional opt-in support for a leading seconds field), and documents/validates the supported dialect.

Changes:

  • Added src/lib/isCron.js implementing cron parsing/validation (lists, ranges, positive steps, month/weekday names, and standard @... aliases).
  • Exported the new validator via src/index.js so it becomes part of the public API.
  • Added focused unit tests and README documentation for the new validator.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/validators/isCron.test.js Adds valid/invalid coverage for 5-field cron, aliases, optional seconds field, and a performance-regression guard.
src/lib/isCron.js Implements isCron validation logic for Unix-style cron expressions and standard aliases.
src/index.js Wires isCron into the public validator export surface.
README.md Documents isCron behavior, supported syntax, and the allow_seconds option.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/validators/isCron.test.js Outdated
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.

Add support for Cron format validation

4 participants