parse

fun parse(versionString: String, strict: Boolean = true): Version(source)

Parses the versionString as a Version and returns the result or throws a VersionFormatException if the string is not a valid representation of a semantic version.

Strict mode is on by default, which means partial versions (e.g. '1.0' or '1') and versions with 'v' prefix are considered invalid. This behaviour can be turned off by setting strict to false.

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 
   println(Version.parse("1.0.0-alpha.1+build.1")) 
   //sampleEnd
}
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 
   println(Version.parse("v1.0-alpha.1+build.1", strict = false))
println(Version.parse("1-alpha", strict = false))
println(Version.parse("2", strict = false)) 
   //sampleEnd
}