version

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareVersions

func CompareVersions(v1, v2 string) int

CompareVersions robustly compares two version strings. It leverages UniRTM's comprehensive internal Version parser to handle semver, date-versions, and aliases (like "latest" vs "lts"). If one or both versions fail to parse (e.g. non-standard alphanumeric directories like "tip"), it falls back to a segment-based numerical splitting algorithm to gracefully handle any string format. Returns:

1 if v1 > v2

-1 if v1 < v2

0 if v1 == v2

func FormatVersion

func FormatVersion(v *Version) (string, error)

FormatVersion formats a Version object back into a version string

Types

type RangeOperator

type RangeOperator string

RangeOperator represents the operator in a version range

const (
	// RangeOperatorGTE represents ">=" (greater than or equal)
	RangeOperatorGTE RangeOperator = ">="
	// RangeOperatorGT represents ">" (greater than)
	RangeOperatorGT RangeOperator = ">"
	// RangeOperatorLTE represents "<=" (less than or equal)
	RangeOperatorLTE RangeOperator = "<="
	// RangeOperatorLT represents "<" (less than)
	RangeOperatorLT RangeOperator = "<"
	// RangeOperatorEQ represents "=" (equal)
	RangeOperatorEQ RangeOperator = "="
	// RangeOperatorCaret represents "^" (compatible with)
	RangeOperatorCaret RangeOperator = "^"
	// RangeOperatorTilde represents "~" (approximately equivalent to)
	RangeOperatorTilde RangeOperator = "~"
)

type SemVer

type SemVer struct {
	Major      int
	Minor      int
	Patch      int
	Prerelease string // e.g., "alpha.1", "beta.2", "rc.1"
	Build      string // e.g., "20130313144700"
}

SemVer represents a semantic version

func ParseSemVer

func ParseSemVer(versionStr string) (*SemVer, error)

ParseSemVer parses a semantic version string into a SemVer struct

func ParseSemVerPartial

func ParseSemVerPartial(versionStr string) (*SemVer, error)

ParseSemVerPartial parses a partial semantic version string (for tilde ranges) Supports: 1, 1.2, 1.2.3, 1.2.3-alpha, etc.

func (*SemVer) Compare

func (s *SemVer) Compare(other *SemVer) int

Compare compares s to other. Returns:

-1 if s < other
 0 if s == other
 1 if s > other

func (*SemVer) Equal

func (s *SemVer) Equal(other *SemVer) bool

Equal checks if two SemVer objects are equivalent

type Version

type Version struct {
	Type VersionType

	// For VersionTypeExact
	Exact *SemVer

	// For VersionTypeRange
	RangeOp  RangeOperator
	RangeVer *SemVer

	// For VersionTypeAlias
	Alias VersionAlias
}

Version represents a version specification

func ParseVersion

func ParseVersion(versionStr string) (*Version, error)

ParseVersion parses a version string into a Version object

func (*Version) Equal

func (v *Version) Equal(other *Version) bool

Equal checks if two Version objects are equivalent

func (*Version) String

func (v *Version) String() string

String returns the string representation of a Version

type VersionAlias

type VersionAlias string

VersionAlias represents known version aliases

const (
	// VersionAliasLatest represents the latest version
	VersionAliasLatest VersionAlias = "latest"
	// VersionAliasLTS represents the latest LTS version
	VersionAliasLTS VersionAlias = "lts"
	// VersionAliasStable represents the latest stable version
	VersionAliasStable VersionAlias = "stable"
)

type VersionType

type VersionType int

VersionType represents the type of version specification

const (
	// VersionTypeExact represents an exact semver version (e.g., "1.20.0")
	VersionTypeExact VersionType = iota
	// VersionTypeRange represents a version range (e.g., ">=1.20.0", "^3.11", "~2.7.0")
	VersionTypeRange
	// VersionTypeAlias represents a version alias (e.g., "latest", "lts", "stable")
	VersionTypeAlias
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL