semver

Imports

Imports #

"sort"

Type Aliases

ByVersion type #

ByVersion implements [sort.Interface] for sorting semantic version strings.

type ByVersion []string

Structs

parsed struct #

parsed returns the parsed form of a semantic version string.

type parsed struct {
major string
minor string
patch string
short string
prerelease string
build string
}

Functions

Build function #

Build returns the build suffix of the semantic version v. For example, Build("v2.1.0+meta") == "+meta". If v is an invalid semantic version string, Build returns the empty string.

func Build(v string) string

Canonical function #

Canonical returns the canonical formatting of the semantic version v. It fills in any missing .MINOR or .PATCH and discards build metadata. Two semantic versions compare equal only if their canonical formattings are identical strings. The canonical invalid semantic version is the empty string.

func Canonical(v string) string

Compare function #

Compare returns an integer comparing two versions according to semantic version precedence. The result will be 0 if v == w, -1 if v < w, or +1 if v > w. An invalid semantic version string is considered less than a valid one. All invalid semantic version strings compare equal to each other.

func Compare(v string, w string) int

IsValid function #

IsValid reports whether v is a valid semantic version string.

func IsValid(v string) bool

Len method #

func (vs ByVersion) Len() int

Less method #

func (vs ByVersion) Less(i int, j int) bool

Major function #

Major returns the major version prefix of the semantic version v. For example, Major("v2.1.0") == "v2". If v is an invalid semantic version string, Major returns the empty string.

func Major(v string) string

MajorMinor function #

MajorMinor returns the major.minor version prefix of the semantic version v. For example, MajorMinor("v2.1.0") == "v2.1". If v is an invalid semantic version string, MajorMinor returns the empty string.

func MajorMinor(v string) string

Max function #

Max canonicalizes its arguments and then returns the version string that compares greater. Deprecated: use [Compare] instead. In most cases, returning a canonicalized version is not expected or desired.

func Max(v string, w string) string

Prerelease function #

Prerelease returns the prerelease suffix of the semantic version v. For example, Prerelease("v2.1.0-pre+meta") == "-pre". If v is an invalid semantic version string, Prerelease returns the empty string.

func Prerelease(v string) string

Sort function #

Sort sorts a list of semantic version strings using [ByVersion].

func Sort(list []string)

Swap method #

func (vs ByVersion) Swap(i int, j int)

compareInt function #

func compareInt(x string, y string) int

comparePrerelease function #

func comparePrerelease(x string, y string) int

isBadNum function #

func isBadNum(v string) bool

isIdentChar function #

func isIdentChar(c byte) bool

isNum function #

func isNum(v string) bool

nextIdent function #

func nextIdent(x string) (dx string, rest string)

parse function #

func parse(v string) (p parsed, ok bool)

parseBuild function #

func parseBuild(v string) (t string, rest string, ok bool)

parseInt function #

func parseInt(v string) (t string, rest string, ok bool)

parsePrerelease function #

func parsePrerelease(v string) (t string, rest string, ok bool)

Generated with Arrow