Module version
Version comparison library for Lua.
Comparison is simple and straightforward, no interpretation is done whatsoever regarding compatibility etc. If that's what you're looking for, then please checkout the semantic versioning specification (SemVer).
Usage:
local ver = require("version") local v = ver.version("3.1.0") assert( v == ver.version("3.1")) -- missing elements default to zero, and hence are equal assert( v > ver.version("3.0")) local r = ver.range("2.75", "3.50.3") assert(r:matches(v)) local compatible = version.set("1.1","1.1.999999") -- upwards compatibility check assert(compatible:matches("1.1.3")) -- adding elements in a chained fashion compatible:allowed("2.1", "2.5"):disallowed("2.3") -- 2.3 was a buggy version... assert(compatible:matches("1.1.3")) assert(compatible:matches("2.4")) assert(not compatible:matches("2.0")) assert(not compatible:matches("2.3"))
Info:
- Copyright: Mashape Inc.
- License: Apache 2.0
- Author: Thijs Schreijer
Functions
range (v1, v2) | Creates a version range. |
range:matches (v) | Matches a version on a range. |
set (...) | Creates a version set. |
set:allowed (v1, v2) | Adds an ALLOWED range to the set. |
set:disallowed (v1, v2) | Adds a DISALLOWED range to the set. |
set:matches (v1) | Matches a version against the set of allowed and disallowed versions. |
version (v) | Creates a new version object from a string. |
Functions
- range (v1, v2)
-
Creates a version range.
Parameters:
- v1
The FROM version of the range (string or version object). If
nil
, assumed to be 0. - v2
(optional) The TO version of the range (string or version object). If omitted it will default to
v1
.
Returns:
-
range object with
from
andto
fields and set:matches method. - v1
The FROM version of the range (string or version object). If
- range:matches (v)
-
Matches a version on a range.
Parameters:
- v Version (string or version object) to match
Returns:
true
when the version matches the range,false
otherwise - set (...)
-
Creates a version set. A set contains a number of allowed and disallowed version ranges.
Parameters:
- ... initial version/range to allow, see set:allowed for parameter descriptions
Returns:
-
a set object, with
ok
andnok
lists and a set:matches method - set:allowed (v1, v2)
-
Adds an ALLOWED range to the set.
Parameters:
- v1 Version or range, if version, the FROM version in either string or version object format
- v2 Version (optional), TO version in either string or version object format
Returns:
-
The set object, to easy chain multiple allowed/disallowed ranges
- set:disallowed (v1, v2)
-
Adds a DISALLOWED range to the set.
Parameters:
- v1 Version or range, if version, the FROM version in either string or version object format
- v2 Version (optional), TO version in either string or version object format
Returns:
-
The set object, to easy chain multiple allowed/disallowed ranges
- set:matches (v1)
-
Matches a version against the set of allowed and disallowed versions.
NOTE: disallowed has a higher precedence, so a version that matches the allowed-set,
but also the dis-allowed set, will return
false
.Parameters:
- v1 Version to match (either string or version object).
Returns:
true
if the version matches the set, orfalse
otherwise - version (v)
-
Creates a new version object from a string. The returned table will have
comparison operators, eg. LT, EQ, GT. For all comparisons, any missing numbers
will be assumed to be "0" on the least significant side of the version string.
Parameters:
- v String formatted as numbers separated by dots (no limit on number of elements).
Returns:
-
version object