XQuery Function Documentation

Search and Browse

http://exist-db.org/xquery/semver

/db/system/repo/semver-xq-2.2.1/content/semver.xq

Validate, compare, sort, parse, and serialize Semantic Versioning (SemVer) 2.0.0 version strings, using XQuery.
SemVer rules are applied strictly, raising errors when version strings do not conform to the spec.

version 2.1.0
author Joe Wicentowski

semver:coerce

semver:coerce($version as xs:string?) as map(*)

Coerce a non-SemVer version string into SemVer version string and parse it as such

Parameters:
$version? $version?
Returns:
map(*) : A map containing analysis of the parsed version, containing entries for each identifier ("major", "minor", "patch", "pre-release", and "build-metadata"), and an "identifiers" entry with all identifiers in an array.

semver:compare

semver:compare($v1 as xs:string, $v2 as xs:string) as xs:integer

Compare two versions (strictly)

Parameters:
$v1 $v1
$v2 $v2
Returns:
xs:integer : -1 if v1 < v2, 0 if v1 = v2, or 1 if v1 > v2.

semver:compare

semver:compare($v1 as xs:string, $v2 as xs:string, $coerce as xs:boolean) as xs:integer

Compare two versions (with an option to coerce invalid SemVer strings)

Parameters:
$v1 $v1
$v2 $v2
$coerce $coerce
Returns:
xs:integer : -1 if v1 < v2, 0 if v1 = v2, or 1 if v1 > v2.

semver:eq

semver:eq($v1 as xs:string, $v2 as xs:string) as xs:boolean

Test if v1 is equal to v2

Parameters:
$v1 $v1
$v2 $v2
Returns:
xs:boolean : true if v1 is equal to v2

semver:ge

semver:ge($v1 as xs:string, $v2 as xs:string) as xs:boolean

Test if v1 is the same or higher version than v2 (strictly)

Parameters:
$v1 $v1
$v2 $v2
Returns:
xs:boolean : true if v1 is greater than or equal to v2

semver:ge

semver:ge($v1 as xs:string, $v2 as xs:string, $coerce as xs:boolean) as xs:boolean

Test if v1 is the same or higher version than v2

Parameters:
$v1 $v1
$v2 $v2
$coerce $coerce
Returns:
xs:boolean : true if v1 is greater than or equal to v2

semver:gt

semver:gt($v1 as xs:string, $v2 as xs:string) as xs:boolean

Test if v1 is a higher version than v2 (strictly)

Parameters:
$v1 $v1
$v2 $v2
Returns:
xs:boolean : true if v1 is greater than v2

semver:gt

semver:gt($v1 as xs:string, $v2 as xs:string, $coerce as xs:boolean) as xs:boolean

Test if v1 is a higher version than v2 (with an option to coerce invalid SemVer strings)

Parameters:
$v1 $v1
$v2 $v2
$coerce $coerce
Returns:
xs:boolean : true if v1 is greater than v2

semver:le

semver:le($v1 as xs:string, $v2 as xs:string) as xs:boolean

Test if v1 is a lower version or the same version as v2 (strictly)

Parameters:
$v1 $v1
$v2 $v2
Returns:
xs:boolean : true if v1 is less than or equal to v2

semver:le

semver:le($v1 as xs:string, $v2 as xs:string, $coerce as xs:boolean) as xs:boolean

Test if v1 is a lower version or the same version as v2 (with an option to coerce invalid SemVer strings)

Parameters:
$v1 $v1
$v2 $v2
$coerce $coerce
Returns:
xs:boolean : true if v1 is less than or equal to v2

semver:lt

semver:lt($v1 as xs:string, $v2 as xs:string) as xs:boolean

Test if v1 is a lower version than v2 (strictly)

Parameters:
$v1 $v1
$v2 $v2
Returns:
xs:boolean : true if v1 is less than v2

semver:lt

semver:lt($v1 as xs:string, $v2 as xs:string, $coerce as xs:boolean) as xs:boolean

Test if v1 is a lower version than v2 (with an option to coerce invalid SemVer strings)

Parameters:
$v1 $v1
$v2 $v2
$coerce $coerce
Returns:
xs:boolean : true if v1 is less than v2

semver:ne

semver:ne($v1 as xs:string, $v2 as xs:string) as xs:boolean

Test if v1 is not equal to v2 (strictly)

Parameters:
$v1 $v1
$v2 $v2
Returns:
xs:boolean : true if v1 is not equal to v2

semver:ne

semver:ne($v1 as xs:string, $v2 as xs:string, $coerce as xs:boolean) as xs:boolean

Test if v1 is not equal to v2 (with an option to coerce invalid SemVer strings)

Parameters:
$v1 $v1
$v2 $v2
$coerce $coerce
Returns:
xs:boolean : true if v1 is not equal to v2

semver:parse

semver:parse($version as xs:string) as map(*)

Parse a SemVer version string (strictly)

Parameters:
$version $version
Returns:
map(*) : A map containing analysis of the parsed version, containing entries for each identifier ("major", "minor", "patch", "pre-release", and "build-metadata"), and an "identifiers" entry with all identifiers in an array.

semver:parse

semver:parse($version as xs:string, $coerce as xs:boolean) as map(*)

Parse a SemVer version string (with an option to coerce invalid SemVer strings)

Parameters:
$version $version
$coerce $coerce
Returns:
map(*) : A map containing analysis of the parsed version, containing entries for each identifier ("major", "minor", "patch", "pre-release", and "build-metadata"), and an "identifiers" entry with all identifiers in an array.

semver:serialize

semver:serialize($version as map(*)) as item()*

Serialize a parsed SemVer string

Parameters:
$version $version
Returns:
item()* : A SemVer string

semver:serialize

semver:serialize($major as xs:integer, $minor as xs:integer, $patch as xs:integer, $pre-release as xs:anyAtomicType*, $build-metadata as xs:anyAtomicType*) as item()*

Serialize a SemVer string

Parameters:
$major $major
$minor $minor
$patch $patch
$pre-release* $pre-release*
$build-metadata* $build-metadata*
Returns:
item()* : A SemVer string

semver:sort

semver:sort($versions as xs:string+) as xs:string+

Sort SemVer strings (strictly)

Parameters:
$versions+ $versions+
Returns:
xs:string+ : A sequence of sorted version strings

semver:sort

semver:sort($versions as xs:string+, $coerce as xs:boolean) as xs:string+

Sort SemVer strings (with an option to coerce invalid SemVer strings)

Parameters:
$versions+ $versions+
$coerce $coerce
Returns:
xs:string+ : A sequence of sorted version strings

semver:validate

semver:validate($version as xs:string) as xs:boolean

Validate whether a SemVer string conforms to the spec

Parameters:
$version $version
Returns:
xs:boolean : True if the version is valid, false if not