-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add any
predicate
#56
Conversation
0fc4ef4
to
d0028a5
Compare
source/index.ts
Outdated
@@ -25,6 +26,18 @@ export interface Ow { | |||
* @param predicate Predicate used in the validator function. | |||
*/ | |||
create<T>(predicate: Predicate<T>): (value: T) => void; | |||
/** | |||
* Test the value for multiple predicates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test that the value matches at least one of the given predicates.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, much better!
d0028a5
to
afa2d04
Compare
Oh wow. That reminds me of https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es2015.promise.d.ts#L41-L113 We really need microsoft/TypeScript#5453 … |
Did you pick 8 for a reason? Can we make it 10? Still arbitrary, but feels better. |
Hehe, you're right, 10 is better. I just thought 8 was crazy enough. |
Yeah, makes sense. |
Might be a stupid question, but why couldn't this be |
@kevva Readability too. It's not clear whether it means ow(unicorn, [ow.string.startsWidth('foo'), ow.string.endsWidth('bar')]); Does it require a string that both starts with |
Yeah, sounds reasonable. On a similar note, wouldn't accepting an array in |
What typing issue? |
The one where we have to use an arbitrary number like 10 for the arguments :). |
Added the
any
method so you can write.I added typings for
any
with up to 8 parameters. The benefit is that the compiler can now also check (in the previous example) that1
should be of type string or number. So we get compile-time checking as well out of the box when we use 8 or less parameters.Secondly, I refactored the main Ow function. Now the predicate checks are done in the concrete predicate class itself. I believe this will make extending Ow much easier as we could now create an
OptionalPredicate
class that has it's own test function seperate from thePredicate
andAnyPredicate
class. Just check the code, hard to explain and I hope it makes sense :p.