1versions 2======== 3 4![](https://github.com/fosskers/versions/workflows/Tests/badge.svg) 5[![Hackage](https://img.shields.io/hackage/v/versions.svg?style=flat)](https://hackage.haskell.org/package/versions) 6[![Stackage Nightly](http://stackage.org/package/versions/badge/nightly)](http://stackage.org/nightly/package/versions) 7[![Stackage LTS](http://stackage.org/package/versions/badge/lts)](http://stackage.org/lts/package/versions) 8 9A Haskell library for parsing and comparing software version numbers. 10 11About 12----- 13We like to give version numbers to our software in a myriad of ways. Some 14ways follow strict guidelines for incrementing and comparison. Some follow 15conventional wisdom and are generally self-consistent. Some are just plain 16asinine. This library provides a means of parsing and comparing *any* style 17of versioning, be it a nice Semantic Version like this: 18 19> 1.2.3-r1+git123 20 21...or a monstrosity like this: 22 23> 2:10.2+0.0093r3+1-1 24 25Please switch to [Semantic Versioning](http://semver.org) if you aren't 26currently using it. It provides consistency in version incrementing and has 27the best constraints on comparisons. 28 29Usage 30----- 31In general, `versioning` is the function you want. It attempts to parse a given 32Text using the three individual parsers, `semver`, `version` and `mess`. If 33one fails, it tries the next. If you know you only want to parse one 34specific version type, use that parser directly (e.g. `semver`). 35 36#### Lenses and Traversals 37The parse result types have Lenses/Traversals for accessing their data 38fields. For instance, to increment the patch number of a parsed SemVer, you 39could: 40 41```haskell 42incPatch :: SemVer -> SemVer 43incPatch s = s & patch %~ (+ 1) 44``` 45 46Or, something more involved: 47 48```haskell 49-- | Get all major versions of legally parsed SemVers. 50majors :: [Text] -> [Word] 51majors vs = vs ^.. each . to semver . _Right . major 52``` 53 54The `to semver . _Right` is clunky, so we provide some direct `Text` 55Traverals inspired by 56([micro](http://hackage.haskell.org/package/microlens-aeson)) 57[lens-aeson](http://hackage.haskell.org/package/lens-aeson): 58 59```haskell 60-- | Get the major version of any `Text` that has one. 61majors :: [Text] -> [Word] 62majors vs = vs ^.. each . major 63``` 64 65We can also use these `Text` Traversals to increment versions, as above: 66 67```haskell 68incPatch :: Text -> Text 69incPatch s = s & patch %~ (+ 1) 70 71> incPatch "1.2.3" 72"1.2.4" 73``` 74