Coder Social home page Coder Social logo

semverfi's Introduction

semverfi

Build Status

A library for parsing, querying, and ordering the always faithful, always loyal semantic versions

install

the cut and paste method

Add the following to your sbt build definition

libraryDependencies += "me.lessis" %% "semverfi" % "0.1.3"

the civilized method

Using ls

ls-install semverfi

usage.

it parses

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
    })

it orders

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)

it bumps ( valid versions )

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)
}

it transitions ( valid versions )

import semverfi._
Version("1.1.1").opt.map(_.prerelease("SNAPSHOT").build("123").normalize)

Doug Tangren (softprops) 2012

semverfi's People

Contributors

softprops avatar sroebuck avatar earldouglas avatar

Watchers

James Cloos avatar Gilad Hoch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.