Categorygithub.com/axllent/semver
repositorypackage
1.0.0
Repository: https://github.com/axllent/semver.git
Documentation: pkg.go.dev

# README

Semver - a more flexible semantic versioning package

GoDoc Go Report Card

This semver package allows comparison of semantic versions strings in Go. It builds on Go's standard semver module by adding support for:

  • Versions with or without the v prefix (e.g., v1.2.3 and 1.2.3).
  • Mixed comparisons between prefixed and non-prefixed versions.
  • Sorting and finding the maximum version from a list of semantic versions.

Installation

To install the package, run:

go get github.com/axllent/semver

Usage

if semver.Compare("1.0.1", "1.0.0") == 1 { // higher
  //...
}

if semver.Compare("1.0.1", "1.0.1-beta") == 1 { // higher
  //...
}

fmt.Println(semver.Max("v1.0.1", "v1.0.1-beta"))
// Output: v1.0.1

versions := []string{"5.0.0", "v5.1.0", "5.1.0-beta", "v1.2.3"}
fmt.Println(semver.SortMax(versions))
// Output: [v5.1.0 5.1.0-beta 5.0.0 v1.2.3]