SpecVersion is the latest fully supported spec version of semver
FinalizeVersion returns the major, minor and patch number only and discards prerelease and build number.
NewBuildVersion creates a new valid build version
Sort sorts a slice of versions
PRVersion represents a PreRelease Version
NewPRVersion creates a new valid prerelease version
Compare compares two PreRelease Versions v and o: -1 == v is less than o 0 == v is equal to o 1 == v is greater than o
IsNumeric checks if prerelease-version is numeric
PreRelease version to string
Range represents a range of versions. A Range can be used to check if a Version satisfies it:
range, err := semver.ParseRange(">1.0.0 <2.0.0") range(semver.MustParse("1.1.1") // returns true
MustParseRange is like ParseRange but panics if the range cannot be parsed.
ParseRange parses a range and returns a Range. If the range could not be parsed an error is returned.
Valid ranges are:
- "<1.0.0" - "<=1.0.0" - ">1.0.0" - ">=1.0.0" - "1.0.0", "=1.0.0", "==1.0.0" - "!1.0.0", "!=1.0.0"
A Range can consist of multiple ranges separated by space: Ranges can be linked by logical AND:
- ">1.0.0 <2.0.0" would match between both ranges, so "1.1.1" and "1.8.7" but not "1.0.0" or "2.0.0" - ">1.0.0 <3.0.0 !2.0.3-beta.2" would match every version between 1.0.0 and 3.0.0 except 2.0.3-beta.2
Ranges can also be linked by logical OR:
- "<2.0.0 || >=3.0.0" would match "1.x.x" and "3.x.x" but not "2.x.x"
AND has a higher precedence than OR. It's not possible to use brackets.
Ranges can be combined by both AND and OR
- `>1.0.0 <2.0.0 || >3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1`
AND combines the existing Range with another Range using logical AND.
OR combines the existing Range with another Range using logical OR.
Version represents a semver compatible version
Make is an alias for Parse, parses version string and returns a validated Version or error
MustParse is like Parse but panics if the version cannot be parsed.
New is an alias for Parse and returns a pointer, parses version string and returns a validated Version or error
Parse parses version string and returns a validated Version or error
ParseTolerant allows for certain version specifications that do not strictly adhere to semver specs to be parsed by this library. It does so by normalizing versions before passing them to Parse(). It currently trims spaces, removes a "v" prefix, adds a 0 patch number to versions with only major and minor components specified, and removes leading 0s.
Compare compares Versions v to o: -1 == v is less than o 0 == v is equal to o 1 == v is greater than o
EQ checks if v is equal to o.
Equals checks if v is equal to o.
FinalizeVersion discards prerelease and build number and only returns major, minor and patch number.
GE checks if v is greater than or equal to o.
GT checks if v is greater than o.
GTE checks if v is greater than or equal to o.
IncrementMajor increments the major version
IncrementMinor increments the minor version
IncrementPatch increments the patch version
LE checks if v is less than or equal to o.
LT checks if v is less than o.
LTE checks if v is less than or equal to o.
MarshalJSON implements the encoding/json.Marshaler interface.
NE checks if v is not equal to o.
Scan implements the database/sql.Scanner interface.
Version to string
UnmarshalJSON implements the encoding/json.Unmarshaler interface.
Validate validates v and returns error in case
Value implements the database/sql/driver.Valuer interface.
Versions represents multiple versions.
Len returns length of version collection
Less checks if version at index i is less than version at index j
Swap swaps two versions inside the collection by its indices