Semantic versions
Check, parse, compare and sort semantic versions (MAJOR.MINOR.PATCH), test them against npm style ranges and compute the next version. Typical uses: pick the highest compatible version of a package, bump a version before a release.
semver validsemver validsemver parsesemver comparesemver sortsemver sortsemver satisfiessemver satisfiessemver max_satisfyingsemver max_satisfyingsemver rangesemver rangesemver bumpsemver bump

semver valid <version>


Description

    1 if the text is a semantic version, else 0

Parameters

    version:   The version - String - required
admin
semver valid "1.4.0-beta.2+build.7"
mentdb
1
a leading zero is not allowed
admin
semver valid "1.04.0"
mentdb
0

semver valid <version> <params>


Description

    Check with the parameter strict (true: exactly the grammar of SemVer 2.0.0, no leading v, no spaces)

Parameters

    version:   The version - String - required
    params:   The parameters as JSON - String - required
admin
semver valid "v1.2.3" "{\"strict\": true}"
mentdb
0

semver parse <version>


Description

    The parts of a version: version (without build), major, minor, patch, prerelease (numbers stay numbers), build, is_prerelease, full

Parameters

    version:   The version - String - required
admin
semver parse "v2.0.0-rc.1+sha.5114f85"
mentdb
{"version": "2.0.0-rc.1", "major": 2, "minor": 0, "patch": 0, "prerelease": ["rc", 1], "build": ["sha", "5114f85"], "is_prerelease": true, "full": "2.0.0-rc.1+sha.5114f85"}

semver compare <version1> <version2>


Description

    -1, 0 or 1 by the precedence of SemVer 2.0.0

Parameters

    version1:   The first version - String - required
    version2:   The second version - String - required
admin
semver compare "1.0.0-beta.2" "1.0.0-beta.11"
mentdb
-1
the build metadata does not count
admin
semver compare "1.0.0+20260101" "1.0.0+20261110"
mentdb
0
a prerelease comes before the release
admin
semver compare "2.0.0-rc.1" "2.0.0"
mentdb
-1

semver sort <versions>


Description

    Sort a JSON array of versions, from the lowest. The texts are returned as given

Parameters

    versions:   A JSON array of versions - String - required
admin
semver sort "[\"1.0.0\", \"1.0.0-rc.1\", \"1.0.0-alpha.beta\", \"1.0.0-beta\", \"1.0.0-alpha\", \"1.0.0-beta.11\", \"1.0.0-alpha.1\", \"1.0.0-beta.2\"]"
mentdb
["1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-alpha.beta", "1.0.0-beta", "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0"]

semver sort <versions> <params>


Description

    Sort with parameters: order (asc or desc), skip_invalid (false: a text that is not a version is an error; true: it is left out)

Parameters

    versions:   A JSON array of versions - String - required
    params:   The parameters as JSON - String - required
admin
semver sort "[\"v1.10.0\", \"latest\", \"v1.9.2\", \"v2.0.0-rc.1\"]" "{\"order\": \"desc\", \"skip_invalid\": true}"
mentdb
["v2.0.0-rc.1", "v1.10.0", "v1.9.2"]
Used in use cases (1 recipe)

    Versioning & deployment › Choose the version to depend on and the number of the next release
Often used with

    semver bump  ·  semver max_satisfying  ·  semver satisfies

semver satisfies <version> <range>


Description

    1 if the version is in the range, else 0

Parameters

    version:   The version - String - required
    range:   The npm range - String - required
admin
semver satisfies "1.9.2" "^1.2.0"
mentdb
1
caret below 1.0.0: the same minor version
admin
semver satisfies "0.3.0" "^0.2.3"
mentdb
0
a prerelease of another version is not in the range
admin
semver satisfies "1.5.0-beta.1" "^1.2.0"
mentdb
0
two sets
admin
semver satisfies "3.1.0" "<2.0.0 || >=3.0.0 <4"
mentdb
1

semver satisfies <version> <range> <params>


Description

    Check with the parameter include_prerelease (true: every prerelease can match)

Parameters

    version:   The version - String - required
    range:   The npm range - String - required
    params:   The parameters as JSON - String - required
