Semver Functions
The Semver category provides semantic versioning operations that mirror the functionality of Semver nodes.
Available Functions
Parsing and Validation
Semver.parse(version)- Parses a version stringSemver.validate(version)- Validates a version string
Comparison
Semver.compare(a, b, operator)- Compares two versionsSemver.checkRange(version, range)- Checks if version matches a range
Getting Components
Semver.getMajor(version)- Gets the major version numberSemver.getMinor(version)- Gets the minor version numberSemver.getPatch(version)- Gets the patch version numberSemver.getPrerelease(version)- Gets the prerelease identifierSemver.getBuild(version)- Gets the build identifier
Incrementing Versions
Semver.incrementMajor(version)- Increments the major versionSemver.incrementMinor(version)- Increments the minor versionSemver.incrementPatch(version)- Increments the patch version
Setting Components
Semver.setMajor(version, value)- Sets the major versionSemver.setMinor(version, value)- Sets the minor versionSemver.setPatch(version, value)- Sets the patch versionSemver.setPrerelease(version, value)- Sets the prerelease identifierSemver.setBuild(version, value)- Sets the build identifier
Conversion
Semver.toString(version)- Converts version to string
Examples
Parsing and Validation
local version = Semver.parse("1.2.3")
local isValid = Semver.validate("1.2.3") -- Returns true
Comparison
local isNewer = Semver.compare("1.2.3", "1.2.2", ">") -- Returns true
local matches = Semver.checkRange("1.2.3", "^1.0.0") -- Returns true
Getting Components
local major = Semver.getMajor("1.2.3") -- Returns 1
local minor = Semver.getMinor("1.2.3") -- Returns 2
local patch = Semver.getPatch("1.2.3") -- Returns 3
local prerelease = Semver.getPrerelease("1.2.3-alpha") -- Returns "alpha"
local build = Semver.getBuild("1.2.3+build.1") -- Returns "build.1"
Incrementing
local nextMajor = Semver.incrementMajor("1.2.3") -- Returns "2.0.0"
local nextMinor = Semver.incrementMinor("1.2.3") -- Returns "1.3.0"
local nextPatch = Semver.incrementPatch("1.2.3") -- Returns "1.2.4"
Setting Components
local version = Semver.setMajor("1.2.3", 2) -- Returns "2.2.3"
local version = Semver.setMinor("1.2.3", 3) -- Returns "1.3.3"
local version = Semver.setPatch("1.2.3", 4) -- Returns "1.2.4"
Parameters
version- Version string (e.g., "1.2.3", "1.2.3-alpha", "1.2.3+build.1")range- Version range (e.g., "^1.0.0", "~1.2.0")operator- Comparison operator:"==","!=","<",">","<=",">="value- New value for the component
Return Values
- Parsing functions return version objects or strings
- Validation returns boolean
- Comparison returns boolean
- Get functions return numbers or strings
- Increment/Set functions return version strings
Related Nodes
- SemverParse Node
- SemverValidate Node
- SemverCompare Node
- SemverGetMajor Node
- And other Semver nodes...