Provide a validator for elm.
elm install pastelInc/elm-validatorExport two functions and one type.
Rule is validation rule.rule return Rule.validate return Result (List error) subject that is validated subject.import Validator exposing (Rule, rule, validate)
ageValidator : Rule String { age : Int }
ageValidator =
rule
{ field = .age
, method = (>) 18
, validWhen = True
, error = "Age must be greater than 18."
}
isValidAge : { age : Int } -> Bool
isValidAge model =
case validate [ ageValidator ] model of
Ok _ ->
True
Err _ ->
False
ageErrors : { age : Int } -> List String
ageErrors model =
case validate [ ageValidator ] model of
Ok _ ->
[]
Err es ->
esnpm install -g [email protected]
elm-testgit checkout -b my-new-featuregit commit -am 'Add some feature'git push origin my-new-featureMIT