Library

semver

Semantic Versioning 2.0.0 + npm-style range matching.

1 file lib/semver/semver.vader 4 exports

Reference specs (locked in 2026-05-26) :

Public surface :

  • Version carries the parsed major.minor.patch[-prerelease][+build].
  • VersionRange carries the parsed range expression.
  • parse / parse_range are the entry points ; both return an explicit T | ParseError union, carrying ParseError (from std/string) on malformed input.
  • Version plugs into std/core::Display, Equals, Comparable: call sites use a.compare(b), a < b, a == b, ${v} (interp).
  • VersionRange plugs into std/core::Contains<Version>: call sites use the infix in operator : v in r desugars to r.contains(v).

Build metadata is excluded from precedence per §10. Range pre-release matching follows node-semver's strict default : a version with a pre-release tag only satisfies a clause containing a comparator with the same [major, minor, patch] tuple AND a pre-release tag.

Types

Version :: struct

A parsed SemVer 2.0.0 version. The prerelease and build strings hold the dot-separated identifiers verbatim (without the leading - / + separators) ; they default to "" when absent, so a simple Version { .major = 1, .minor = 2, .patch = 3 } literal is the canonical way to build a no-pre-release / no-build version. Use parse for the full grammar.

Fields

major: i32
No description.
minor: i32
No description.
patch: i32
No description.
prerelease: string = ""
No description.
build: string = ""
No description.
Implements Display to_string :: fn(self) -> string
Implements Equals equals :: fn(self, other: Self) -> bool
Implements Comparable compare :: fn(self, other: Self) -> i32
VersionRange :: struct

A parsed range expression: a disjunction of conjunctions of terms, matching the npm || (OR) / whitespace (AND) grammar. Construct via parse_range only ; the internal RangeClause / RangeTerm types are not exported.

Implements Contains<Version> contains :: fn(self, value: Version) -> bool

Functions

parse :: fn(s: string) -> Version | ParseError

Parse s into a Version per SemVer 2.0.0 §2/§9/§10.

Strict : rejects leading zeros on any numeric identifier, empty identifiers, non-[0-9A-Za-z-] characters in pre-release / build, missing components.

Parameters

sstring the version string (no leading v).

Returns

Version | ParseError the parsed Version on success.

Errors

  • ParseError carrying a one-line description.

Example

match parsed :: parse("1.2.3-rc.1") {
    is Version    -> println("${parsed}")
    is ParseError -> eprintln(parsed.message())
}
parse_range :: fn(s: string) -> VersionRange | ParseError

Parse s into a VersionRange per the npm range grammar : ^, ~, primitive comparators (=, <, <=, >, >=), whitespace for AND, || for OR, hyphen ranges A - B, x-ranges (1.2.x, 1.x, *), and partial versions.

Upper bounds derived from ^ / ~ / x-range carry a -0 pre-release tag so no pre-release of the bumped major / minor can slip through (matches node-semver).

Parameters

sstring the range expression.

Returns

VersionRange | ParseError the parsed VersionRange on success.

Errors

  • ParseError carrying a one-line description.

Example

r :: parse_range("^1.2.3 || >=2.0.0")
Written by vader doc. Icons: Codicons, CC BY 4.0. Fonts: Atkinson Hyperlegible, JetBrains Mono, OFL.