Comparing version 4.1.4 to 4.1.5
@@ -11,3 +11,3 @@ /*! | ||
* @module ibantools | ||
* @version 4.1.4 | ||
* @version 4.1.5 | ||
* @license MPL-2.0 | ||
@@ -31,17 +31,12 @@ * @preferred | ||
function isValidIBAN(iban) { | ||
if (iban !== undefined && iban !== null) { | ||
var reg = new RegExp('^[0-9]{2}$', ''); | ||
var spec = exports.countrySpecs[iban.slice(0, 2)]; | ||
if (spec !== undefined && | ||
spec.bban_regexp && | ||
spec.bban_regexp !== null && | ||
spec.chars && | ||
spec.chars === iban.length && | ||
reg.test(iban.slice(2, 4)) && | ||
isValidBBAN(iban.slice(4), iban.slice(0, 2)) && | ||
isValidIBANChecksum(iban)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
if (iban === undefined || iban === null) | ||
return false; | ||
var reg = new RegExp('^[0-9]{2}$', ''); | ||
var spec = exports.countrySpecs[iban.slice(0, 2)]; | ||
if (spec === undefined || spec.bban_regexp === undefined || spec.bban_regexp === null || spec.chars === undefined) | ||
return false; | ||
return (spec.chars === iban.length && | ||
reg.test(iban.slice(2, 4)) && | ||
isValidBBAN(iban.slice(4), iban.slice(0, 2)) && | ||
isValidIBANChecksum(iban)); | ||
} | ||
@@ -120,17 +115,17 @@ exports.isValidIBAN = isValidIBAN; | ||
function isValidBBAN(bban, countryCode) { | ||
if (bban !== undefined && bban !== null && countryCode !== undefined && countryCode !== null) { | ||
var spec = exports.countrySpecs[countryCode]; | ||
if (spec !== undefined && | ||
spec !== null && | ||
spec.bban_regexp && | ||
spec.bban_regexp !== null && | ||
spec.chars && | ||
spec.chars !== null && | ||
spec.chars - 4 === bban.length && | ||
checkFormatBBAN(bban, spec.bban_regexp)) { | ||
if (spec.bban_validation_func) { | ||
return spec.bban_validation_func(bban.replace(/[\s.]+/g, '')); | ||
} | ||
return true; | ||
if (bban === undefined || bban === null || countryCode === undefined || countryCode === null) | ||
return false; | ||
var spec = exports.countrySpecs[countryCode]; | ||
if (spec === undefined || | ||
spec === null || | ||
spec.bban_regexp === undefined || | ||
spec.bban_regexp === null || | ||
spec.chars === undefined || | ||
spec.chars === null) | ||
return false; | ||
if (spec.chars - 4 === bban.length && checkFormatBBAN(bban, spec.bban_regexp)) { | ||
if (spec.bban_validation_func) { | ||
return spec.bban_validation_func(bban.replace(/[\s.]+/g, '')); | ||
} | ||
return true; | ||
} | ||
@@ -198,6 +193,7 @@ return false; | ||
var result = {}; | ||
result.iban = iban; | ||
if (isValidIBAN(iban)) { | ||
result.bban = iban.slice(4); | ||
result.countryCode = iban.slice(0, 2); | ||
var eFormatIBAN = electronicFormatIBAN(iban); | ||
result.iban = eFormatIBAN || iban; | ||
if (!!eFormatIBAN && isValidIBAN(eFormatIBAN)) { | ||
result.bban = eFormatIBAN.slice(4); | ||
result.countryCode = eFormatIBAN.slice(0, 2); | ||
result.valid = true; | ||
@@ -270,22 +266,44 @@ } | ||
function isValidIBANChecksum(iban) { | ||
var countryCode = iban.slice(0, 2); | ||
var providedChecksum = parseInt(iban.slice(2, 4), 10); | ||
var temp = iban.slice(3) + iban.slice(0, 2) + '00'; | ||
var validationString = ''; | ||
for (var n = 1; n < temp.length; n++) { | ||
var c = temp.charCodeAt(n); | ||
if (c >= 65) { | ||
validationString += (c - 55).toString(); | ||
} | ||
else { | ||
validationString += temp[n]; | ||
} | ||
} | ||
while (validationString.length > 2) { | ||
var part = validationString.slice(0, 6); | ||
validationString = (parseInt(part, 10) % 97).toString() + validationString.slice(part.length); | ||
} | ||
var rest = parseInt(validationString, 10) % 97; | ||
var bban = iban.slice(4); | ||
// Wikipedia[validating_iban] says there are a specif way to check if a IBAN is valid but | ||
// it. It says 'If the remainder is 1, the check digit test is passed and the | ||
// IBAN might be valid.'. might, MIGHT! | ||
// We don't want might but want yes or no. Since every BBAN is IBAN from the fifth | ||
// (slice(4)) we can generate the IBAN from BBAN and country code(two first characters) | ||
// from in the IBAN. | ||
// To generate the (generate the iban check digits)[generating-iban-check] | ||
// Move the country code to the end | ||
// remove the checksum from the begging | ||
// Add "00" to the end | ||
// modulo 97 on the amount | ||
// subtract remainder from 98, (98 - remainder) | ||
// Add a leading 0 if the remainder is less then 10 (padStart(2, "0")) (we skip this | ||
// since we compare int, not string) | ||
// | ||
// [validating_iban][https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN] | ||
// [generating-iban-check][https://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits] | ||
var validationString = replaceCharaterWithCode("".concat(bban).concat(countryCode, "00")); | ||
var rest = mod9710(validationString); | ||
return 98 - rest === providedChecksum; | ||
} | ||
/** | ||
* Iban contain characters and should be converted to intereger by 55 substracted | ||
* from there ascii value | ||
* | ||
* @ignore | ||
*/ | ||
function replaceCharaterWithCode(str) { | ||
// It is slower but alot more readable | ||
// https://jsbench.me/ttkzgsekae/1 | ||
return str | ||
.split('') | ||
.map(function (c) { | ||
var code = c.charCodeAt(0); | ||
return code >= 65 ? (code - 55).toString() : c; | ||
}) | ||
.join(''); | ||
} | ||
/** | ||
* MOD-97-10 | ||
@@ -296,14 +314,3 @@ * | ||
function mod9710Iban(iban) { | ||
iban = iban.slice(3) + iban.slice(0, 4); | ||
var validationString = ''; | ||
for (var n = 1; n < iban.length; n++) { | ||
var c = iban.charCodeAt(n); | ||
if (c >= 65) { | ||
validationString += (c - 55).toString(); | ||
} | ||
else { | ||
validationString += iban[n]; | ||
} | ||
} | ||
return mod9710(validationString); | ||
return mod9710(replaceCharaterWithCode(iban.slice(3) + iban.slice(0, 4))); | ||
} | ||
@@ -337,6 +344,6 @@ /** | ||
countyMap[countyCode] = { | ||
chars: county.chars ? county.chars : null, | ||
bban_regexp: county.bban_regexp ? county.bban_regexp : null, | ||
IBANRegistry: county.IBANRegistry ? county.IBANRegistry : false, | ||
SEPA: county.SEPA ? county.SEPA : false, | ||
chars: county.chars || null, | ||
bban_regexp: county.bban_regexp || null, | ||
IBANRegistry: county.IBANRegistry || false, | ||
SEPA: county.SEPA || false, | ||
}; | ||
@@ -472,8 +479,13 @@ } | ||
while (validationString.length > 2) { | ||
// > Any computer programming language or software package that is used to compute D | ||
// > mod 97 directly must have the ability to handle integers of more than 30 digits. | ||
// > In practice, this can only be done by software that either supports | ||
// > arbitrary-precision arithmetic or that can handle 219-bit (unsigned) integers | ||
// https://en.wikipedia.org/wiki/International_Bank_Account_Number#Modulo_operation_on_IBAN | ||
var part = validationString.slice(0, 6); | ||
var value = parseInt(part, 10) % 97; | ||
if (isNaN(value)) { | ||
var partInt = parseInt(part, 10); | ||
if (isNaN(partInt)) { | ||
return NaN; | ||
} | ||
validationString = value.toString() + validationString.slice(part.length); | ||
validationString = (partInt % 97) + validationString.slice(part.length); | ||
} | ||
@@ -1225,3 +1237,9 @@ return parseInt(validationString, 10) % 97; | ||
}, | ||
NO: { chars: 15, bban_regexp: '^[0-9]{11}$', bban_validation_func: checkNorwayBBAN, IBANRegistry: true, SEPA: true }, | ||
NO: { | ||
chars: 15, | ||
bban_regexp: '^[0-9]{11}$', | ||
bban_validation_func: checkNorwayBBAN, | ||
IBANRegistry: true, | ||
SEPA: true, | ||
}, | ||
NP: {}, | ||
@@ -1228,0 +1246,0 @@ NR: {}, |
@@ -11,3 +11,3 @@ /*! | ||
* @module ibantools | ||
* @version 4.1.4 | ||
* @version 4.1.5 | ||
* @license MPL-2.0 | ||
@@ -29,17 +29,12 @@ * @preferred | ||
export function isValidIBAN(iban) { | ||
if (iban !== undefined && iban !== null) { | ||
var reg = new RegExp('^[0-9]{2}$', ''); | ||
var spec = countrySpecs[iban.slice(0, 2)]; | ||
if (spec !== undefined && | ||
spec.bban_regexp && | ||
spec.bban_regexp !== null && | ||
spec.chars && | ||
spec.chars === iban.length && | ||
reg.test(iban.slice(2, 4)) && | ||
isValidBBAN(iban.slice(4), iban.slice(0, 2)) && | ||
isValidIBANChecksum(iban)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
if (iban === undefined || iban === null) | ||
return false; | ||
var reg = new RegExp('^[0-9]{2}$', ''); | ||
var spec = countrySpecs[iban.slice(0, 2)]; | ||
if (spec === undefined || spec.bban_regexp === undefined || spec.bban_regexp === null || spec.chars === undefined) | ||
return false; | ||
return (spec.chars === iban.length && | ||
reg.test(iban.slice(2, 4)) && | ||
isValidBBAN(iban.slice(4), iban.slice(0, 2)) && | ||
isValidIBANChecksum(iban)); | ||
} | ||
@@ -116,17 +111,17 @@ /** | ||
export function isValidBBAN(bban, countryCode) { | ||
if (bban !== undefined && bban !== null && countryCode !== undefined && countryCode !== null) { | ||
var spec = countrySpecs[countryCode]; | ||
if (spec !== undefined && | ||
spec !== null && | ||
spec.bban_regexp && | ||
spec.bban_regexp !== null && | ||
spec.chars && | ||
spec.chars !== null && | ||
spec.chars - 4 === bban.length && | ||
checkFormatBBAN(bban, spec.bban_regexp)) { | ||
if (spec.bban_validation_func) { | ||
return spec.bban_validation_func(bban.replace(/[\s.]+/g, '')); | ||
} | ||
return true; | ||
if (bban === undefined || bban === null || countryCode === undefined || countryCode === null) | ||
return false; | ||
var spec = countrySpecs[countryCode]; | ||
if (spec === undefined || | ||
spec === null || | ||
spec.bban_regexp === undefined || | ||
spec.bban_regexp === null || | ||
spec.chars === undefined || | ||
spec.chars === null) | ||
return false; | ||
if (spec.chars - 4 === bban.length && checkFormatBBAN(bban, spec.bban_regexp)) { | ||
if (spec.bban_validation_func) { | ||
return spec.bban_validation_func(bban.replace(/[\s.]+/g, '')); | ||
} | ||
return true; | ||
} | ||
@@ -191,6 +186,7 @@ return false; | ||
var result = {}; | ||
result.iban = iban; | ||
if (isValidIBAN(iban)) { | ||
result.bban = iban.slice(4); | ||
result.countryCode = iban.slice(0, 2); | ||
var eFormatIBAN = electronicFormatIBAN(iban); | ||
result.iban = eFormatIBAN || iban; | ||
if (!!eFormatIBAN && isValidIBAN(eFormatIBAN)) { | ||
result.bban = eFormatIBAN.slice(4); | ||
result.countryCode = eFormatIBAN.slice(0, 2); | ||
result.valid = true; | ||
@@ -260,22 +256,44 @@ } | ||
function isValidIBANChecksum(iban) { | ||
var countryCode = iban.slice(0, 2); | ||
var providedChecksum = parseInt(iban.slice(2, 4), 10); | ||
var temp = iban.slice(3) + iban.slice(0, 2) + '00'; | ||
var validationString = ''; | ||
for (var n = 1; n < temp.length; n++) { | ||
var c = temp.charCodeAt(n); | ||
if (c >= 65) { | ||
validationString += (c - 55).toString(); | ||
} | ||
else { | ||
validationString += temp[n]; | ||
} | ||
} | ||
while (validationString.length > 2) { | ||
var part = validationString.slice(0, 6); | ||
validationString = (parseInt(part, 10) % 97).toString() + validationString.slice(part.length); | ||
} | ||
var rest = parseInt(validationString, 10) % 97; | ||
var bban = iban.slice(4); | ||
// Wikipedia[validating_iban] says there are a specif way to check if a IBAN is valid but | ||
// it. It says 'If the remainder is 1, the check digit test is passed and the | ||
// IBAN might be valid.'. might, MIGHT! | ||
// We don't want might but want yes or no. Since every BBAN is IBAN from the fifth | ||
// (slice(4)) we can generate the IBAN from BBAN and country code(two first characters) | ||
// from in the IBAN. | ||
// To generate the (generate the iban check digits)[generating-iban-check] | ||
// Move the country code to the end | ||
// remove the checksum from the begging | ||
// Add "00" to the end | ||
// modulo 97 on the amount | ||
// subtract remainder from 98, (98 - remainder) | ||
// Add a leading 0 if the remainder is less then 10 (padStart(2, "0")) (we skip this | ||
// since we compare int, not string) | ||
// | ||
// [validating_iban][https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN] | ||
// [generating-iban-check][https://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits] | ||
var validationString = replaceCharaterWithCode("".concat(bban).concat(countryCode, "00")); | ||
var rest = mod9710(validationString); | ||
return 98 - rest === providedChecksum; | ||
} | ||
/** | ||
* Iban contain characters and should be converted to intereger by 55 substracted | ||
* from there ascii value | ||
* | ||
* @ignore | ||
*/ | ||
function replaceCharaterWithCode(str) { | ||
// It is slower but alot more readable | ||
// https://jsbench.me/ttkzgsekae/1 | ||
return str | ||
.split('') | ||
.map(function (c) { | ||
var code = c.charCodeAt(0); | ||
return code >= 65 ? (code - 55).toString() : c; | ||
}) | ||
.join(''); | ||
} | ||
/** | ||
* MOD-97-10 | ||
@@ -286,14 +304,3 @@ * | ||
function mod9710Iban(iban) { | ||
iban = iban.slice(3) + iban.slice(0, 4); | ||
var validationString = ''; | ||
for (var n = 1; n < iban.length; n++) { | ||
var c = iban.charCodeAt(n); | ||
if (c >= 65) { | ||
validationString += (c - 55).toString(); | ||
} | ||
else { | ||
validationString += iban[n]; | ||
} | ||
} | ||
return mod9710(validationString); | ||
return mod9710(replaceCharaterWithCode(iban.slice(3) + iban.slice(0, 4))); | ||
} | ||
@@ -327,6 +334,6 @@ /** | ||
countyMap[countyCode] = { | ||
chars: county.chars ? county.chars : null, | ||
bban_regexp: county.bban_regexp ? county.bban_regexp : null, | ||
IBANRegistry: county.IBANRegistry ? county.IBANRegistry : false, | ||
SEPA: county.SEPA ? county.SEPA : false, | ||
chars: county.chars || null, | ||
bban_regexp: county.bban_regexp || null, | ||
IBANRegistry: county.IBANRegistry || false, | ||
SEPA: county.SEPA || false, | ||
}; | ||
@@ -458,8 +465,13 @@ } | ||
while (validationString.length > 2) { | ||
// > Any computer programming language or software package that is used to compute D | ||
// > mod 97 directly must have the ability to handle integers of more than 30 digits. | ||
// > In practice, this can only be done by software that either supports | ||
// > arbitrary-precision arithmetic or that can handle 219-bit (unsigned) integers | ||
// https://en.wikipedia.org/wiki/International_Bank_Account_Number#Modulo_operation_on_IBAN | ||
var part = validationString.slice(0, 6); | ||
var value = parseInt(part, 10) % 97; | ||
if (isNaN(value)) { | ||
var partInt = parseInt(part, 10); | ||
if (isNaN(partInt)) { | ||
return NaN; | ||
} | ||
validationString = value.toString() + validationString.slice(part.length); | ||
validationString = (partInt % 97) + validationString.slice(part.length); | ||
} | ||
@@ -1211,3 +1223,9 @@ return parseInt(validationString, 10) % 97; | ||
}, | ||
NO: { chars: 15, bban_regexp: '^[0-9]{11}$', bban_validation_func: checkNorwayBBAN, IBANRegistry: true, SEPA: true }, | ||
NO: { | ||
chars: 15, | ||
bban_regexp: '^[0-9]{11}$', | ||
bban_validation_func: checkNorwayBBAN, | ||
IBANRegistry: true, | ||
SEPA: true, | ||
}, | ||
NP: {}, | ||
@@ -1214,0 +1232,0 @@ NR: {}, |
{ | ||
"name": "ibantools", | ||
"version": "4.1.4", | ||
"version": "4.1.5", | ||
"description": "Validation, extraction and creation of IBAN, BBAN, BIC/SWIFT numbers plus some other helpful stuff like ISO 3136-1 alpha 2 country list", | ||
@@ -56,3 +56,2 @@ "keywords": [ | ||
"chai": "^4.3.4", | ||
"cheerio": "^0.22", | ||
"coveralls": "^3.1.1", | ||
@@ -64,3 +63,2 @@ "docdash": "^1.2.0", | ||
"gulp": "^4.0.2", | ||
"gulp-mocha": "^8.0", | ||
"gulp-rename": "^2.0", | ||
@@ -67,0 +65,0 @@ "gulp-shell": "^0.8.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25
3082
107260
6