Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sporto/gleam-valid

Validation library for Gleam
https://github.com/sporto/gleam-valid

gleam gleam-lang

Last synced: about 1 month ago
JSON representation

Validation library for Gleam

Awesome Lists containing this project

README

        

# Valid

![CI](https://github.com/sporto/gleam-valid/workflows/test/badge.svg?branch=main)

A validation library for [Gleam](https://gleam.run/).

API Docs: .

This library follows the principle [Parse don't validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/).

```gleam
fn user_validator(user: InputUser) -> ValidatorResult(ValidUser, String) {
valid.build3(ValidUser)
|> valid.check(user.name, valid.is_some("Please provide a name"))
|> valid.check(user.email, valid.is_some("Please provide an email"))
|> valid.check(user.age, valid.ok())
}

case user_valid(input) {
Ok(valid_user) -> ...
Error(errors) -> ...
}
```

## Install

```
gleam add valid
```

## Usage and Examples

- For basic usage see

### Validators

- For string validators, see
- For int validators, see
- For list validators, see
- For optional validators, see
- For creating a custom validator, see

### Composition

- For composing validators, see

### Other

- For validating a dictionary, see
- For custom error types, see
- For validating a whole structure, see