[go: up one dir, main page]

Skip to content

sporto/gleam-valid

Repository files navigation

Valid

CI

A validation library for Gleam.

API Docs: https://hexdocs.pm/valid.

This library follows the principle Parse don't validate.

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 <test/basic_test.gleam>

Validators

  • For string validators, see <test/validator_string_test.gleam>
  • For int validators, see <test/validator_int_test.gleam>
  • For list validators, see <test/validator_list_test.gleam>
  • For optional validators, see <test/validator_option_test.gleam>
  • For creating a custom validator, see <test/validator_custom_test.gleam>

Composition

  • For composing validators, see <test/composition_test.gleam>

Other

  • For validating a dictionary, see <test/dictionary_test.gleam>
  • For custom error types, see <test/custom_error_test.gleam>
  • For validating a whole structure, see <test/whole_test.gleam>