Skip to content

Commit

Permalink
Merge pull request #33 from finfrog/master
Browse files Browse the repository at this point in the history
 fix #32
  • Loading branch information
LaurentVB authored Feb 3, 2017
2 parents 1ac4eac + 05fa0c5 commit 0e195cf
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions iban.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@
return new RegExp('^' + regex.join('') + '$');
}

/**
*
* @param iban
* @returns {string}
*/
function electronicFormat(iban){
return iban.replace(NON_ALPHANUM, '').toUpperCase();
}


/**
* Create a new Specification for a valid IBAN number.
*
Expand Down Expand Up @@ -330,7 +340,7 @@
if (!isString(iban)){
return false;
}
iban = this.electronicFormat(iban);
iban = electronicFormat(iban);
var countryStructure = countries[iban.slice(0,2)];
return !!countryStructure && countryStructure.isValid(iban);
};
Expand All @@ -346,7 +356,7 @@
if (typeof separator == 'undefined'){
separator = ' ';
}
iban = this.electronicFormat(iban);
iban = electronicFormat(iban);
var countryStructure = countries[iban.slice(0,2)];
if (!countryStructure) {
throw new Error('No country with code ' + iban.slice(0,2));
Expand All @@ -368,7 +378,7 @@
if (!countryStructure) {
throw new Error('No country with code ' + countryCode);
}
return countryStructure.fromBBAN(this.electronicFormat(bban));
return countryStructure.fromBBAN(electronicFormat(bban));
};

/**
Expand All @@ -382,7 +392,7 @@
return false;
}
var countryStructure = countries[countryCode];
return countryStructure && countryStructure.isValidBBAN(this.electronicFormat(bban));
return countryStructure && countryStructure.isValidBBAN(electronicFormat(bban));
};

/**
Expand All @@ -395,18 +405,10 @@
if (typeof separator == 'undefined'){
separator = ' ';
}
return this.electronicFormat(iban).replace(EVERY_FOUR_CHARS, "$1" + separator);
};

/**
*
* @param iban
* @returns {string}
*/
exports.electronicFormat = function(iban){
return iban.replace(NON_ALPHANUM, '').toUpperCase();
return electronicFormat(iban).replace(EVERY_FOUR_CHARS, "$1" + separator);
};

exports.electronicFormat = electronicFormat;
/**
* An object containing all the known IBAN specifications.
*/
Expand Down

0 comments on commit 0e195cf

Please sign in to comment.