package validator

All checked builds pass
  1. Overview
  2. Docs
Create a record validator via composable sub-validators

Install

dune-project
 Dependency

Authors

Maintainers

Sources

validator-0.2.3.tbz
sha256=c54012be18ee9ebe850b0f051fd3ffc5ffd86879c9f74a7133c97a77ce9ab6ce
sha512=8a392666a3afc7637551f81cdcecb2071c048844552fe4cd28d4314b6229bb19bd7197460c509fa82bf9bdcf5e76b3b89d0a98963689b98dd7d9f8596e031ed2

Description

Create a record validator via composable sub-validators

Added to opam-repository:

README

Validator

CI

Create a record validator via composable sub-validators

Installation

Using Opam

opam install validator

Using Esy

esy add @opam/validator

Usage

In OCaml

type input_form = {
  name: string;
  email: string option;
  age: int;
}

type valid_form = {
  name: string;
  email: string;
  age: int;
}

let build_valid_form name email age =
  { name; email; age }

let validator_name =
  let open Validator in
  string_is_not_empty "Empty"
  |> compose
    (string_has_min_length 3 "Name is too short")

let validator_email =
  let open Validator in
  option_is_some "Missing email"
  |> compose (string_is_email "Not an email")

let validator_age =
  let open Validator in
  int_min 13 "Must be 13"

let validator (input: input_form) =
  let open Validator in
  build build_valid_form
  |> validate input.name validator_name
  |> validate input.email validator_email
  |> validate input.age validator_age

validator { name = "Sam"; email = Some "sam@sample.com"; age = 20}

==>

Ok { name = "Sam"; email = "sam@sample.com"; age = 20}

Contributing

Take a look at our Contributing Guide.

Dependencies (2)

  1. dune >= "2.7"
  2. ocaml >= "4.08.0"

Dev Dependencies (3)

  1. odoc with-doc
  2. ppx_deriving with-test
  3. alcotest with-test

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building validator with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.2.3 (this version) good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure