Skip to content

Commit

Permalink
fix: remove errors from the isIBAN validator
Browse files Browse the repository at this point in the history
  • Loading branch information
edilson committed Jul 24, 2023
1 parent e81e6d7 commit bd34c0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/lib/isIBAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ function hasValidIbanFormat(str, options) {

if (options.whitelist) {
if (!hasOnlyValidCountryCodes(options.whitelist)) {
throw new Error('One of the codes passed is invalid');
return false;
}

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

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

if (options.blacklist) {
const isoCountryCodeInBlackList = options.blacklist.includes(isoCountryCode);

if (isoCountryCodeInBlackList) {
throw new Error('IBAN code belongs to one of the countries listed on blacklist!');
return false;
}
}

Expand Down
8 changes: 3 additions & 5 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5257,7 +5257,7 @@ describe('Validators', () => {
'DK5000400440116243',
'GB29NWBK60161331926819',
],
error: [
invalid: [
'BE71 0961 2345 6769',
'FR76 3000 6000 0112 3456 7890 189',
'DE91 1000 0000 0123 4567 89',
Expand All @@ -5275,7 +5275,7 @@ describe('Validators', () => {
test({
validator: 'isIBAN',
args: [{ whitelist: ['XX', 'AA'] }],
error: [
invalid: [
'DK5000400440116243',
'GB29NWBK60161331926819',
'BE71 0961 2345 6769',
Expand Down Expand Up @@ -5318,15 +5318,13 @@ describe('Validators', () => {
'IR200170000000339545727003',
'MZ97123412341234123412341',
],
error: [
'IT60X0542811101000000123456',
],
invalid: [
'XX22YYY1234567890123',
'FR14 2004 1010 0505 0001 3',
'FR7630006000011234567890189@',
'FR7630006000011234567890189😅',
'FR763000600001123456!!🤨7890189@',
'IT60X0542811101000000123456',
],
});
});
Expand Down

0 comments on commit bd34c0b

Please sign in to comment.