🌱
Sprout
Github
  • About
  • Roadmap to Sprout v1.0
  • Migration from Sprig
  • Introduction
    • Getting Started
    • Templating Conventions
  • Features
    • Loader System (Registry)
    • Loader System (Registry Group)
    • Function Aliases
    • Function Notices
    • Safe Functions
  • Registries
    • List of all registries
    • Backward
    • Checksum
    • Conversion
    • Crypto
    • Encoding
    • Env
    • Filesystem
    • Maps
    • Numeric
    • Network
    • Random
    • Reflect
    • Regexp
    • SemVer
    • Slices
    • Std
    • Strings
    • Time
    • Uniqueid
  • Groups
    • List of all registry groups
    • All
    • Hermetic
  • Advanced
    • How to create a handler
    • How to create a registry
    • How to create a registry group
  • Links
    • GitHub repository
Powered by GitBook
On this page
  • semver
  • semverCompare
Edit on GitHub
  1. Registries

SemVer

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

PreviousRegexpNextSlices

Last updated 8 months ago

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"

This registry utilizing the original 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

{{ 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

{{ 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
Semver(version string) (*semver.Version, error)
SemverCompare(constraint, version string) (bool, error)
Semver package