glerd_valid
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
operator | type | description |
---|---|---|
gte, min | Int, Float, String (length) | should be greater than or equal to |
gt | Int, Float, String (length) | should be greater than |
lte, max | Int, Float, String (length) | should be less than or equal to |
lt | Int, Float, String (length) | should be less than |
eq | Int, Float, String, Bool | should be equal to |
ne | Int, Float, String, Bool | should not be equal to |
Development
gleam test # and then commit generated file