diff --git a/iban.js b/iban.js index ab4690a..7e6a063 100644 --- a/iban.js +++ b/iban.js @@ -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. * @@ -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); }; @@ -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)); @@ -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)); }; /** @@ -382,7 +392,7 @@ return false; } var countryStructure = countries[countryCode]; - return countryStructure && countryStructure.isValidBBAN(this.electronicFormat(bban)); + return countryStructure && countryStructure.isValidBBAN(electronicFormat(bban)); }; /** @@ -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. */