Skip to content
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 host() and port() validators #55

Merged
merged 1 commit into from
Aug 26, 2017
Merged

Add host() and port() validators #55

merged 1 commit into from
Aug 26, 2017

Conversation

kachkaev
Copy link
Contributor

@kachkaev kachkaev commented Aug 26, 2017

Closes #51

I leveraged validator.js to avoid writing too much code. Only two files are being required from that module, so the overall library size does not grow by too much for those who decide to use it on the client side. This also opens a door to tens of other custom validators if there is a need for them in future. Perhaps, email() and url() could now also be switched to validator.js methods, but that's a topic for a different discussion.

Unfortunately, host() did not catch two edge cases due to validatorjs/validator.js#704, so I commented out two lines in the tests. Not crucial for the PR to get merged, but worth noting for future.

@kachkaev kachkaev mentioned this pull request Aug 26, 2017
Copy link
Collaborator

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@SimenB SimenB requested a review from af August 26, 2017 13:41
@af af merged commit 2af1e16 into af:master Aug 26, 2017
@af
Copy link
Owner

af commented Aug 26, 2017

This is great, thanks!

assert.equal(port().type, 'port')
const spec = { FOO: port() }

const with1 = cleanEnv({ FOO: '1' }, { FOO: num() })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that I should have used spec instead of { FOO: num() } here 😃

@kachkaev kachkaev mentioned this pull request Aug 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants