Comparing version 1.0.1 to 1.0.2
@@ -0,1 +1,6 @@ | ||
/*! | ||
* @license | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
/** | ||
@@ -2,0 +7,0 @@ * Interface for IBAN Country Specification |
@@ -14,2 +14,276 @@ /*! | ||
*/ | ||
"use strict";!function(e,a){if("object"==typeof module&&"object"==typeof module.exports){var n=a(require,exports);void 0!==n&&(module.exports=n)}else"function"==typeof define&&define.amd&&define(e,a)}(["require","exports"],function(e,a){function n(e){if(void 0!==e&&null!==e){var a=i(e),n=o[a.slice(0,2)];if(void 0!==n&&n.chars===a.length&&s(a.slice(4),n.bban_regexp)&&1===p(a))return!0}return!1}function r(e,a){if(void 0!==e&&null!==e&&void 0!==a&&null!==a){var n=i(e),r=o[a];if(void 0!==r&&r.chars-4===n.length&&s(n,r.bban_regexp))return!0}return!1}function b(e){var a=i(e.bban),n=o[e.countryCode];if(null!==a&&void 0!==n&&n.chars===a.length+4&&s(a,n.bban_regexp)){var r=p(e.countryCode+"00"+a);return e.countryCode+("0"+(98-r)).slice(-2)+a}return null}function c(e){var a={};if(e=i(e),n(e)){a.bban=e.slice(4),a.countryCode=e.slice(0,2);var r=o[a.countryCode];a.countryName=r.name,a.valid=!0}else a.valid=!1;return a}function s(e,a){var n=new RegExp(a,"");return n.test(e)}function i(e){return void 0===e||null===e?null:e.replace(/[^a-zA-Z0-9]/g,"").toUpperCase()}function t(e,a){return"undefined"==typeof a&&(a=" "),i(e).replace(/(.{4})(?!$)/g,"$1"+a)}function p(e){e=e.slice(3)+e.slice(0,4);for(var a="",n=1;n<e.length;n++){var r=e.charCodeAt(n);a+=r>=65?(r-55).toString():e[n]}for(;a.length>2;){var b=a.slice(0,6);a=(parseInt(b,10)%97).toString()+a.slice(b.length)}return parseInt(a,10)%97}function g(){return o}var o={};a.isValidIBAN=n,a.isValidBBAN=r,a.composeIBAN=b,a.extractIBAN=c,a.electonicFormatIBAN=i,a.friendlyFormatIBAN=t,a.getCountrySpecifications=g,o.AL={chars:28,bban_regexp:"^[0-9]{8}[A-Z0-9]{16}$",name:"Albania"},o.AD={chars:24,bban_regexp:"^[0-9]{8}[A-Z0-9]{12}$",name:"Andorra"},o.AT={chars:20,bban_regexp:"^[0-9]{16}$",name:"Austria"},o.AZ={chars:28,bban_regexp:"^[A-Z0-9]{4}[0-9]{20}$",name:"Azerbaijan"},o.BH={chars:22,bban_regexp:"^[A-Z]{4}[A-Z0-9]{14}$",name:"Bahrain"},o.BE={chars:16,bban_regexp:"^[0-9]{12}$",name:"Belgium"},o.BA={chars:20,bban_regexp:"^[0-9]{16}$",name:"Bosnia and Herzegovina"},o.BR={chars:29,bban_regexp:"^[0-9]{23}[A-Z]{1}[A-Z0-9]{1}$",name:"Brazil"},o.BG={chars:22,bban_regexp:"^[A-Z]{4}[0-9]{6}[A-Z0-9]{8}$",name:"Bulgaria"},o.CR={chars:21,bban_regexp:"^[0-9]{17}$",name:"Costa Rica"},o.HR={chars:21,bban_regexp:"^[0-9]{17}$",name:"Croatia"},o.CY={chars:28,bban_regexp:"^[0-9]{8}[A-Z0-9]{16}$",name:"Cyprus"},o.CZ={chars:24,bban_regexp:"^[0-9]{20}$",name:"Czech Republic"},o.DK={chars:18,bban_regexp:"^[0-9]{14}$",name:"Denmark"},o.DO={chars:28,bban_regexp:"^[A-Z]{4}[0-9]{20}$",name:"Dominican Republic"},o.TL={chars:23,bban_regexp:"^[0-9]{19}$",name:"East Timor"},o.EE={chars:20,bban_regexp:"^[0-9]{16}$",name:"Estonia"},o.FO={chars:18,bban_regexp:"^[0-9]{14}$",name:"Faroe Islands"},o.FI={chars:18,bban_regexp:"^[0-9]{14}$",name:"Finland"},o.FR={chars:27,bban_regexp:"^[0-9]{10}[A-Z0-9]{11}[0-9]{2}$",name:"France"},o.GE={chars:22,bban_regexp:"^[A-Z0-9]{2}[0-9]{16}$",name:"Georgia (country)"},o.DE={chars:22,bban_regexp:"^[0-9]{18}$",name:"Germany"},o.GI={chars:23,bban_regexp:"^[A-Z]{4}[A-Z0-9]{15}$",name:"Gibraltar"},o.GR={chars:27,bban_regexp:"^[0-9]{7}[A-Z0-9]{16}$",name:"Greece"},o.GL={chars:18,bban_regexp:"^[0-9]{14}$",name:"Greenland"},o.GT={chars:28,bban_regexp:"^[A-Z0-9]{4}[A-Z0-9]{20}$",name:"Guatemala"},o.HU={chars:28,bban_regexp:"^[0-9]{24}$",name:"Hungary"},o.IS={chars:26,bban_regexp:"^[0-9]{22}$",name:"Iceland"},o.IE={chars:22,bban_regexp:"^[A-Z0-9]{4}[0-9]{14}$",name:"Republic of Ireland"},o.IL={chars:23,bban_regexp:"^[0-9]{19}$",name:"Israel"},o.IT={chars:27,bban_regexp:"^[A-Z]{1}[0-9]{10}[A-Z0-9]{12}$",name:"Italy"},o.JO={chars:30,bban_regexp:"^[A-Z]{4}[0-9]{22}$",name:"Jordan"},o.KZ={chars:20,bban_regexp:"^[0-9]{3}[A-Z0-9]{13}$",name:"Kazakhstan"},o.XK={chars:20,bban_regexp:"^[0-9]{4}[0-9]{10}[0-9]{2}$",name:"Kosovo"},o.KW={chars:30,bban_regexp:"^[A-Z]{4}[A-Z0-9]{22}$",name:"Kuwait"},o.LV={chars:21,bban_regexp:"^[A-Z]{4}[A-Z0-9]{13}$",name:"Latvia"},o.LB={chars:28,bban_regexp:"^[0-9]{4}[A-Z0-9]{20}$",name:"Lebanon"},o.LI={chars:21,bban_regexp:"^[0-9]{5}[A-Z0-9]{12}$",name:"Liechtenstein"},o.LT={chars:20,bban_regexp:"^[0-9]{16}$",name:"Lithuania"},o.LU={chars:20,bban_regexp:"^[0-9]{3}[A-Z0-9]{13}$",name:"Luxembourg"},o.MK={chars:19,bban_regexp:"^[0-9]{3}[A-Z0-9]{10}[0-9]{2}$",name:"Republic of Macedonia"},o.MT={chars:31,bban_regexp:"^[A-Z]{4}[0-9]{5}[A-Z0-9]{18}$",name:"Malta"},o.MR={chars:27,bban_regexp:"^[0-9]{23}$",name:"Mauritania"},o.MU={chars:30,bban_regexp:"^[A-Z]{4}[0-9]{19}[A-Z]{3}$",name:"Mauritius"},o.MC={chars:27,bban_regexp:"^[0-9]{10}[A-Z0-9]{11}[0-9]{2}$",name:"Monaco"},o.MD={chars:24,bban_regexp:"^[A-Z0-9]{2}[A-Z0-9]{18}$",name:"Moldova"},o.ME={chars:22,bban_regexp:"^[0-9]{18}$",name:"Montenegro"},o.NL={chars:18,bban_regexp:"^[A-Z]{4}[0-9]{10}$",name:"Netherlands"},o.NO={chars:15,bban_regexp:"^[0-9]{11}$",name:"Norway"},o.PK={chars:24,bban_regexp:"^[A-Z0-9]{4}[0-9]{16}$",name:"Pakistan"},o.PS={chars:29,bban_regexp:"^[A-Z0-9]{4}[0-9]{21}$",name:"Palestinian territories"},o.PL={chars:28,bban_regexp:"^[0-9]{24}$",name:"Poland"},o.PT={chars:25,bban_regexp:"^[0-9]{21}$",name:"Portugal"},o.QA={chars:29,bban_regexp:"^[A-Z]{4}[A-Z0-9]{21}$",name:"Qatar"},o.RO={chars:24,bban_regexp:"^[A-Z]{4}[A-Z0-9]{16}$",name:"Romania"},o.SM={chars:27,bban_regexp:"^[A-Z]{1}[0-9]{10}[A-Z0-9]{12}$",name:"San Marino"},o.SA={chars:24,bban_regexp:"^[0-9]{2}[A-Z0-9]{18}$",name:"Saudi Arabia"},o.RS={chars:22,bban_regexp:"^[0-9]{18}$",name:"Serbia"},o.SK={chars:24,bban_regexp:"^[0-9]{20}$",name:"Slovakia"},o.SI={chars:19,bban_regexp:"^[0-9]{15}$",name:"Slovenia"},o.ES={chars:24,bban_regexp:"^[0-9]{20}$",name:"Spain"},o.SE={chars:24,bban_regexp:"^[0-9]{20}$",name:"Sweden"},o.CH={chars:21,bban_regexp:"^[0-9]{5}[A-Z0-9]{12}$",name:"Switzerland"},o.TN={chars:24,bban_regexp:"^[0-9]{20}$",name:"Tunisia"},o.TR={chars:26,bban_regexp:"^[0-9]{5}[A-Z0-9]{17}$",name:"Turkey"},o.AE={chars:23,bban_regexp:"^[0-9]{3}[0-9]{16}$",name:"United Arab Emirates"},o.GB={chars:22,bban_regexp:"^[A-Z]{4}[0-9]{14}$",name:"United Kingdom"},o.VG={chars:24,bban_regexp:"^[A-Z0-9]{4}[0-9]{16}$",name:"British Virgin Islands"}}); | ||
"use strict"; | ||
// Country specifications | ||
var countrySpecs = {}; | ||
/** | ||
* Validate IBAN | ||
* @example | ||
* // returns true | ||
* ibantools.isValidIBAN('NL91 ABNA 0517 1643 00'); | ||
* @example | ||
* // returns true | ||
* ibantools.isValidIBAN('NL91-ABNA-0517-1643-00'); | ||
* @example | ||
* // returns false | ||
* ibantools.isValidIBAN('NL92 ABNA 0517 1643 00'); | ||
* @alias module:ibantools.isValidIBAN | ||
* @param {string} IBAN IBAN | ||
* @return {boolean} valid | ||
*/ | ||
function isValidIBAN(iban) { | ||
if (iban !== undefined && iban !== null) { | ||
var tmpIban = electonicFormatIBAN(iban); | ||
var spec = countrySpecs[tmpIban.slice(0, 2)]; | ||
if (spec !== undefined && | ||
spec.chars === tmpIban.length && | ||
checkFormatBBAN(tmpIban.slice(4), spec.bban_regexp) && | ||
mod9710(tmpIban) === 1) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
exports.isValidIBAN = isValidIBAN; | ||
/** | ||
* Validate BBAN | ||
* @example | ||
* // returns true | ||
* ibantools.isValidBBAN('ABNA 0517 1643 00', 'NL'); | ||
* @example | ||
* // returns true | ||
* ibantools.isValidBBAN('ABNA0517164300', 'NL'); | ||
* @example | ||
* // returns false | ||
* ibantools.isValidBBAN('A7NA 0517 1643 00', 'NL'); | ||
* @alias module:ibantools.isValidBBAN | ||
* @param {string} BBAN BBAN | ||
* @param {string} countryCode Country code | ||
* @return {boolean} valid | ||
*/ | ||
function isValidBBAN(bban, countryCode) { | ||
if (bban !== undefined && bban !== null && | ||
countryCode !== undefined && countryCode !== null) { | ||
var tmpBban = electonicFormatIBAN(bban); | ||
var spec = countrySpecs[countryCode]; | ||
if (spec !== undefined && | ||
spec.chars - 4 === tmpBban.length && | ||
checkFormatBBAN(tmpBban, spec.bban_regexp)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
exports.isValidBBAN = isValidBBAN; | ||
/** | ||
* composeIBAN | ||
* @example | ||
* // returns NL91ABNA0417164300 | ||
* ibantools.composeIBAN('NL', 'ABNA0417164300'); | ||
* @alias module:ibantools.composeIBAN | ||
* @param {ComposeIBANParams} Object {bban: string, countryCode: string} | ||
* @result {string} IBAN IBAN | ||
*/ | ||
function composeIBAN(params) { | ||
var bban = electonicFormatIBAN(params.bban); | ||
var spec = countrySpecs[params.countryCode]; | ||
if (bban !== null && | ||
spec !== undefined && | ||
spec.chars === (bban.length + 4) && | ||
checkFormatBBAN(bban, spec.bban_regexp)) { | ||
var checksom = mod9710(params.countryCode + '00' + bban); | ||
return params.countryCode + ('0' + (98 - checksom)).slice(-2) + bban; | ||
} | ||
return null; | ||
} | ||
exports.composeIBAN = composeIBAN; | ||
/** | ||
* extractIBAN | ||
* @example | ||
* // returns {bban: 'ABNA0417164300', countryCode: 'NL', countryName: 'Netherlands', valid: true} | ||
* ibantools.extractIBAN('NL91ABNA0417164300'); | ||
* @alias module:ibantools.extractIBAN | ||
* @param {string} IBAN IBAN | ||
* @result {ExtractIBANResult} Object {bban: string, countryCode: string, countryName: string, valid: boolean} | ||
*/ | ||
function extractIBAN(iban) { | ||
var result = {}; | ||
iban = electonicFormatIBAN(iban); | ||
if (isValidIBAN(iban)) { | ||
result.bban = iban.slice(4); | ||
result.countryCode = iban.slice(0, 2); | ||
var spec = countrySpecs[result.countryCode]; | ||
result.countryName = spec.name; | ||
result.valid = true; | ||
} | ||
else { | ||
result.valid = false; | ||
} | ||
return result; | ||
} | ||
exports.extractIBAN = extractIBAN; | ||
/** | ||
* Check BBAN format | ||
* @param {string} BBAN | ||
* @param {string} Regexp BBAN validation regexp | ||
* @return {boolean} valid | ||
*/ | ||
function checkFormatBBAN(bban, bformat) { | ||
var reg = new RegExp(bformat, ''); | ||
return reg.test(bban); | ||
} | ||
/** | ||
* Get IBAN in electronic format (no spaces) | ||
* IBAN validation is not performed. | ||
* @example | ||
* // returns 'NL91ABNA0417164300' | ||
* ibantools.electronicFormatIBAN('NL91 ABNA 0417 1643 00'); | ||
* @alias module:ibantools.electronicFormatIBAN | ||
* @param {string} IBAN IBAN | ||
* @return {string} IBAN Electronic formated IBAN | ||
*/ | ||
function electonicFormatIBAN(iban) { | ||
if (iban === undefined || iban === null) { | ||
return null; | ||
} | ||
return iban.replace(/[^a-zA-Z0-9]/g, "").toUpperCase(); | ||
} | ||
exports.electonicFormatIBAN = electonicFormatIBAN; | ||
/** | ||
* Get IBAN in friendly format (separated after every 4 characters) | ||
* IBAN validation is not performed. | ||
* @example | ||
* // returns 'NL91 ABNA 0417 1643 00' | ||
* ibantools.electronicFormatIBAN('NL91ABNA0417164300'); | ||
* @example | ||
* // returns 'NL91-ABNA-0417-1643-00' | ||
* ibantools.electronicFormatIBAN('NL91ABNA0417164300','-'); | ||
* @alias module:ibantools.friendlyFormatIBAN | ||
* @param {string} IBAN IBAN | ||
* @param {string} separator Not required. Default separator is space ' ' | ||
* @return {string} IBAN Friendly formated IBAN | ||
*/ | ||
function friendlyFormatIBAN(iban, separator) { | ||
if (typeof separator === 'undefined') { | ||
separator = ' '; | ||
} | ||
return electonicFormatIBAN(iban).replace(/(.{4})(?!$)/g, "$1" + separator); | ||
} | ||
exports.friendlyFormatIBAN = friendlyFormatIBAN; | ||
/** | ||
* MOD-97-10 | ||
* @param {string} | ||
* @return {number} | ||
*/ | ||
function mod9710(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]; | ||
} | ||
} | ||
while (validationString.length > 2) { | ||
var part = validationString.slice(0, 6); | ||
validationString = (parseInt(part, 10) % 97).toString() + validationString.slice(part.length); | ||
} | ||
return parseInt(validationString, 10) % 97; | ||
} | ||
/** | ||
* getCountrySpecifications | ||
* @example | ||
* // Validating IBAN form field after user selects his country | ||
* // <select id="countries"> | ||
* // ... | ||
* // <option value="NL">Netherlands</option> | ||
* // ... | ||
* // </select> | ||
* $('#countries').select(function() { | ||
* // Find country | ||
* let country = ibantools.getCountrySpecifications()[$(this).val()]; | ||
* // Add country code letters to IBAN form field | ||
* $('input#iban').value($(this).val()); | ||
* // Add new value to 'pattern' attribute to #iban input text field | ||
* $('input#iban').attr('pattern', $(this).val() + '[0-9]{2}' + country.bban_regexp.slice(1).replace('$','')); | ||
* }); | ||
* @alias module:ibantools.getCountrySpecifications | ||
* @return {CountryMap} Object [countryCode: string]CountrySpec -> {chars: :number, bban_regexp: string, name: string} | ||
*/ | ||
function getCountrySpecifications() { | ||
return countrySpecs; | ||
} | ||
exports.getCountrySpecifications = getCountrySpecifications; | ||
/** | ||
* Fill map of IBAN country specifications | ||
*/ | ||
countrySpecs['AL'] = { chars: 28, bban_regexp: '^[0-9]{8}[A-Z0-9]{16}$', name: 'Albania' }; | ||
countrySpecs['AD'] = { chars: 24, bban_regexp: '^[0-9]{8}[A-Z0-9]{12}$', name: 'Andorra' }; | ||
countrySpecs['AT'] = { chars: 20, bban_regexp: '^[0-9]{16}$', name: 'Austria' }; | ||
countrySpecs['AZ'] = { chars: 28, bban_regexp: '^[A-Z0-9]{4}[0-9]{20}$', name: 'Azerbaijan' }; | ||
countrySpecs['BH'] = { chars: 22, bban_regexp: '^[A-Z]{4}[A-Z0-9]{14}$', name: 'Bahrain' }; | ||
countrySpecs['BE'] = { chars: 16, bban_regexp: '^[0-9]{12}$', name: 'Belgium' }; | ||
countrySpecs['BA'] = { chars: 20, bban_regexp: '^[0-9]{16}$', name: 'Bosnia and Herzegovina' }; | ||
countrySpecs['BR'] = { chars: 29, bban_regexp: '^[0-9]{23}[A-Z]{1}[A-Z0-9]{1}$', name: 'Brazil' }; | ||
countrySpecs['BG'] = { chars: 22, bban_regexp: '^[A-Z]{4}[0-9]{6}[A-Z0-9]{8}$', name: 'Bulgaria' }; | ||
countrySpecs['CR'] = { chars: 21, bban_regexp: '^[0-9]{17}$', name: 'Costa Rica' }; | ||
countrySpecs['HR'] = { chars: 21, bban_regexp: '^[0-9]{17}$', name: 'Croatia' }; | ||
countrySpecs['CY'] = { chars: 28, bban_regexp: '^[0-9]{8}[A-Z0-9]{16}$', name: 'Cyprus' }; | ||
countrySpecs['CZ'] = { chars: 24, bban_regexp: '^[0-9]{20}$', name: 'Czech Republic' }; | ||
countrySpecs['DK'] = { chars: 18, bban_regexp: '^[0-9]{14}$', name: 'Denmark' }; | ||
countrySpecs['DO'] = { chars: 28, bban_regexp: '^[A-Z]{4}[0-9]{20}$', name: 'Dominican Republic' }; | ||
countrySpecs['TL'] = { chars: 23, bban_regexp: '^[0-9]{19}$', name: 'East Timor' }; | ||
countrySpecs['EE'] = { chars: 20, bban_regexp: '^[0-9]{16}$', name: 'Estonia' }; | ||
countrySpecs['FO'] = { chars: 18, bban_regexp: '^[0-9]{14}$', name: 'Faroe Islands' }; | ||
countrySpecs['FI'] = { chars: 18, bban_regexp: '^[0-9]{14}$', name: 'Finland' }; | ||
countrySpecs['FR'] = { chars: 27, bban_regexp: '^[0-9]{10}[A-Z0-9]{11}[0-9]{2}$', name: 'France' }; | ||
countrySpecs['GE'] = { chars: 22, bban_regexp: '^[A-Z0-9]{2}[0-9]{16}$', name: 'Georgia (country)' }; | ||
countrySpecs['DE'] = { chars: 22, bban_regexp: '^[0-9]{18}$', name: 'Germany' }; | ||
countrySpecs['GI'] = { chars: 23, bban_regexp: '^[A-Z]{4}[A-Z0-9]{15}$', name: 'Gibraltar' }; | ||
countrySpecs['GR'] = { chars: 27, bban_regexp: '^[0-9]{7}[A-Z0-9]{16}$', name: 'Greece' }; | ||
countrySpecs['GL'] = { chars: 18, bban_regexp: '^[0-9]{14}$', name: 'Greenland' }; | ||
countrySpecs['GT'] = { chars: 28, bban_regexp: '^[A-Z0-9]{4}[A-Z0-9]{20}$', name: 'Guatemala' }; | ||
countrySpecs['HU'] = { chars: 28, bban_regexp: '^[0-9]{24}$', name: 'Hungary' }; | ||
countrySpecs['IS'] = { chars: 26, bban_regexp: '^[0-9]{22}$', name: 'Iceland' }; | ||
countrySpecs['IE'] = { chars: 22, bban_regexp: '^[A-Z0-9]{4}[0-9]{14}$', name: 'Republic of Ireland' }; | ||
countrySpecs['IL'] = { chars: 23, bban_regexp: '^[0-9]{19}$', name: 'Israel' }; | ||
countrySpecs['IT'] = { chars: 27, bban_regexp: '^[A-Z]{1}[0-9]{10}[A-Z0-9]{12}$', name: 'Italy' }; | ||
countrySpecs['JO'] = { chars: 30, bban_regexp: '^[A-Z]{4}[0-9]{22}$', name: 'Jordan' }; | ||
countrySpecs['KZ'] = { chars: 20, bban_regexp: '^[0-9]{3}[A-Z0-9]{13}$', name: 'Kazakhstan' }; | ||
countrySpecs['XK'] = { chars: 20, bban_regexp: '^[0-9]{4}[0-9]{10}[0-9]{2}$', name: 'Kosovo' }; | ||
countrySpecs['KW'] = { chars: 30, bban_regexp: '^[A-Z]{4}[A-Z0-9]{22}$', name: 'Kuwait' }; | ||
countrySpecs['LV'] = { chars: 21, bban_regexp: '^[A-Z]{4}[A-Z0-9]{13}$', name: 'Latvia' }; | ||
countrySpecs['LB'] = { chars: 28, bban_regexp: '^[0-9]{4}[A-Z0-9]{20}$', name: 'Lebanon' }; | ||
countrySpecs['LI'] = { chars: 21, bban_regexp: '^[0-9]{5}[A-Z0-9]{12}$', name: 'Liechtenstein' }; | ||
countrySpecs['LT'] = { chars: 20, bban_regexp: '^[0-9]{16}$', name: 'Lithuania' }; | ||
countrySpecs['LU'] = { chars: 20, bban_regexp: '^[0-9]{3}[A-Z0-9]{13}$', name: 'Luxembourg' }; | ||
countrySpecs['MK'] = { chars: 19, bban_regexp: '^[0-9]{3}[A-Z0-9]{10}[0-9]{2}$', name: 'Republic of Macedonia' }; | ||
countrySpecs['MT'] = { chars: 31, bban_regexp: '^[A-Z]{4}[0-9]{5}[A-Z0-9]{18}$', name: 'Malta' }; | ||
countrySpecs['MR'] = { chars: 27, bban_regexp: '^[0-9]{23}$', name: 'Mauritania' }; | ||
countrySpecs['MU'] = { chars: 30, bban_regexp: '^[A-Z]{4}[0-9]{19}[A-Z]{3}$', name: 'Mauritius' }; | ||
countrySpecs['MC'] = { chars: 27, bban_regexp: '^[0-9]{10}[A-Z0-9]{11}[0-9]{2}$', name: 'Monaco' }; | ||
countrySpecs['MD'] = { chars: 24, bban_regexp: '^[A-Z0-9]{2}[A-Z0-9]{18}$', name: 'Moldova' }; | ||
countrySpecs['ME'] = { chars: 22, bban_regexp: '^[0-9]{18}$', name: 'Montenegro' }; | ||
countrySpecs['NL'] = { chars: 18, bban_regexp: '^[A-Z]{4}[0-9]{10}$', name: 'Netherlands' }; | ||
countrySpecs['NO'] = { chars: 15, bban_regexp: '^[0-9]{11}$', name: 'Norway' }; | ||
countrySpecs['PK'] = { chars: 24, bban_regexp: '^[A-Z0-9]{4}[0-9]{16}$', name: 'Pakistan' }; | ||
countrySpecs['PS'] = { chars: 29, bban_regexp: '^[A-Z0-9]{4}[0-9]{21}$', name: 'Palestinian territories' }; | ||
countrySpecs['PL'] = { chars: 28, bban_regexp: '^[0-9]{24}$', name: 'Poland' }; | ||
countrySpecs['PT'] = { chars: 25, bban_regexp: '^[0-9]{21}$', name: 'Portugal' }; | ||
countrySpecs['QA'] = { chars: 29, bban_regexp: '^[A-Z]{4}[A-Z0-9]{21}$', name: 'Qatar' }; | ||
countrySpecs['RO'] = { chars: 24, bban_regexp: '^[A-Z]{4}[A-Z0-9]{16}$', name: 'Romania' }; | ||
countrySpecs['SM'] = { chars: 27, bban_regexp: '^[A-Z]{1}[0-9]{10}[A-Z0-9]{12}$', name: 'San Marino' }; | ||
countrySpecs['SA'] = { chars: 24, bban_regexp: '^[0-9]{2}[A-Z0-9]{18}$', name: 'Saudi Arabia' }; | ||
countrySpecs['RS'] = { chars: 22, bban_regexp: '^[0-9]{18}$', name: 'Serbia' }; | ||
countrySpecs['SK'] = { chars: 24, bban_regexp: '^[0-9]{20}$', name: 'Slovakia' }; | ||
countrySpecs['SI'] = { chars: 19, bban_regexp: '^[0-9]{15}$', name: 'Slovenia' }; | ||
countrySpecs['ES'] = { chars: 24, bban_regexp: '^[0-9]{20}$', name: 'Spain' }; | ||
countrySpecs['SE'] = { chars: 24, bban_regexp: '^[0-9]{20}$', name: 'Sweden' }; | ||
countrySpecs['CH'] = { chars: 21, bban_regexp: '^[0-9]{5}[A-Z0-9]{12}$', name: 'Switzerland' }; | ||
countrySpecs['TN'] = { chars: 24, bban_regexp: '^[0-9]{20}$', name: 'Tunisia' }; | ||
countrySpecs['TR'] = { chars: 26, bban_regexp: '^[0-9]{5}[A-Z0-9]{17}$', name: 'Turkey' }; | ||
countrySpecs['AE'] = { chars: 23, bban_regexp: '^[0-9]{3}[0-9]{16}$', name: 'United Arab Emirates' }; | ||
countrySpecs['GB'] = { chars: 22, bban_regexp: '^[A-Z]{4}[0-9]{14}$', name: 'United Kingdom' }; | ||
countrySpecs['VG'] = { chars: 24, bban_regexp: '^[A-Z0-9]{4}[0-9]{16}$', name: 'British Virgin Islands' }; |
{ | ||
"name": "ibantools", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Validation of IBAN numbers and generation of IBAN's plus some other helpful stuff", | ||
@@ -12,4 +12,8 @@ "keywords": [ | ||
"main": "build/ibantools.js", | ||
"jsnext:main": "es6/ibantools.js", | ||
"files": [ | ||
"build" | ||
"build", | ||
"es6", | ||
"LICENSE", | ||
"typings.json" | ||
], | ||
@@ -28,5 +32,7 @@ "directories": { | ||
"scripts": { | ||
"build": "rm -rf dist && rm -rf es6 && rm -rf build && gulp all", | ||
"test": "gulp test-it", | ||
"getcc": "node scripts/getcc.js", | ||
"coverage": "gulp coverage" | ||
"coverage": "gulp coverage", | ||
"prepublish": "typings install && npm run build" | ||
}, | ||
@@ -39,24 +45,23 @@ "author": { | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"cheerio": "^0.19.0", | ||
"gulp": "^3.9.0", | ||
"gulp-mocha": "^2.2.0", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-shell": "^0.5.1", | ||
"gulp-typescript": "^2.9.2", | ||
"gulp-uglify": "^1.5.1", | ||
"istanbul": "^0.4.1", | ||
"jasmine-core": "^2.4.0", | ||
"jsdoc": "^3.4.0", | ||
"karma": "^0.13.15", | ||
"karma-chrome-launcher": "^0.2.2", | ||
"karma-firefox-launcher": "^0.1.7", | ||
"karma-jasmine": "^0.3.6", | ||
"karma-requirejs": "^0.2.2", | ||
"merge2": "^0.3.6", | ||
"mocha": "^2.3.4", | ||
"request": "^2.67.0", | ||
"requirejs": "^2.1.22", | ||
"run-sequence": "^1.1.5" | ||
"chai": "^3.4", | ||
"cheerio": "^0.20", | ||
"gulp": "^3.9", | ||
"gulp-mocha": "^2.2", | ||
"gulp-rename": "^1.2", | ||
"gulp-shell": "^0.5", | ||
"gulp-typescript": "^2.9", | ||
"istanbul": "^0.4", | ||
"jasmine-core": "^2.4", | ||
"jsdoc": "^3.4", | ||
"karma": "^0.13", | ||
"karma-chrome-launcher": "^0.2", | ||
"karma-jasmine": "^0.3", | ||
"karma-requirejs": "^0.2", | ||
"merge2": "^1.0", | ||
"mocha": "^2.3", | ||
"request": "^2.67", | ||
"requirejs": "^2.1", | ||
"run-sequence": "^1.1", | ||
"typings": "^0.6" | ||
} | ||
} |
# IBANTools | ||
[![License MPL-2.0] (https://img.shields.io/badge/license-MPL%202.0-green.svg?dummy)](https://github.com/Simplify/ibantools/blob/master/LICENSE) | ||
[![License](https://img.shields.io/badge/license-MPL%202.0-green.svg?dummy)](https://github.com/Simplify/ibantools/blob/master/LICENSE) | ||
[![Bower version](https://badge.fury.io/bo/ibantools.svg)](https://badge.fury.io/bo/ibantools) | ||
[![npm version](https://badge.fury.io/js/ibantools.svg)](https://badge.fury.io/js/ibantools) | ||
@@ -9,4 +10,4 @@ [![devDependency Status](https://david-dm.org/simplify/ibantools/dev-status.svg)](https://david-dm.org/simplify/ibantools#info=devDependencies) | ||
[![Build Status](https://travis-ci.org/Simplify/ibantools.svg?branch=master)](https://travis-ci.org/Simplify/ibantools) | ||
IBANTools is JavaScript library for validation, creation and extraction of IBAN's. | ||
@@ -18,3 +19,3 @@ | ||
### Node | ||
### Node (Common JS ES5 and ES6) | ||
@@ -25,3 +26,3 @@ ``` | ||
### Bower | ||
### Bower (AMD ES6) | ||
@@ -34,3 +35,3 @@ ``` | ||
### Node - CommonJS | ||
### Node.js - CommonJS | ||
@@ -42,3 +43,3 @@ ```js | ||
### AMD - RequireJS | ||
### AMD - RequireJS - Browser | ||
@@ -51,6 +52,22 @@ ```js | ||
### Node.js - Common JS in browser | ||
Use browserify or webpack. | ||
### ES6 | ||
Use node module, not bower. | ||
If you are using ES6-aware tools, like a [rollup](https://github.com/rollup/rollup) or [JSPM](http://jspm.io/) that understand 'jsnext:main', those will automatically select ES6 module from the package. | ||
### With TypeScript | ||
If you are using `ibantools` with TypeScript, link definition file from the package: | ||
#### Typings (suggested way) | ||
TODO! | ||
#### TSD (old way) | ||
Link definition file from the package: | ||
``` | ||
@@ -65,3 +82,3 @@ $ tsd link | ||
```ts | ||
/// <reference path="../typings/tsd.d.ts" /> | ||
/// <reference path="../typings/tsd.d.ts" /> | ||
import iban = require("ibantools"); | ||
@@ -71,11 +88,2 @@ console.log(iban.isValidIBAN("NL91 ABNA 0517 1643 00")); | ||
### Note about TypeScript usage | ||
After TypeScript 1.8 release (available now in typescript@next), It will be possible to directly use source `.ts` files from node packages, not only generated JavaScript files. | ||
I'm planing to add original source file to both node and bower package after 1.8 release. | ||
Mode info: | ||
* [Github issue](https://github.com/Microsoft/TypeScript/issues/247) | ||
* [Example](https://github.com/chanon/typescript_module_example) | ||
## API | ||
@@ -87,2 +95,3 @@ | ||
* `npm install` and after `node node_modules/.bin/tsd install` (or better install `tsd` globally and run `tsd install`). | ||
* Write tests for your changes in `test/IBANToolsTest.ts`. | ||
@@ -89,0 +98,0 @@ * Do not write more tests in `karma/ibantoolsSpec.js` unless module have problem with loading using AMD. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
51936
20
7
712
98
1