This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.0.1
Provide a validator for elm
version 1.0.2
license MIT
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.0.2
Committed At 2018-08-26 13:25:09 UTC
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1

Modules

README

elm-validator CircleCI

Provide a validator for elm.

Features

  • Custom validation
  • Multiple validations per field
  • Validations based on multiple fields

Installation

elm install pastelInc/elm-validator

Usage

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

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