Sentinel
Import: version
The version import provides functions for parsing versions and version constraints, and verifying versions against a set of constraints.
Versions are created through the new
function, which accepts a string type in dotted-tri format (i.e. 1.0.0-alpha.1+001) that can represent a version.
version.new(v)
Constructs a version from string value.
version.new("1.0.0-alpha.1+001")
version.major
An integer representation of the Major number for a given version .
version.new("1.0.0-alpha.1+001").major // 1
version.minor
An integer representation of the Minor number for a given version.
version.new("1.0.0-alpha.1+001").minor // 0
version.patch
An integer representation of the Patch number for a given version.
version.new("1.0.0-alpha.1+001").patch // 0
version.prerelease
A string representation of the Prerelease for a given version.
version.new("1.0.0-alpha.1+001").prerelease // "alpha.1"
version.metadata
A string representation of the Metadata for a given version.
version.new("1.0.0-alpha.1+001").metadata // "001"
version.version
A string representation of the version including pre-release and metadata information.
version.new("1.0.0-alpha.1+001").version // "1.0.0-alpha.1+001"
version.greater_than(v)
Tests that the version is greater than a given version.
version.new("1.0.0-alpha.1+001").greater_than("0.12.0-alpha.1+001") // True
version.new("1.0.0-alpha.1+001").gt("1.0.1-alpha.1+001") // False
version.greater_than_or_equals(v)
Tests that the version is greater than or equal to a given version.
version.new("1.0.0-alpha.1+001").greater_than_or_equals("1.0.0-alpha.1+001") // True
version.new("1.0.0-alpha.1+001").gte("1.0.1-alpha.1+001") // False
version.less_than(v)
Tests that the version is less than a given version.
version.new("1.0.0-alpha.1+001").less_than("1.0.1-alpha.1+001") // True
version.new("1.0.0-alpha.1+001").lt("0.12.0-alpha.1+001") // False
version.less_than_or_equals(v)
Tests that the version is less than or equal to a given version.
version.new("1.0.0-alpha.1+001").less_than_or_equals("1.0.0-alpha.1+001") // True
version.new("1.0.0-alpha.1+001").lte("0.12.0-alpha.1+001") // False
version.less_than_or_equals(v)
Tests that the version equals a given version.
version.new("1.0.0-alpha.1+001").equals("1.0.0-alpha.1+001") // True
version.new("1.0.0-alpha.1+001").eq("0.12.0-alpha.1+001") // False
version.compare(v)
Compares one version with a given version. Compare returns -1, 0, or 1 if the version is less, equal, or greater than the other version, respectively.
version.new("1.0.0-alpha.1+001").compare("0.12.0-alpha.1+001") // -1
version.new("1.0.0-alpha.1+001").compare("1.0.0-alpha.1+001") // 0
version.new("0.12.0-alpha.1+001").cmp("1.0.0-alpha.1+001") // 1
version.satisfies(v, x)
Tests that a version adheres to one or more version constraints. Satisfies supports the following restriction operators:
- =
- !=
- >
- <
- >=
- <=
- ~>
Satisfies supports the following usage scenarios:
- A constraint with a pre-release can only match a pre-release version that contains the same major, minor and patch identifiers.
- A constraint without a pre-release can only match a version without a pre-release.
version.new("1.0.0-alpha.1+001").satisfies("> 1.0.0-alpha.1+001") // false
version.new("1.0.0-alpha.1+001").satisfies(">= 1.0.0-alpha.1+001") // true
version.new("1.0.0-alpha.1+001").satisfies(">= 1.0.0-alpha.1+001, < 1.0.0-beta+001") // true
version.new("1.0.0").sat("= 1.0.0") // true
version.new("0.12.7").sat("~> 0.12.0") // true