Link to package: http://package.elm-lang.org/packages/esanmiguelc/elm-validate
Link to repository: https://github.com/esanmiguelc/elm-validate
Validation library inspired by ecto changeset validations. The idea behind this project is to be able to concatenate validations and ultimately get a ValidationResult
which provides all of the errors produced by the pipeline, which can then be used in any desired manner.
You start by adding beginValidation
which puts your Model
inside a context that allows it to be piped through all of the validations.
beginValidation {password = "somepass"}
|> validateLengthOf .password 8 "Password is too short"
Once you are done with it you can pattern match the result like so:
let
result =
beginValidation {email = "[email protected]", password = "somepass"}
|> validatePresenceOf .email "Email must be present"
|> validateLengthOf .password 8 "Password is too short"
in
case result of
Valid model ->
{- do stuff with a valid model here -}
( model, logUserIn model )
Err model errors ->
{- do stuff with the errors here -}
( { model | errors = errors }, Cmd.none )
After you have read the Code of conduct.
- Fork the repo.
- Write some tests.
- Make 'em pass
- Stuck? Ask a Question!
- Create a pull request - make sure your tests pass.
- Have a cup of ☕
- Clone the repository.
$ git clone [email protected]:esanmiguelc/elm-validate.git
- Make sure you have npm installed.
- Install dependencies.
$ npm install
- Run the tests
$ npm run test