Skip to content

Latest commit

 

History

History
142 lines (103 loc) · 2.52 KB

semver.md

File metadata and controls

142 lines (103 loc) · 2.52 KB

import { Callout } from 'nextra/components';

semver

This module requires that Risor has been compiled with the `semver` Go build tag. When compiling **manually**, [make sure you specify `-tags semver`](https://github.com/risor-io/risor#build-and-install-the-cli-from-source).

Functions

compare

compare(v1 int, v2 int) int

Compares v1 and v2. Returns -1 if v1 is less than v2, 0 if both are equal, 1 if v1 is greater than v2.

>>> import semver
>>> semver.compare("1.2.3", "1.2.4")
-1

major

major(version string) int

Returns the major version of the given version string.

>>> import semver
>>> semver.major("1.2.3")
1

minor

minor(version string) int

Returns the minor version of the given version string.

>>> import semver
>>> semver.minor("1.2.3")
2

patch

patch(version string) int

Returns the patch version of the given version string.

>>> import semver
>>> semver.patch("1.2.3")
3

build

build(version string) string

Returns the build version of the given version string.

>>> import semver
>>> semver.build("1.2.3+build")
"build"

pre

pre(version string) string

Pre returns the pre-release version of the given version string.

>>> import semver
>>> semver.pre("1.2.3-pre")
"pre"

validate

validate(version string) bool

Returns an error if the version isn't valid.

>>> import semver
>>> semver.validate("1.2.3invalid")
Invalid character(s) found in patch number "3invalid"

parse

parse(version string) map

Parses the given version string and returns a map with the major, minor, patch, pre-release, and build versions.

>>> import semver
>>> semver.parse("1.2.3-pre+build")
{
  "major": 1,
  "minor": 2,
  "patch": 3,
  "pre": "pre",
  "build": "build"
}

equals

equals(v1 string, v2 string) bool

Returns whether v1 and v2 are equal.

>>> import semver
>>> semver.equals("1.2.3", "1.2.3")
true