version | 1.0.0 |
license | MIT |
native-modules | False |
elm-version | 0.18.0 <= v < 0.19.0 |
Tag | 1.0.0 |
Committed At | 2018-07-29 06:20:15 UTC |
elm-lang/core | 5.1.1 <= v < 6.0.0 | 5.1.1 |
Provide a validator for elm.
elm-package install pastelInc/elm-validator
Export 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 ->
es
npm install -g elm-test
elm-test
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT