Semver
Work with semantic versions (“1.2.3”, “v1.2.3-rc.1”): read their parts, compare them, bump them, and check them against constraints such as “>= 1.20”. A version that does not parse is an error.
Reference
| Function | Description |
|---|---|
semverBump | Increments component (“major”, “minor” or “patch”) of version v, resetting the lower components and dropping prerelease and build metadata. |
semverCompare | Compares versions a and b: -1 when a is older, 0 when they are equal, 1 when a is newer. |
semverConstraint | Reports whether version v satisfies constraint, written as “>=1.2.0,<2.0.0”, “^2.0”, “~1.2” or “1.x”. |
semverMajor | Returns the major component of version v; an error when v is not a valid version. |
semverMinor | Returns the minor component of version v; an error when v is not a valid version. |
semverPatch | Returns the patch component of version v; an error when v is not a valid version. |
semverValid | Reports whether v is a valid semantic version; a leading “v” is accepted. |
Functions
semverBump
semverBump increments component (“major”, “minor” or “patch”) of version v, resetting the lower components and dropping prerelease and build metadata.
{{ semverBump "1.2.3" "minor" }} → 1.3.0
semverCompare
semverCompare compares versions a and b: -1 when a is older, 0 when they are equal, 1 when a is newer. An error when either is not a valid version.
{{ semverCompare .spec.version .status.runningVersion }} → 1
See also: semverConstraint
semverConstraint
semverConstraint reports whether version v satisfies constraint, written as “>=1.2.0,<2.0.0”, “^2.0”, “~1.2” or “1.x”. An error when either does not parse.
{{ semverConstraint .spec.version "^1.0" }} → true
See also: semverCompare
semverMajor
semverMajor returns the major component of version v; an error when v is not a valid version.
{{ semverMajor "1.2.3" }} → 1
See also: semverMinor, semverPatch
semverMinor
semverMinor returns the minor component of version v; an error when v is not a valid version.
{{ semverMinor "1.2.3" }} → 2
See also: semverMajor, semverPatch
semverPatch
semverPatch returns the patch component of version v; an error when v is not a valid version.
{{ semverPatch "1.2.3" }} → 3
See also: semverMajor, semverMinor
semverValid
semverValid reports whether v is a valid semantic version; a leading “v” is accepted.
{{ semverValid .spec.version }} → true