pastelInc/elm-validator/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Validator

This module supports validation.

type Rule error subject

Validation rules. You can create rules what have any type of validation method and error.

{ field : subject -> field
, method : field -> Bool
, validWhen : Bool
, error : error
}
-> Rule error subject

Create an rule.

rule
    { field = .age
    , method = (>) 18
    , validWhen = True
    , error = "Age must be greater than 18."
    }
validate : List (Rule error subject) -> subject -> Result (List error) subject

Validate a subject using rules.

validate
    [ rule
        { field = .age
        , method = (>) 18
        , validWhen = True
        , error = "Age must be greater than 18."
        }
    ]
    { age = 18 }