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

feat(isIBAN): add white and blacklist options to the isIBAN validator #2235

Merged
merged 4 commits into from Aug 3, 2023

Conversation

edilson
Copy link
Contributor

@edilson edilson commented Jun 14, 2023

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:

import isIBAN from 'validator/lib/isIBAN';

isIBAN('GB29NWBK60161331926819', { whitelist: ['IT'] })

Error: IBAN code does not belong to one of the countries listed on whitelist!

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:

import isIBAN from 'validator/lib/isIBAN';

isIBAN('GB29NWBK60161331926819', { blacklist: ['GB'] })

Error: IBAN code belongs to one of the countries listed on blacklist!

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

@codecov
Copy link

codecov bot commented Jun 14, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (4f63909) 99.95% compared to head (852c3fb) 99.95%.

❗ Current head 852c3fb differs from pull request most recent head bd34c0b. Consider uploading reports for the commit bd34c0b to get more accurate results

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           
Impacted Files Coverage Δ
src/lib/isIBAN.js 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

@WikiRik WikiRik left a 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?

@edilson
Copy link
Contributor Author

edilson commented Jun 26, 2023

@WikiRik do you think this could be merged now?

@edilson
Copy link
Contributor Author

edilson commented Jul 21, 2023

@pano9000 @profnandaa could you take a look on this feature, please?

const isoCountryCodeInWhiteList = options.whitelist.includes(isoCountryCode);

if (!isoCountryCodeInWhiteList) {
throw new Error('IBAN code does not belong to one of the countries listed on whitelist!');
Copy link
Member

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...

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

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

LGTM.

@profnandaa profnandaa merged commit f303d39 into validatorjs:master Aug 3, 2023
7 checks passed
@edilson
Copy link
Contributor Author

edilson commented Aug 3, 2023

Thanks, folks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants