Skip to content

A lightweight and idiomatic Go package for parsing and comparing semantic versions (SemVer) based on the official SemVer 2.0.0 specification. Supports version precedence checks, pre-release identifiers, and more.

License

Notifications You must be signed in to change notification settings

Nidal-Bakir/go-semver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-semver

A lightweight and idiomatic Go package to parse and compare semantic versions based on the Semantic Versioning 2.0.0 specification.

✨ Features

  • Parse semantic version strings (MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD])
  • Compare versions with full support for precedence rules
  • Handle pre-release and build metadata
  • Determine ordering between two versions
  • Idiomatic Go API

📦 Installation

go get github.com/Nidal-Bakir/go-semver

🛠️ Usage

package main

import (
    "fmt"
    "github.com/Nidal-Bakir/go-semver"
)

func main() {
    v1, _ := semver.Parse("1.2.3-alpha.1")
    v2, _ := semver.Parse("1.2.3")

    if v1.IsLess(v2) {
        fmt.Println(v1, "is less than", v2)
    }
}

🔍 Version Comparison Rules

This package follows the precedence rules defined in the Semantic Versioning 2.0.0 spec, including:

  • Precedence is determined by the major, minor, and patch versions, in that order.

  • Pre-release versions have lower precedence than the associated normal version.

  • Build metadata does not affect version precedence.

✅ Example Comparisons

Version A Version B Result
1.0.0 2.0.0 A < B
1.0.0-alpha 1.0.0 A < B
1.0.0-alpha 1.0.0-alpha.1 A < B
1.2.3+build1 1.2.3+build2 A == B

About

A lightweight and idiomatic Go package for parsing and comparing semantic versions (SemVer) based on the official SemVer 2.0.0 specification. Supports version precedence checks, pre-release identifiers, and more.

Resources

License

Stars

Watchers

Forks

Languages