Closed Emilios1995 closed 7 years ago
I like the approach, very nice example of how to create a [pred, errorMsg]
tuple.
const typeRule = (type) => [
isType(type),
(val, field) => typeMessage(type, field)
];
Just so I fully understand, this:
const isType = R.curry((type, field) => R.type(field) === type);
should be:
const isType = R.curry((type, val) => R.type(val) === type);
right?
Exactly! Sorry, my bad.
Yes, I think this is very cool!
We should add this to the 0.6
release. Will probably merge this tomorrow.
I also like the example
const validationRules = {
name: [typeRule("String")]
}
shows how nicely one can create rules.
@Emilios1995 Great work!
Thanks, I'm glad you liked it!
We should also document this in the API docs. I'll probably make a commit for that later.
We should als add a test, but I can write that one tomorrow, if you have no time for that.
@busypeoples I'll try to do both things tonight. I'll ping you tomorrow if I have any trouble.
Done! But I'm not sure if I left that test too complex or the docs too verbose. What do you think?
P.S. I would also love to see something like my typeRule
function somewhere in the readme, but I'll leave that to your consideration.
@Emilios1995 Thank you very much! I'll look into it in more detail in a couple of hours. But looks good after quickly going through the commits. I will merge later on today.
Regarding the typeRule
, definitely. That example you have is more than elegant, and displays nicely how one can compose rules to bigger rules etc.
It is very common to include the name of the field in the error message. I thought it convenient to include pass it when errorMessage is a function.
Here's how I'm using this feature (from my fork):