A library for parsing, querying, and ordering the always faithful, always loyal semantic versions
Add the following to your sbt build definition
libraryDependencies += "me.lessis" % "semverfi" % "0.1.3"
Using ls
ls-install semverfi
import semverfi._
val patches =
Map("normal" -> "1.0.1",
"pre-release" -> "1.0.2-alpha.1",
"build" -> "1.0.3-alpha.1+build10",
"garbage" -> "asfnaasfiasdf")
.values
.map(Version.apply)
.map({
case n @ NormalVersion(_, _, p) =>
p
case pr @ PreReleaseVersion(_, _, p, _) =>
p
case b @ BuildVersion(_, _, p, _, _) =>
p
case i @ Invalid(in) =>
println("%s was invalid" format in)
i.patch
})
The semver specification defines precedence rules for how to order versions. This library abides by those rules.
import semverfi._
import scala.util.Random.shuffle
val expected = List("1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0-rc.1+build.1", "1.0.0", "1.0.0+0.3.7", "1.3.7+build", "1.3.7+build.2.b8f12d7", "1.3.7+build.11.e0f985a")
val shuffled = shuffle(expected)
val parsed = shuffled.map(Version.apply)
// print list of sorted versions zipped with expected input
(parsed.sorted zip expected).foreach(println)
import semverfi._
Version("1.1.1").opt { version =>
println(version.bumpMajor) // NormalVersion(2,0,0)
println(version.bumpMinor) // NormalVersion(1,2,0)
println(version.bumpPatch) // NormalVersion(1,1,2)
}
import semverfi._
Version("1.1.1").opt.map(_.prerelease("SNAPSHOT").build("123").normalize)
Doug Tangren (softprops) 2012