Hey everyone, it’s me again with more good news from the validate
world!
I’m thrilled to announce that validate
has just leveled up to version 1.1.0! This update packs a bunch of new features and annotations that I’m sure you’ll find useful.
What’s New:
- New String Annotations:
@ulid
for ULID strings,@ipv4
and@ipv6
for IP addresses,@phone
for E.164 phone numbers, and@mac_address
for MAC addresses. These will help ensure your data formats are spot on. - Option Type Annotations: Introducing
@some
and@none
to assert presence or absence of values in option types. - Advanced Annotations:
@custom
: Create your own validation logic! It’s super flexible and allows you to define validations that suit your unique needs.@ignore_if
: Skip validations conditionally. Really handy for those complex data structures.@some_if
and@none_if
: Control the requirements ofSome
andNone
in option types based on conditions.
Dive into the Examples:
@custom
let custom_validator str =
if String.length str > 1 then Ok ()
else Error (Validate.BaseError { code = "custom_validator"; params = [] })
type custom_validator_record = {
custom_validator : string; [@custom custom_validator]
...
}
[@@deriving validate]
@ignore_if
type temperature_record = {
unit : string;
temperature : int; [@greater_than_or_equal 0] [@ignore_if fun r -> r.unit <> "K"]
}
[@@deriving validate]
@some_if
and @none_if
type contact_info = {
username : string option; [@some_if fun r -> r.email = None]
email : string option; [@none_if fun r -> Option.is_some r.username]
}
[@@deriving validate]
These new features add so much more depth and flexibility to validate
. I’m really excited to see how you all use them in your projects.
Check out all the details: GitHub - Axot017/validate.