Crystal validator v1.0.0 released - Data validator / validation rules

Hello,

∠(・.-)―〉 →◎ validator is a Crystal data validation module.

After a few months of use in production, Crystal Validator has been released to version 1. :partying_face:

This version adds (optional) validation rules. Inspired by Laravel framework’s Validator (PHP) and Mongoose ODM data validation (Node.js), as well as data cleaning and formatting (optional also). It makes data cleaning and data validation in Crystal very easy! With self-generated granular methods for cleaning and checking data of each field (Hash / Class).

More details on the README: Validation rules

2 Likes

It looks like you are using regex for some of the validations. Do you know what the performance it like with this?

I didn’t benchmark on validators using Regex, I didn’t notice any particular bottleneck. The validators I mainly use are for models (Granite) and don’t use Regex, like: between, min, max, not_empty, in, presence, size, lower, upper, starts, ends.

For special cases such as the user account, I use the validators: email and url (Regex).

There is also a latitudes and longitudes validation (Regex) tested with a few hundred req/s, it works well. I think it can go much higher (a few thousand req/s).

The first bottleneck will be the database and not the data validation with Regex.

The other validators that use Regex, are special cases such as: url, email, domain, ip, ipv4, ipv6, magnet_uri, jwt, uuid, lat / lnt. I don’t need them in my main (most requested) routes. I use in an administration interface and a CLI: ip, domain, uuid, jwt, lat / lnt, hex, hex_color, …