Version
This class describes a semantic version and related operations following the semver 2.0.0 specification. Instances of this class are immutable, which makes them thread-safe.
Samples
import io.github.z4kn4fein.semver.Inc
import io.github.z4kn4fein.semver.LooseVersionSerializer
import io.github.z4kn4fein.semver.Version
import io.github.z4kn4fein.semver.VersionSerializer
import io.github.z4kn4fein.semver.constraints.toConstraint
import io.github.z4kn4fein.semver.inc
import io.github.z4kn4fein.semver.nextMajor
import io.github.z4kn4fein.semver.nextMinor
import io.github.z4kn4fein.semver.nextPatch
import io.github.z4kn4fein.semver.nextPreRelease
import io.github.z4kn4fein.semver.satisfies
import io.github.z4kn4fein.semver.satisfiesAll
import io.github.z4kn4fein.semver.satisfiesAny
import io.github.z4kn4fein.semver.toVersion
import io.github.z4kn4fein.semver.toVersionOrNull
import io.github.z4kn4fein.semver.withoutSuffixes
import kotlinx.serialization.json.Json
fun main() {
//sampleStart
val version = "1.2.3-alpha.1+build.1".toVersion()
println("Version: $version")
println("Major: ${version.major}, Minor: ${version.minor}, Patch: ${version.patch}")
println("Pre-release: ${version.preRelease}")
println("Build metadata: ${version.buildMetadata}")
println("Is it pre-release? ${version.isPreRelease}")
println("Is it stable? ${version.isStable}")
// equality
println("Is 1.0.0 == 1.0.0? ${"1.0.0".toVersion() == "1.0.0".toVersion()}")
println("Is 1.0.0 == 1.0.1? ${"1.0.0".toVersion() == "1.0.1".toVersion()}")
// comparison
println("Is 1.0.1 > 1.0.0? ${"1.0.1".toVersion() > "1.0.0".toVersion()}")
println("Is 1.0.0-alpha.1 > 1.0.0-alpha.0? ${"1.0.0-alpha.1".toVersion() > "1.0.0-alpha.0".toVersion()}")
// range
println("Is 1.0.1 in 1.0.0 .. 1.0.2? ${"1.0.1".toVersion() in "1.0.0".toVersion().."1.0.2".toVersion()}")
// destructuring
print("Destructuring: ")
val (major, minor, patch, preRelease, build) = "1.0.0-alpha+build".toVersion()
print("$major $minor $patch $preRelease $build")
//sampleEnd
}
Constructors
Properties
Functions
Component function that returns the MAJOR number of the version upon destructuring.
Component function that returns the MINOR number of the version upon destructuring.
Component function that returns the PATCH number of the version upon destructuring.
Component function that returns the PRE-RELEASE identifier of the version upon destructuring.
Component function that returns the BUILD metadata of the version upon destructuring.
Increments the version by its MAJOR number. When the preRelease parameter is set, a pre-release version will be produced from the next MAJOR version. The value of preRelease will be the first pre-release identifier of the new version.
Increments the version by its MINOR number. When the preRelease parameter is set, a pre-release version will be produced from the next MINOR version. The value of preRelease will be the first pre-release identifier of the new version.
Increments the version by its PRE-RELEASE identifier or produces the next pre-release of a stable version. The preRelease parameter's value is used for setting the pre-release identity when the version is stable or has a different pre-release name. If the version is already pre-release and the first identifier matches with the preRelease parameter, a simple incrementation will apply.
Determines whether a Version satisfies a Constraint or not.
Determines whether a Version satisfies each Constraint in a collection or not.
Determines whether a Version satisfies at least one Constraint in a collection or not.
Produces a copy of the Version without the PRE-RELEASE and BUILD METADATA identities.