-
Notifications
You must be signed in to change notification settings - Fork 74
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 startsWith and endsWith for URLs. #6
Conversation
You can do this now with |
Ah yes - true, but I try to keep RegExp out of my tests for clarity. Thanks for considering :) |
@@ -31,6 +31,8 @@ Lead Maintainer - [Eran Hammer](https://github.com/hueniverse) | |||
- [`null()`](#null) | |||
- [`undefined()`](#undefined) | |||
- [`include(values)`](#includevalues) | |||
- [`startWith(value)`](#startWith) |
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.
The link target should be #startwithvalue
.
@cjihrig all yours now... |
Thanks @cjihrig and @hueniverse - I'll get on these fixes asap. |
@antony any update on this? |
@cjihrig Sorry - absolutely snowed under at the moment with my startup - i'll sync with upstream as soon as I get a free minute and make the changes. Sorry about the delay! |
Hi @cjihrig - grabbed a couple of minutes to go through your suggestions. I've restricted the assertion to strings only - I toyed with arrays for a while but I couldn't think of a decent use case where you wouldn't assert more explicitly so I've gone with a string-only assertion. Please let me know if there are any further suggestions. |
|
||
internals.assert(this, typeof this._ref === 'string' && typeof value === 'string', 'Can only assert endsWith on a string, with a string'); | ||
|
||
var comparator = this._ref.slice(-Math.abs(value.length)); |
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.
Is Math.abs
necessary in this context? It does add some overhead and I don't think we really need it.
You should probably note that it's case sensitive since we are just using simple |
… index before negating
@arb I've updated the PR as per your suggestions, Thanks! |
Add startsWith and endsWith for URLs.
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. |
I realise that this library is intended to be as small and light as possible - but I think these two assertions are essential for assertions on urls - redirects - domains etc, especially when considering the code+lab marriage.
Include goes part of the way, but checking a relative url when given an absolute url and checking schemes on domains are something I end up doing every day, hence this PR.