Semver

The Semver registry is designed to handle semantic versioning, offering functions to compare and manage version numbers consistently across your projects.

circle-info

You can easily import all the functions from the semver registry by including the following import statement in your code

import "github.com/go-sprout/sprout/registry/semver"
circle-info

This registry utilizing the original Semver packagearrow-up-right created by Masterminds, which adheres to the Semantic Versioning specification.

semver

The function creates a new semantic version object from a given version string, allowing for the structured handling and comparison of software versioning according to semantic versioning principles.

Signature

Must version

{{ semver "1.0.0" }} // Output: 1.0.0
{{ semver "1.0.0-alpha" }} // Output: 1.0.0-alpha
{{ (semver "2.1.0").Major }} // Output: 2

semverCompare

The function checks whether a given version string satisfies a specified semantic version constraint, ensuring that the version meets the defined requirements according to the Semantic Versioning rules.

Signature

Must version

{{ semverCompare ">=1.0.0" "1.0.0" }} // Output: true
{{ semverCompare "1.0.0" "1.0.0" }} // Output: true
{{ semverCompare "1.0.0" "1.0.1" }} // Output: false
{{ semverCompare "~1.0.0" "1.0.0" }} // Output: true
{{ semverCompare ">1.0.0-alpha" "1.0.0-alpha.1" }} // Output: true
{{ semverCompare "1.0.0-alpha.1" "1.0.0-alpha" }} // Output: false
{{ semverCompare "1.0.0-alpha.1" "1.0.0-alpha.1" }} // Output: true

Last updated