-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
feat(isIBAN): add white and blacklist options to the isIBAN validator #2235
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #2235 +/- ##
=======================================
Coverage 99.95% 99.95%
=======================================
Files 107 107
Lines 2414 2431 +17
Branches 607 614 +7
=======================================
+ Hits 2413 2430 +17
Partials 1 1
☔ View full report in Codecov by Sentry. |
README.md
Outdated
@@ -121,7 +121,7 @@ Validator | Description | |||
**isHexadecimal(str)** | check if the string is a hexadecimal number. | |||
**isHexColor(str)** | check if the string is a hexadecimal color. | |||
**isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification][CSS Colors Level 4 Specification].<br/><br/>Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). | |||
**isIBAN(str)** | check if the string is an IBAN (International Bank Account Number). | |||
**isIBAN(str)** | check if the string is an IBAN (International Bank Account Number).<br/><br/>Also allows you to define a whitelist, when you only want to recieve IBAN codes from certain countries or a blacklist, removing some of them from the current list. |
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.
Could you elaborate on how you can define this? Like we explain the options
object in other validators as well. Also with the list of supported country codes
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.
@WikiRik I have updated and put which attributes it will receive and also the values that can be used in each of them.
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.
Can you undo the style changes in README?
…or without formatting it
@WikiRik do you think this could be merged now? |
@pano9000 @profnandaa could you take a look on this feature, please? |
src/lib/isIBAN.js
Outdated
const isoCountryCodeInWhiteList = options.whitelist.includes(isoCountryCode); | ||
|
||
if (!isoCountryCodeInWhiteList) { | ||
throw new Error('IBAN code does not belong to one of the countries listed on whitelist!'); |
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.
nit: the pattern so far has not been to throw errors, just true/false. I'm not sure how to go about this one...
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.
I guess we can continue with the true/false approach and let the user decide how to treat this.
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.
Done @profnandaa
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.
LGTM.
Thanks, folks |
feat(isIBAN): add white and blacklist options to the isIBAN validator
In order to restrict the list of countries that I want to validate the IBAN against now we can pass the whitelist option with the country codes that I want to validate the code. Also if I want to remove a certain country from the validation now I will have the blacklist option and the countries passed there will be removed from validation.
So, if you use the isIBAN validator and pass a the whitelist option and the country from the IBAN code is not on the whitelist, it will return an error:
And if you use the same validator with the blacklist option it should return an error if the code passed is from one of the countries listed:
Checklist