Helpers for working with version strings in elm.json
files.
A guaranteed valid Elm version. All versions are 1.0.0
or greater.
one : Version
Version 1.0.0
for easy access.
compare : Version -> Version -> Basics.Order
Compare two versions:
v1 = fromString "1.0.0"
v2 = fromString "2.0.0"
v3 = fromString "3.0.0"
-- Maybe.map2 compare v1 v2 == Just LT
-- Maybe.map2 compare v2 v2 == Just EQ
-- Maybe.map2 compare v2 v1 == Just GT
toString : Version -> String
Convert a Version
to a String
that works in elm.json
toString one == "1.0.0"
fromString : String -> Maybe Version
Try to convert a String
into a Version
. The major, minor, and patch
numbers must all appear separated by dots:
fromString "1.0.0" == Just one
fromString "2.0.0" == Just ...
fromString "3-0-0" == Nothing
fromString "3.0" == Nothing
encode : Version -> Json.Encode.Value
Turn a Version
into a string for use in elm.json
decoder : Json.Decode.Decoder Version
Decode the version strings that appear in elm.json
toTuple : Version -> ( Basics.Int, Basics.Int, Basics.Int )
Turn a Version
into a tuple to extract the numbers as integers.
toTuple one == (1, 0, 0)
Maybe.map toTuple (fromString "2.0.4" ) == Just (2, 0, 4)
Maybe.map toTuple (fromString "7.3.10") == Just (7, 3, 10)
fromTuple : ( Basics.Int, Basics.Int, Basics.Int ) -> Maybe Version
Try to make a Version
from given numbers. This way you do not need
to turn things into strings for no reason. It can still fail if you give
negative numbers or versions below 1.0.0
:
fromTuple (1, 0, 0) == Just one
fromTuple (2, 0, 1) == Just ...
fromTuple (0, 0, 1) == Nothing