glerd_valid

Package Version Hex Docs Erlang-compatible JavaScript-compatible

Gleam Record validators using Glerd metadata

gleam add --dev glerd glerd_valid

1. Describe your records with validation metadata

Example:

pub type User {
  /// valid:age:'gte=18, lt=150'
  /// valid:name:'gte=3, lt=100'
  User(age: Int, name: String)
}

2. Generate Records info

Use Glerd

3. Make module for validators generation

my_module.gleam
import glerd_valid
import glerd_gen

pub fn main() {
  glerd_gen.record_info
  |> glerd_valid.generate("src", _)
}

4. Gen validators

gleam run -m my_module

Further documentation can be found at https://hexdocs.pm/glerd_valid.

Supported metadata

operatortypedescription
gte, minInt, Float, String (length)should be greater than or equal to
gtInt, Float, String (length)should be greater than
lte, maxInt, Float, String (length)should be less than or equal to
ltInt, Float, String (length)should be less than
eqInt, Float, String, Boolshould be equal to
neInt, Float, String, Boolshould not be equal to

Development

gleam test # and then commit generated file
Search Document