admin
semver satisfies "1.5.0-beta.1" "^1.2.0" "{\"include_prerelease\": true}"
mentdb
1
Used in use cases (1 recipe)

    Versioning & deployment › Choose the version to depend on and the number of the next release
Often used with

    semver bump  ·  semver max_satisfying  ·  semver sort

semver max_satisfying <versions> <range>


Description

    The highest version of a list that is in the range, or an empty text if none is

Parameters

    versions:   A JSON array of versions - String - required
    range:   The npm range - String - required
admin
semver max_satisfying "[\"1.3.9\", \"1.4.0\", \"1.4.7\", \"1.5.0\", \"2.0.0\"]" "~1.4.0"
mentdb
1.4.7
nothing matches
admin
semver max_satisfying "[\"1.3.9\", \"2.0.0\"]" "^3"
mentdb

semver max_satisfying <versions> <range> <params>


Description

    With parameters: include_prerelease, skip_invalid, min (true: the lowest version in the range)

Parameters

    versions:   A JSON array of versions - String - required
    range:   The npm range - String - required
    params:   The parameters as JSON - String - required
admin
semver max_satisfying "[\"1.3.9\", \"1.4.0\", \"1.4.7\", \"1.5.0\"]" ">=1.4" "{\"min\": true}"
mentdb
1.4.0
Used in use cases (1 recipe)

    Versioning & deployment › Choose the version to depend on and the number of the next release
Often used with

    semver bump  ·  semver satisfies  ·  semver sort

semver range <range>


Description

    The comparators of a range, after the expansion of ^ ~ x and hyphens: {range, sets}. Useful to understand a range

Parameters

    range:   The npm range - String - required
admin
semver range "^1.2.3 || ~0.4 || 2.0.0 - 2.4"
mentdb
{"range": ">=1.2.3 <2.0.0-0||>=0.4.0 <0.5.0-0||>=2.0.0 <2.5.0-0", "sets": [[">=1.2.3", "<2.0.0-0"], [">=0.4.0", "<0.5.0-0"], [">=2.0.0", "<2.5.0-0"]]}
an invalid comparator
admin
semver range ">=1.2.x.4"
mentdb
ERROR: Sorry, an error appears (the range has an invalid comparator: '>=1.2.x.4').

semver range <range> <params>


Description

    The comparators with the parameter include_prerelease

Parameters

    range:   The npm range - String - required
    params:   The parameters as JSON - String - required
admin
semver range "^0.2.3" "{\"include_prerelease\": true}"
mentdb
{"range": ">=0.2.3-0 <0.3.0-0", "sets": [[">=0.2.3-0", "<0.3.0-0"]]}

semver bump <version> <part>


Description

    The next version (build metadata removed). part: major, minor, patch, premajor, preminor, prepatch, prerelease (the next prerelease), release (drop the prerelease)

Parameters

    version:   The version - String - required
    part:   The part to increase - String - required
admin
semver bump "1.4.7" "minor"
mentdb
1.5.0
the release of a prerelease
admin
semver bump "2.0.0-rc.3" "release"
mentdb
2.0.0
the next prerelease
admin
semver bump "2.0.0-rc.3" "prerelease"
mentdb
2.0.0-rc.4
a major of a prerelease 2.0.0-x is 2.0.0
admin
semver bump "2.0.0-rc.3" "major"
mentdb
2.0.0

semver bump <version> <part> <params>


Description

    The next version with parameters: preid (the prerelease name, ex: beta or rc), preid_base (0 or 1, the first number)

Parameters

    version:   The version - String - required
    part:   The part to increase - String - required
    params:   The parameters as JSON - String - required
admin
semver bump "1.4.7" "preminor" "{\"preid\": \"beta\"}"
mentdb
1.5.0-beta.0
from alpha to rc, starting at 1
admin
semver bump "2.0.0-alpha.4" "prerelease" "{\"preid\": \"rc\", \"preid_base\": \"1\"}"
mentdb
2.0.0-rc.1
Used in use cases (1 recipe)

    Versioning & deployment › Choose the version to depend on and the number of the next release
Often used with

    semver max_satisfying  ·  semver satisfies  ·  semver sort