elm / project-metadata-utils / Elm.Constraint

Helpers for working with version constraint strings in elm.json files.

Constraint


type Constraint

A guaranteed valid Elm constraint. That means the lower bound v1 and the upper bound v2 are both valid Elm.Version versions, and v1 <= v2 is guaranteed.

check : Elm.Version.Version -> Constraint -> Basics.Bool

Check if a version is within the given constraint:

import Elm.Version as V

oneToTwo = fromString "1.0.0 <= v < 2.0.0"
sixToTen = fromString "6.0.0 <= v < 10.0.0"

-- Maybe.map (check V.one) oneToTwo == Just True
-- Maybe.map (check V.one) sixToTen == Just False

String Conversions

toString : Constraint -> String

Convert a Constraint to a String that works in elm.json

fromString : String -> Maybe Constraint

Try to convert a String into a Constraint:

fromString "1.0.0 <= v < 2.0.0"   == Just ...
fromString "1.0.0 <= v < 10.0.0"  == Just ...
fromString "1.0.0 <= v <= 1.0.0"  == Just ...

fromString "1.0.0"                == Nothing
fromString "1.0.0 <= 2.0.0"       == Nothing
fromString "1.0.0 <=  v  < 2.0.0" == Nothing -- extra spaces
fromString "1.0.0 <= vsn < 2.0.0" == Nothing -- not "v" only
fromString "2.0.0 <= v < 1.0.0"   == Nothing -- unsatisfiable

JSON Conversions

encode : Constraint -> Json.Encode.Value

Turn a Constraint into a string for use in elm.json

decoder : Json.Decode.Decoder Constraint

Decode the constraint strings that appear in elm.json