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 Cat {
  /// valid:name:length:'gte=3, lt=50'
  /// valid:lives_count:self:'min=1, max=9'
  Cat(name: String, lives_count: Int)
}

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

Operators

operatordescription
gte, minshould be greater than or equal to
gtshould be greater than
lte, maxshould be less than or equal to
ltshould be less than
eqshould be equal to
neshould not be equal to

Levels

leveldescription
selfcheck on Record field itself
lengthcheck on Record field length

Compatibility

operatorleveltype
gte, minselfInt
gte, minselfFloat
gte, minlengthString
gte, minlengthList
gtselfInt
gtselfFloat
gtlengthString
gtlengthList
lte, maxselfInt
lte, maxselfFloat
lte, maxlengthString
lte, maxlengthList
ltselfInt
ltselfFloat
ltlengthString
ltlengthList
eqselfInt
eqselfFloat
eqselfString
eqselfList
eqselfBool
eqlengthString
eqlengthList
neselfInt
neselfFloat
neselfString
neselfList
neselfBool
nelengthString
nelengthList

Development

gleam test # and then commit generated file
Search Document