pastelInc/elm-validator - version: 1.0.2

for more information visit the package's GitHub page

Package contains the following modules:

elm-validator CircleCI

Provide a validator for elm.

Features

Installation

elm install pastelInc/elm-validator

Usage

Export two functions and one type.

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

Tests

npm install -g elm-test@0.19.0-beta4
elm-test

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT