ddn.util.semver

Module ddn.util.semver

Provides a full-featured Semantic Versioning (SemVer) implementation according to https://semver.org/. Includes parsing, comparison, stringification, and manipulation utilities.

Types 2

classSemVerParseException : Exception

Exception thrown when a version string is invalid.

Constructors
this(string msg)
structSemVer

Represents a Semantic Version according to semver.org.

Provides parsing, comparison, and stringification.

Fields
uint major
uint minor
uint patch
string[] prerelease
string[] build
Methods
SemVer parse(string verstr)Parses a version string into a SemVer object.
string toString() constConverts this SemVer to its canonical string representation.
bool isPrerelease() constReturns true if this version is a pre-release.
bool hasBuild() constReturns true if this version has build metadata.
int compare(const SemVer other) constCompares this SemVer to another according to semver precedence rules.
bool opEquals(const SemVer other) constEquality operator. Ignores build metadata.
int opCmp(const SemVer other) constLess-than operator, for sorting. Ignores build metadata.
size_t toHash() const @safe nothrowComputes a hash value for this SemVer.
SemVer bumpMajor() constReturns a new SemVer with incremented major version, resetting minor and patch to 0, and clearing prerelease/build.
SemVer bumpMinor() constReturns a new SemVer with incremented minor version, resetting patch to 0, and clearing prerelease/build.
SemVer bumpPatch() constReturns a new SemVer with incremented patch version, clearing prerelease/build.
SemVer withPrerelease(string[] ids) constReturns a new SemVer with the given prerelease identifiers.
SemVer withBuild(string[] ids) constReturns a new SemVer with the given build metadata identifiers.
Constructors
this(uint major, uint minor, uint patch, string[] prerelease = [], string[] build = [])Constructs a SemVer from its components.

Templates 1

tmplSEMVER(uint major, uint minor, uint patch = 0)

Template for encoding a semantic version as a ulong at compile-time.

The version is encoded as major * 100_000_000 + minor * 10_000 + patch, enabling simple numeric comparisons in static if statements. Minor and patch each use 4 digits (0-9999); major has no fixed limit.

Parameters

majorMajor version number (0 to practical ulong limits)
minorMinor version number (0-9999)
patchPatch version number (0-9999, defaults to 0) Example:
enum VER_1_10 = SEMVER!(1, 10, 0);
static if (VER_1_10 <= SEMVER!(1, 12, 3)) {
   // Code for version 1.12.3 or later
}
static assert(SEMVER!(1, 2, 3) == 1_0002_0003);