The versions package

[ Tags: bsd3, data, library ] [ Propose Tags ]

A library for parsing and comparing software version numbers. We like to give version numbers to our software in a myriad of ways. Some ways follow strict guidelines for incrementing and comparison. Some follow conventional wisdom and are generally self-consistent. Some are just plain asinine. This library provides a means of parsing and comparing any style of versioning, be it a nice Semantic Version like this:

1.2.3-r1+git123

...or a monstrosity like this:

2:10.2+0.0093r3+1-1

Please switch to Semantic Versioning if you aren't currently using it. It provides consistency in version incrementing and has the best constraints on comparisons.


[Skip to Readme]

Properties

Versions 1.0.0, 1.0.1, 1.0.2, 1.1.0, 2.0.0, 3.0.0, 3.0.1, 3.0.1.1, 3.0.2, 3.0.2.1, 3.1.0, 3.1.0.1, 3.1.1, 3.2.0 (info)
Change log CHANGELOG.md
Dependencies base (>=4.8 && <4.11), deepseq (==1.4.*), hashable (==1.2.*), megaparsec (==6.*), text (==1.2.*) [details]
License BSD3
Author Colin Woodbury
Maintainer colingw@gmail.com
Category Data
Source repository head: git clone git://github.com/fosskers/haskell-versions.git
Uploaded Thu Jul 27 15:51:16 UTC 2017 by fosskers
Distributions LTSHaskell:3.1.1, NixOS:3.2.0, Tumbleweed:3.0.2.1
Downloads 1709 total (30 in the last 30 days)
Rating 2.25 (2 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-07-27 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for versions-3.2.0

[back to package description]

versions

Build Status Hackage Stackage Nightly Stackage LTS

A Haskell library for parsing and comparing software version numbers.

About

We like to give version numbers to our software in a myriad of ways. Some ways follow strict guidelines for incrementing and comparison. Some follow conventional wisdom and are generally self-consistent. Some are just plain asinine. This library provides a means of parsing and comparing any style of versioning, be it a nice Semantic Version like this:

1.2.3-r1+git123

...or a monstrosity like this:

2:10.2+0.0093r3+1-1

Please switch to Semantic Versioning if you aren't currently using it. It provides consistency in version incrementing and has the best constraints on comparisons.

Usage

In general, parseV is the function you want. It attempts to parse a given Text using the three individual parsers, semver, version and mess. If one fails, it tries the next. If you know you only want to parse one specific version type, use that parser directly (e.g. semver).

Lenses and Traversals

The parse result types have Lenses/Traversals for accessing their data fields. For instance, to increment the patch number of a parsed SemVer, you could:

incPatch :: SemVer -> SemVer
incPatch s = s & svPatch %~ (+ 1)

Or, something more involved:

-- | Get all major versions of legally parsed SemVers.
majors :: [Text] -> [Int]
majors vs = vs ^.. each . to semver . _Right . svMajor

The to semver . _Right is clunky, so we provide some direct Text Traverals inspired by (micro) lens-aeson:

-- | Get all major versions of legally parsed SemVers.
majors :: [Text] -> [Int]
majors vs = vs ^.. each . _SemVer . svMajor

Note that _SemVer only attempts to parse as true Semantic Versioning. If the package versions you're parsing don't agree to a standard, you can achieve a similar result via:

-- | Get all major versions of potentially parsed SemVers.
majors :: [Text] -> [Int]
majors vs = vs ^.. each . _Versioning . _Ideal . svMajor

We can also use these Text Traversals to increment versions, as above:

incPatch :: Text -> Text
incPatch s = s & _SemVer . svPatch %~ (+ 1)

> incPatch "1.2.3"
"1.2.4"