My first library project - exvalidate

hei all!!

to continue progressing with elixir and improve my attitudes. I have created this library to validate data in elixir either as middleware or validation in a module.

I have published it on hex.pm, It has been a great learning exercise and I would love feedback.

Thanks in advance.

Carlos.

4 Likes

Nice one :slight_smile: well done!

Smal note: I couldn’t follow what this example was supposed to demonstrate:

  iex(3)> Exvalidate.Rules.MaxLength.validating({:max_length, 3}, {"Vegeta"})
  {:error, :max_length_greater_than_max}

I’m guessing this should’ve been more like the one for lists right above it?

Bigger note: it doesn’t feel like Exvalidate.Rules.Type matches the purpose of the library - it doesn’t validate the incoming type for some types, it casts them! (booleans and numbers)

Overall, I’d suggest being more specific about what particular kind of validation the library wants to do; right now, there’s a strong sense that it’s for “parameters from the user” - based on things like defining the schema with atom keys but the input having string keys - but then validating that some inputs are atoms doesn’t seem useful since users can’t send those…

1 Like

looks great! something you may want to think about. In the BEAM we typically store IPv4 values as a tuple of 4 bytes, like {127, 0, 0, 1}, you may want to consider whether it’s in-scope to go ahead and also do the type conversion (is this consistent? If you get passed a string that’s a number, does exvalidate convert to number, e.g.)

Also, I recommend instead of using a regex, using erlang’s builtin ipv4 parsing utilities (:inet.parse_address/1), which will also let you do ipv6, or (shameless plug) I have a library that does that sort of thing and a lot more called “net_address”.

1 Like

first thank you for commenting.

About small note: is an example of an error exceeding the defined maximum length, is it possible that the error message has confused you? I’m looking at the error atoms and they are a bit confusing.

About big note: my intention was to be able to validate the data types of elixir, but it is true that it also works as a parse, I will think about your advice.

Thanks you!!.

thanks for the suggestion, i will think and investigate about it. when i did the ipv4 validation i did not stop to investigate.

Thank you.

1 Like

Haha you’re just starting; we’re here to point you to all the goodies the erlang vm ships with.