Toggable ordered flag for array to match items against input in order#688
Toggable ordered flag for array to match items against input in order#688Marsup merged 1 commit intohapijs:masterfrom
Conversation
lib/array.js
Outdated
|
@Marsup Thanks for your feedback. I've fixed what I could. Can you explain what is the purpose of strip option? I couldn't find a good example in the lib/array.js. |
README.md
Outdated
There was a problem hiding this comment.
You're still documenting things that have little to do with this method, the type is not in the method's signature.
|
The strip flag is a consequence of the call of any.strip(), it's used just below, you should be able to understand the goal with the docs. |
|
@Marsup Thanks for your comment... Please review. Got the strip() implemented now. Missed the LF because JSlint wasn't complaining. Let me know if there are any more changes to do. |
lib/array.js
Outdated
There was a problem hiding this comment.
Careful with the index here, if your test didn't strip the last one it would fail, you have to change v.
|
@Marsup Please review. |
|
Sorry for the delay, busy days... One last thing, would you mind including all the |
|
No worries. |
|
Hey, sorry again I'm a bit slow on this one, I had to think about it for a while :)
Does it look like something you can achieve ? |
|
No worries. I don't have a specific need for this feature. I'm contributing to learn. So, no rush...
|
|
The 1st problem doesn't exist currently since loops on values and schemas are not tied together, unlike what you have to do here. The use case cannot be covered with current API. I'm starting to think an even more powerful construct would be for |
|
Can you explain more in detail because I'm a bit lost here? Like What about count of items in array? Should it pass if it doesn't match? Maybe not? Because that use case can be validated against |
|
Let's take that example : Joi.array()
.ordered(Joi.string().required(), Joi.boolean().required(), Joi.number())
.items(Joi.date())It would match anything containing at least a string and a boolean, optionally a number, then any number of dates. |
|
+1 on the PR as it is. My main use case is supporting tuples (e.g. to serialize ordered maps as arrays of key/value tuples). I'm not sure how common the use case @Marsup is describing is as I haven't come across it myself yet. I think a more common example would be |
|
Nice...!! I will give that a shot. |
|
Sorry, I didn't get to work on this PR this week. 😞 And it would need to be put on hold for a couple of weeks while I'm travelling. |
|
I think we're missing a test case (which would probably fail) where there are fewer elements than the number of required ordered items. |
|
Yes. You are right. That test case will fail. 😞 I will fix it tomorrow. |
|
@Marsup Please review. |
lib/array.js
Outdated
There was a problem hiding this comment.
Those 2 lines should be written :
var ordered = ordereds.shift();|
Very good job so far, we're getting to the final details :) 👍 |
|
Thanks, @Marsup. Please review. |
lib/array.js
Outdated
There was a problem hiding this comment.
There is no need to splice here, just build a new array out of the required schemas.
|
Done. Please review. |
lib/array.js
Outdated
There was a problem hiding this comment.
You're not going to be using this flag, this line can be removed.
|
Those were the final ones, ready to merge after that :) |
|
Cool. All done now. :) |
Toggable ordered flag for array to match items against input in order
|
Congrats, hope it was not too painful :) |
|
Nice!! It was more fun than painful. :) Do let me know if you have other -CK-
|
|
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Feel free to ping me for suggestion/feedback on my code. Happy to change them if necessary.
closes #659