numver

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 2 Imported by: 4

README

numver

Go Reference codecov

A library for extracting numeric parts from version strings

Usage

numver only consider numeric parts in version strings, and ignore any others.

v1 := numver.Parse("1.2.3b05_20240924")
v2 := numver.Version{1, 2, 3, 5, 20240924}
// v1 and v2 are the same
v1.Compare(v2) // = 0

Credits

GUO YANKE, MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SearchOptions

type SearchOptions struct {
	// Items is a list of items to search.
	Items []string
	// Constraint is a version constraint to match.
	Constraint string
	// Extractor is a function to extract a version from an item.
	Extractor VersionExtractor
	// Descending is a flag to search in descending order.
	Descending bool
}

SearchOptions is a set of options for the Search function.

type Version

type Version []int

Version is a sequence of integers.

func Parse

func Parse(s string) Version

Parse parses a version string, extract all numeric parts found.

func Search(opts SearchOptions) (itemFound string, versionFound Version, found bool)

Search searches for the best matching item in the list of items.

func (Version) Compare

func (v Version) Compare(other Version) int

Compare returns -1 if v < other, 0 if v == other, 1 if v > other.

func (Version) IsEmpty

func (v Version) IsEmpty() bool

IsEmpty returns true if the version is empty.

func (Version) Match

func (v Version) Match(constraint Version) bool

Match returns true if the version matches the constraint.

func (Version) String

func (v Version) String() string

String returns the version as a string, with dot separated.

type VersionExtractor added in v0.1.1

type VersionExtractor func(src string) (ver string, ok bool)

VersionExtractor is a function to extract a version component from a string.

Jump to

Keyboard shortcuts

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