Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/esanmiguelc/elm-validate
Validation library inspired by ecto changeset validations.
https://github.com/esanmiguelc/elm-validate
elm validations
Last synced: about 2 months ago
JSON representation
Validation library inspired by ecto changeset validations.
- Host: GitHub
- URL: https://github.com/esanmiguelc/elm-validate
- Owner: esanmiguelc
- License: mit
- Created: 2017-07-09T03:32:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T13:45:00.000Z (almost 2 years ago)
- Last Synced: 2023-09-18T04:20:30.892Z (over 1 year ago)
- Topics: elm, validations
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/esanmiguelc/elm-validate
- Size: 54.7 KB
- Stars: 7
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# elm-validate
[![Build Status](https://travis-ci.org/esanmiguelc/elm-validate.svg?branch=master)](https://travis-ci.org/esanmiguelc/elm-validate)
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.
## The Gist:
You start by adding `beginValidation` which puts your `Model` inside a context that allows it to be piped through all of the validations.
```elm
beginValidation {password = "somepass"}
|> validateLengthOf .password 8 "Password is too short"
```Once you are done with it you can pattern match the result like so:
```elm
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 )
```## Contributing
After you have read the [Code of conduct](CODE_OF_CONDUCT.md).
1. Fork the repo.
2. Write some tests.
3. Make 'em pass
4. Stuck? Ask a Question!
5. Create a pull request - make sure your tests pass.
6. Have a cup of :coffee:### Setting up
1. Clone the repository.
```bash
$ git clone [email protected]:esanmiguelc/elm-validate.git
```2. Make sure you have [npm](https://www.npmjs.com/get-npm) installed.
3. Install dependencies.```bash
$ npm install
```4. Run the tests
```bash
$ npm run test
```