Skip to main content

semver

$semver

Validates that a string is a valid semantic version per the semver 2.0.0 spec.

Parameters

  • in (string, optional): Semver range expression. Supports comparators (>=1.0.0, <2.0.0), caret (^1.2.3), tilde (~1.2.3), and space-separated AND (>=1.0.0 <2.0.0).
  • min (string, optional): Minimum version (inclusive).
  • max (string, optional): Maximum version (inclusive).

Use either in OR min/max, not both.

Example

// Format-only validation
new Schema('string').validator('$semver')

// Caret range (positional `in`)
new Schema('string').validator({$semver: '^1.2.0'})

// Tilde range
new Schema('string').validator({$semver: '~1.2.0'})

// Comparator range
new Schema('string').validator({$semver: '>=1.0.0 <2.0.0'})

// Explicit min/max (inclusive)
new Schema('string').validator({$semver: {min: '1.0.0', max: '2.0.0'}})