semver

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package semver implements the subset of npm's semver used by pi package management: exact versions, ranges (^ ~ x-ranges, hyphen, ||, primitives), Satisfies and MaxSatisfying with npm's prerelease-inclusion rule.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b Version) int

Compare returns -1, 0, or 1 by npm semver precedence (build ignored).

func MaxSatisfying

func MaxSatisfying(versions []string, rangeInput string) string

MaxSatisfying returns the highest version matching the range, or "".

func Satisfies

func Satisfies(version string, rangeInput string) bool

Satisfies applies npm's rule that prerelease versions only match ranges whose comparator set names a prerelease on the same [major,minor,patch].

func Valid

func Valid(input string) bool

Valid reports whether input is an exact version (npm semver.valid).

func ValidRange

func ValidRange(input string) bool

ValidRange reports whether input parses as an npm range.

Types

type Range

type Range struct {
	// contains filtered or unexported fields
}

Range is a parsed npm range: OR of comparator sets.

func ParseRange

func ParseRange(input string) (Range, bool)

func (Range) Matches

func (r Range) Matches(v Version) bool

type Version

type Version struct {
	Major, Minor, Patch int
	Prerelease          []string
}

func Parse

func Parse(input string) (Version, bool)

Parse accepts an exact npm version ("1.2.3", "v1.2.3", "1.2.3-rc.1+build").

Jump to

Keyboard shortcuts

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