New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

iban-ts

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iban-ts - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

312

dist/iban-ts.cjs.development.js

@@ -6,14 +6,13 @@ 'use strict';

var A = /*#__PURE__*/'A'.charCodeAt(0);
var Z = /*#__PURE__*/'Z'.charCodeAt(0);
/**
* Create a new Specification for a valid IBAN number.
*
* @param countryCode the code of the country
* @param length the length of the IBAN
* @param structure the structure of the underlying BBAN (for validation and formatting)
* @param example an example valid IBAN
* @constructor
* Represents a specification for validating and manipulating IBANs (International Bank Account Numbers).
*/
var Specification = /*#__PURE__*/function () {
/**
* Creates a new instance of Specification.
* @param countryCode - The country code associated with the IBAN.
* @param length - The total length of the IBAN.
* @param structure - The structure of the underlying BBAN (Basic Bank Account Number).
* @param example - An example of a valid IBAN for this specification.
*/
function Specification(countryCode, length, structure, example) {

@@ -31,11 +30,7 @@ this.countryCode = void 0;

/**
* Check if the passed iban is valid according to this specification.
*
* @param {string} iban the iban to validate
* @returns {boolean} true if valid, false otherwise
* Checks if the given IBAN is valid according to this specification.
* @param iban - The IBAN to validate.
* @returns True if the IBAN is valid, false otherwise.
*/
var _proto = Specification.prototype;
_proto.isValid = function isValid(iban) {

@@ -45,25 +40,20 @@ return this.length === iban.length && this.countryCode === iban.slice(0, 2) && this._regex().test(iban.slice(4)) && this.iso7064Mod97_10(this.iso13616Prepare(iban)) === 1;

/**
* Convert the passed IBAN to a country-specific BBAN.
*
* @param iban the IBAN to convert
* @param separator the separator to use between BBAN blocks
* @returns {string} the BBAN
*/
;
* Converts the given IBAN to a country-specific BBAN.
* @param iban - The IBAN to convert.
* @param separator - The separator to use between BBAN blocks.
* @returns The BBAN or undefined if the conversion fails.
*/;
_proto.toBBAN = function toBBAN(iban, separator) {
var _this$_regex, _this$_regex$exec;
return (_this$_regex = this._regex()) == null ? void 0 : (_this$_regex$exec = _this$_regex.exec(iban.slice(4))) == null ? void 0 : _this$_regex$exec.slice(1).join(separator);
var _this$_regex;
if (separator === void 0) {
separator = ' ';
}
return (_this$_regex = this._regex()) == null || (_this$_regex = _this$_regex.exec(iban.slice(4))) == null ? void 0 : _this$_regex.slice(1).join(separator);
}
/**
* Convert the passed BBAN to an IBAN for this country specification.
* Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
* This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
*
* @param bban the BBAN to convert to IBAN
* @returns {string} the IBAN
*/
;
* Converts the given BBAN to an IBAN according to this country's specification.
* @param bban - The BBAN to convert to IBAN.
* @returns The corresponding IBAN.
* @throws {Error} If the BBAN is invalid.
*/;
_proto.fromBBAN = function fromBBAN(bban) {

@@ -73,17 +63,11 @@ if (!this.isValidBBAN(bban)) {

}
var remainder = this.iso7064Mod97_10(this.iso13616Prepare(this.countryCode + '00' + bban));
var checkDigit = ('0' + (98 - remainder)).slice(-2);
var prepared = this.iso13616Prepare(this.countryCode + '00' + bban);
var checkDigit = ('0' + (98 - this.iso7064Mod97_10(prepared))).slice(-2);
return this.countryCode + checkDigit + bban;
}
/**
* Check of the passed BBAN is valid.
* This function only checks the format of the BBAN (length and matching the letetr/number specs) but does not
* verify the check digit.
*
* @param bban the BBAN to validate
* @returns {boolean} true if the passed bban is a valid BBAN according to this specification, false otherwise
*/
;
* Checks if the given BBAN is valid according to this specification.
* @param bban - The BBAN to validate.
* @returns True if the BBAN is valid, false otherwise.
*/;
_proto.isValidBBAN = function isValidBBAN(bban) {

@@ -93,126 +77,87 @@ return this.length - 4 === bban.length && this._regex().test(bban);

/**
* Lazy-loaded regex (parse the structure and construct the regular expression the first time we need it for validation)
*/
;
* Gets a lazily-loaded regex constructed based on the BBAN structure.
* @returns The regular expression for validating the BBAN.
*/;
_proto._regex = function _regex() {
return this._cachedRegex || (this._cachedRegex = this.parseStructure(this.structure));
if (!this._cachedRegex) {
this._cachedRegex = this.parseStructure(this.structure);
}
return this._cachedRegex;
}
/**
* Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
* numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
*
* @param {string} iban the IBAN
* @returns {string} the prepared IBAN
*/
;
* Prepares an IBAN for mod 97 computation as specified in ISO13616.
* @param iban - The IBAN to prepare.
* @returns The prepared IBAN.
*/;
_proto.iso13616Prepare = function iso13616Prepare(iban) {
iban = iban.toUpperCase();
iban = iban.substr(4) + iban.substr(0, 4);
return iban.split('').map(function (n) {
var code = n.charCodeAt(0);
if (code >= A && code <= Z) {
// A = 10, B = 11, ... Z = 35
return code - A + 10;
} else {
return n;
}
}).join('');
return iban.replace(/[A-Z]/g, function (match) {
return (match.charCodeAt(0) - A + 10).toString();
});
}
/**
* Parse the BBAN structure used to configure each IBAN Specification and returns a matching regular expression.
* A structure is composed of blocks of 3 characters (one letter and 2 digits). Each block represents
* a logical group in the typical representation of the BBAN. For each group, the letter indicates which characters
* are allowed in this group and the following 2-digits number tells the length of the group.
*
* @param {string} structure the structure to parse
* @returns {RegExp}
*/
;
* Parses the BBAN structure and returns a matching regular expression.
* @param structure - The structure to parse.
* @returns A RegExp derived from the BBAN structure.
*/;
_proto.parseStructure = function parseStructure(structure) {
var _structure$match;
// split in blocks of 3 chars
var regex = (_structure$match = structure.match(/(.{3})/g)) == null ? void 0 : _structure$match.map(function (block) {
// parse each structure block (1-char + 2-digits)
var format;
var pattern = block.slice(0, 1);
var repeats = parseInt(block.slice(1), 10);
switch (pattern) {
case 'A':
format = '0-9A-Za-z';
break;
case 'B':
format = '0-9A-Z';
break;
case 'C':
format = 'A-Za-z';
break;
case 'F':
format = '0-9';
break;
case 'L':
format = 'a-z';
break;
case 'U':
format = 'A-Z';
break;
case 'W':
format = '0-9a-z';
break;
var formats = {
A: '0-9A-Za-z',
B: '0-9A-Z',
C: 'A-Za-z',
F: '0-9',
L: 'a-z',
U: 'A-Z',
W: '0-9a-z'
};
var regex = (_structure$match = structure.match(/.{3}/g)) == null ? void 0 : _structure$match.map(function (block) {
var _ref = [block[0], parseInt(block.slice(1), 10)],
pattern = _ref[0],
repeats = _ref[1];
if (!formats[pattern]) {
throw new Error("Invalid pattern: " + pattern);
}
return '([' + format + ']{' + repeats + '})';
});
return new RegExp('^' + (regex == null ? void 0 : regex.join('')) + '$');
return "([" + formats[pattern] + "]{" + repeats + "})";
}).join('');
return new RegExp("^" + regex + "$");
}
/**
* Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
*
* @param iban
* @returns {number}
*/
;
* @param iban - The IBAN to calculate the MOD 97 10 for.
* @returns The MOD 97 10 result.
*/;
_proto.iso7064Mod97_10 = function iso7064Mod97_10(iban) {
var remainder = iban;
var block;
while (remainder.length > 2) {
block = remainder.slice(0, 9);
var block = remainder.slice(0, 9);
remainder = parseInt(block, 10) % 97 + remainder.slice(block.length);
}
return parseInt(remainder, 10) % 97;
};
return Specification;
}();
var NON_ALPHANUM = /[^a-zA-Z0-9]/g;
var EVERY_FOUR_CHARS = /(.{4})(?!$)/g;
/**
* Removes non-alphanumeric characters from the string and converts it to uppercase.
*
* @param iban
* @returns {string}
* @param iban The IBAN string to format.
* @returns The formatted IBAN string.
*/
var electronicFormat = function electronicFormat(iban) {
return iban.replace(NON_ALPHANUM, '').toUpperCase();
};
// Map of country codes to their respective IBAN specifications
var countries = {};
/**
* Adds a new IBAN specification for a country.
*
* @param IBAN The IBAN specification to add.
*/
var addSpecification = function addSpecification(IBAN) {
countries[IBAN.countryCode] = IBAN;
};
addSpecification(new Specification('AD', 24, 'F04F04A12', 'AD1200012030200359100100'));

@@ -294,31 +239,31 @@ addSpecification(new Specification('AE', 23, 'F03F16', 'AE070331234567890123456'));

addSpecification(new Specification('VG', 24, 'U04F16', 'VG96VPVG0000012345678901'));
addSpecification(new Specification('XK', 20, 'F04F10F02', 'XK051212012345678906')); // The following countries are not included in the official IBAN registry but use the IBAN specification
addSpecification(new Specification('XK', 20, 'F04F10F02', 'XK051212012345678906'));
// The following countries are not included in the official IBAN registry but use the IBAN specification
// Angola
addSpecification(new Specification('AO', 25, 'F21', 'AO69123456789012345678901')); // Burkina
addSpecification(new Specification('BF', 27, 'F23', 'BF2312345678901234567890123')); // Burundi
addSpecification(new Specification('BI', 16, 'F12', 'BI41123456789012')); // Benin
addSpecification(new Specification('BJ', 28, 'F24', 'BJ39123456789012345678901234')); // Ivory
addSpecification(new Specification('CI', 28, 'U02F22', 'CI70CI1234567890123456789012')); // Cameron
addSpecification(new Specification('CM', 27, 'F23', 'CM9012345678901234567890123')); // Cape Verde
addSpecification(new Specification('CV', 25, 'F21', 'CV30123456789012345678901')); // Algeria
addSpecification(new Specification('DZ', 24, 'F20', 'DZ8612345678901234567890')); // Iran
addSpecification(new Specification('IR', 26, 'F22', 'IR861234568790123456789012')); // Madagascar
addSpecification(new Specification('MG', 27, 'F23', 'MG1812345678901234567890123')); // Mali
addSpecification(new Specification('ML', 28, 'U01F23', 'ML15A12345678901234567890123')); // Mozambique
addSpecification(new Specification('MZ', 25, 'F21', 'MZ25123456789012345678901')); // Senegal
addSpecification(new Specification('SN', 28, 'U01F23', 'SN52A12345678901234567890123')); // The following are regional and administrative French Republic subdivision IBAN specification (same structure as FR, only country code vary)
addSpecification(new Specification('AO', 25, 'F21', 'AO69123456789012345678901'));
// Burkina
addSpecification(new Specification('BF', 27, 'F23', 'BF2312345678901234567890123'));
// Burundi
addSpecification(new Specification('BI', 16, 'F12', 'BI41123456789012'));
// Benin
addSpecification(new Specification('BJ', 28, 'F24', 'BJ39123456789012345678901234'));
// Ivory
addSpecification(new Specification('CI', 28, 'U02F22', 'CI70CI1234567890123456789012'));
// Cameron
addSpecification(new Specification('CM', 27, 'F23', 'CM9012345678901234567890123'));
// Cape Verde
addSpecification(new Specification('CV', 25, 'F21', 'CV30123456789012345678901'));
// Algeria
addSpecification(new Specification('DZ', 24, 'F20', 'DZ8612345678901234567890'));
// Iran
addSpecification(new Specification('IR', 26, 'F22', 'IR861234568790123456789012'));
// Madagascar
addSpecification(new Specification('MG', 27, 'F23', 'MG1812345678901234567890123'));
// Mali
addSpecification(new Specification('ML', 28, 'U01F23', 'ML15A12345678901234567890123'));
// Mozambique
addSpecification(new Specification('MZ', 25, 'F21', 'MZ25123456789012345678901'));
// Senegal
addSpecification(new Specification('SN', 28, 'U01F23', 'SN52A12345678901234567890123'));
// The following are regional and administrative French Republic subdivision IBAN specification (same structure as FR, only country code vary)
addSpecification(new Specification('GF', 27, 'F05F05A11F02', 'GF121234512345123456789AB13'));

@@ -336,22 +281,17 @@ addSpecification(new Specification('GP', 27, 'F05F05A11F02', 'GP791234512345123456789AB13'));

addSpecification(new Specification('WF', 27, 'F05F05A11F02', 'WF621234512345123456789AB13'));
var NON_ALPHANUM = /[^a-zA-Z0-9]/g;
var EVERY_FOUR_CHARS = /(.{4})(?!$)/g;
/**
* Utility function to check if a variable is a String.
* Type guard for checking if a value is a string.
*
* @param value
* @returns {boolean} true if the passed variable is a String, false otherwise.
* @param value The value to check.
* @returns True if the value is a string, false otherwise.
*/
var isString = function isString(value) {
return typeof value == 'string' || value instanceof String;
return typeof value === 'string' || value instanceof String;
};
/**
* Check if an IBAN is valid.
* Validates an IBAN number.
*
* @param {string} iban the IBAN to validate.
* @returns {boolean} true if the passed IBAN is valid, false otherwise
* @param iban The IBAN to validate.
* @returns True if the IBAN is valid, false otherwise.
*/
var isValid = function isValid(iban) {

@@ -361,3 +301,2 @@ if (!isString(iban)) {

}
iban = electronicFormat(iban);

@@ -374,4 +313,2 @@ var countryStructure = countries[iban.slice(0, 2)];

*/
var toBBAN = function toBBAN(iban, separator) {

@@ -381,10 +318,7 @@ if (separator === void 0) {

}
iban = electronicFormat(iban);
var countryStructure = countries[iban.slice(0, 2)];
if (!countryStructure) {
throw new Error('No country with code ' + iban.slice(0, 2));
}
return countryStructure.toBBAN(iban, separator);

@@ -401,11 +335,7 @@ };

*/
var fromBBAN = function fromBBAN(countryCode, bban) {
var countryStructure = countries[countryCode];
if (!countryStructure) {
throw new Error('No country with code ' + countryCode);
}
return countryStructure.fromBBAN(electronicFormat(bban));

@@ -419,4 +349,2 @@ };

*/
var isValidBBAN = function isValidBBAN(countryCode, bban) {

@@ -426,3 +354,2 @@ if (!isString(bban)) {

}
var countryStructure = countries[countryCode];

@@ -437,4 +364,2 @@ return countryStructure == null ? void 0 : countryStructure.isValidBBAN(electronicFormat(bban));

*/
var printFormat = function printFormat(iban, separator) {

@@ -444,3 +369,2 @@ if (separator === void 0) {

}
return electronicFormat(iban).replace(EVERY_FOUR_CHARS, '$1' + separator);

@@ -447,0 +371,0 @@ };

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="A".charCodeAt(0),F="Z".charCodeAt(0),n=function(){function n(e,F,n,t){this.countryCode=void 0,this.length=void 0,this.structure=void 0,this.example=void 0,this._cachedRegex=null,this.countryCode=e,this.length=F,this.structure=n,this.example=t}var t=n.prototype;return t.isValid=function(e){return this.length===e.length&&this.countryCode===e.slice(0,2)&&this._regex().test(e.slice(4))&&1===this.iso7064Mod97_10(this.iso13616Prepare(e))},t.toBBAN=function(e,F){var n,t;return null==(n=this._regex())||null==(t=n.exec(e.slice(4)))?void 0:t.slice(1).join(F)},t.fromBBAN=function(e){if(!this.isValidBBAN(e))throw new Error("Invalid BBAN");var F=("0"+(98-this.iso7064Mod97_10(this.iso13616Prepare(this.countryCode+"00"+e)))).slice(-2);return this.countryCode+F+e},t.isValidBBAN=function(e){return this.length-4===e.length&&this._regex().test(e)},t._regex=function(){return this._cachedRegex||(this._cachedRegex=this.parseStructure(this.structure))},t.iso13616Prepare=function(n){return(n=(n=n.toUpperCase()).substr(4)+n.substr(0,4)).split("").map((function(n){var t=n.charCodeAt(0);return t>=e&&t<=F?t-e+10:n})).join("")},t.parseStructure=function(e){var F,n=null==(F=e.match(/(.{3})/g))?void 0:F.map((function(e){var F,n=e.slice(0,1),t=parseInt(e.slice(1),10);switch(n){case"A":F="0-9A-Za-z";break;case"B":F="0-9A-Z";break;case"C":F="A-Za-z";break;case"F":F="0-9";break;case"L":F="a-z";break;case"U":F="A-Z";break;case"W":F="0-9a-z"}return"(["+F+"]{"+t+"})"}));return new RegExp("^"+(null==n?void 0:n.join(""))+"$")},t.iso7064Mod97_10=function(e){for(var F,n=e;n.length>2;)F=n.slice(0,9),n=parseInt(F,10)%97+n.slice(F.length);return parseInt(n,10)%97},n}(),t=function(e){return e.replace(w,"").toUpperCase()},r={},A=function(e){r[e.countryCode]=e};A(new n("AD",24,"F04F04A12","AD1200012030200359100100")),A(new n("AE",23,"F03F16","AE070331234567890123456")),A(new n("AL",28,"F08A16","AL47212110090000000235698741")),A(new n("AT",20,"F05F11","AT611904300234573201")),A(new n("AZ",28,"U04A20","AZ21NABZ00000000137010001944")),A(new n("BA",20,"F03F03F08F02","BA391290079401028494")),A(new n("BE",16,"F03F07F02","BE68539007547034")),A(new n("BG",22,"U04F04F02A08","BG80BNBG96611020345678")),A(new n("BH",22,"U04A14","BH67BMAG00001299123456")),A(new n("BR",29,"F08F05F10U01A01","BR9700360305000010009795493P1")),A(new n("BY",28,"A04F04A16","BY13NBRB3600900000002Z00AB00")),A(new n("CH",21,"F05A12","CH9300762011623852957")),A(new n("CR",22,"F04F14","CR72012300000171549015")),A(new n("CY",28,"F03F05A16","CY17002001280000001200527600")),A(new n("CZ",24,"F04F06F10","CZ6508000000192000145399")),A(new n("DE",22,"F08F10","DE89370400440532013000")),A(new n("DK",18,"F04F09F01","DK5000400440116243")),A(new n("DO",28,"U04F20","DO28BAGR00000001212453611324")),A(new n("EE",20,"F02F02F11F01","EE382200221020145685")),A(new n("EG",29,"F04F04F17","EG800002000156789012345180002")),A(new n("ES",24,"F04F04F01F01F10","ES9121000418450200051332")),A(new n("FI",18,"F06F07F01","FI2112345600000785")),A(new n("FO",18,"F04F09F01","FO6264600001631634")),A(new n("FR",27,"F05F05A11F02","FR1420041010050500013M02606")),A(new n("GB",22,"U04F06F08","GB29NWBK60161331926819")),A(new n("GE",22,"U02F16","GE29NB0000000101904917")),A(new n("GI",23,"U04A15","GI75NWBK000000007099453")),A(new n("GL",18,"F04F09F01","GL8964710001000206")),A(new n("GR",27,"F03F04A16","GR1601101250000000012300695")),A(new n("GT",28,"A04A20","GT82TRAJ01020000001210029690")),A(new n("HR",21,"F07F10","HR1210010051863000160")),A(new n("HU",28,"F03F04F01F15F01","HU42117730161111101800000000")),A(new n("IE",22,"U04F06F08","IE29AIBK93115212345678")),A(new n("IL",23,"F03F03F13","IL620108000000099999999")),A(new n("IS",26,"F04F02F06F10","IS140159260076545510730339")),A(new n("IT",27,"U01F05F05A12","IT60X0542811101000000123456")),A(new n("IQ",23,"U04F03A12","IQ98NBIQ850123456789012")),A(new n("JO",30,"A04F22","JO15AAAA1234567890123456789012")),A(new n("KW",30,"U04A22","KW81CBKU0000000000001234560101")),A(new n("KZ",20,"F03A13","KZ86125KZT5004100100")),A(new n("LB",28,"F04A20","LB62099900000001001901229114")),A(new n("LC",32,"U04F24","LC07HEMM000100010012001200013015")),A(new n("LI",21,"F05A12","LI21088100002324013AA")),A(new n("LT",20,"F05F11","LT121000011101001000")),A(new n("LU",20,"F03A13","LU280019400644750000")),A(new n("LV",21,"U04A13","LV80BANK0000435195001")),A(new n("MC",27,"F05F05A11F02","MC5811222000010123456789030")),A(new n("MD",24,"U02A18","MD24AG000225100013104168")),A(new n("ME",22,"F03F13F02","ME25505000012345678951")),A(new n("MK",19,"F03A10F02","MK07250120000058984")),A(new n("MR",27,"F05F05F11F02","MR1300020001010000123456753")),A(new n("MT",31,"U04F05A18","MT84MALT011000012345MTLCAST001S")),A(new n("MU",30,"U04F02F02F12F03U03","MU17BOMM0101101030300200000MUR")),A(new n("NL",18,"U04F10","NL91ABNA0417164300")),A(new n("NO",15,"F04F06F01","NO9386011117947")),A(new n("PK",24,"U04A16","PK36SCBL0000001123456702")),A(new n("PL",28,"F08F16","PL61109010140000071219812874")),A(new n("PS",29,"U04A21","PS92PALS000000000400123456702")),A(new n("PT",25,"F04F04F11F02","PT50000201231234567890154")),A(new n("QA",29,"U04A21","QA30AAAA123456789012345678901")),A(new n("RO",24,"U04A16","RO49AAAA1B31007593840000")),A(new n("RS",22,"F03F13F02","RS35260005601001611379")),A(new n("SA",24,"F02A18","SA0380000000608010167519")),A(new n("SC",31,"U04F04F16U03","SC18SSCB11010000000000001497USD")),A(new n("SE",24,"F03F16F01","SE4550000000058398257466")),A(new n("SI",19,"F05F08F02","SI56263300012039086")),A(new n("SK",24,"F04F06F10","SK3112000000198742637541")),A(new n("SM",27,"U01F05F05A12","SM86U0322509800000000270100")),A(new n("ST",25,"F08F11F02","ST68000100010051845310112")),A(new n("SV",28,"U04F20","SV62CENR00000000000000700025")),A(new n("TL",23,"F03F14F02","TL380080012345678910157")),A(new n("TN",24,"F02F03F13F02","TN5910006035183598478831")),A(new n("TR",26,"F05F01A16","TR330006100519786457841326")),A(new n("UA",29,"F25","UA511234567890123456789012345")),A(new n("VA",22,"F18","VA59001123000012345678")),A(new n("VG",24,"U04F16","VG96VPVG0000012345678901")),A(new n("XK",20,"F04F10F02","XK051212012345678906")),A(new n("AO",25,"F21","AO69123456789012345678901")),A(new n("BF",27,"F23","BF2312345678901234567890123")),A(new n("BI",16,"F12","BI41123456789012")),A(new n("BJ",28,"F24","BJ39123456789012345678901234")),A(new n("CI",28,"U02F22","CI70CI1234567890123456789012")),A(new n("CM",27,"F23","CM9012345678901234567890123")),A(new n("CV",25,"F21","CV30123456789012345678901")),A(new n("DZ",24,"F20","DZ8612345678901234567890")),A(new n("IR",26,"F22","IR861234568790123456789012")),A(new n("MG",27,"F23","MG1812345678901234567890123")),A(new n("ML",28,"U01F23","ML15A12345678901234567890123")),A(new n("MZ",25,"F21","MZ25123456789012345678901")),A(new n("SN",28,"U01F23","SN52A12345678901234567890123")),A(new n("GF",27,"F05F05A11F02","GF121234512345123456789AB13")),A(new n("GP",27,"F05F05A11F02","GP791234512345123456789AB13")),A(new n("MQ",27,"F05F05A11F02","MQ221234512345123456789AB13")),A(new n("RE",27,"F05F05A11F02","RE131234512345123456789AB13")),A(new n("PF",27,"F05F05A11F02","PF281234512345123456789AB13")),A(new n("TF",27,"F05F05A11F02","TF891234512345123456789AB13")),A(new n("YT",27,"F05F05A11F02","YT021234512345123456789AB13")),A(new n("NC",27,"F05F05A11F02","NC551234512345123456789AB13")),A(new n("BL",27,"F05F05A11F02","BL391234512345123456789AB13")),A(new n("MF",27,"F05F05A11F02","MF551234512345123456789AB13")),A(new n("PM",27,"F05F05A11F02","PM071234512345123456789AB13")),A(new n("WF",27,"F05F05A11F02","WF621234512345123456789AB13"));var w=/[^a-zA-Z0-9]/g,i=/(.{4})(?!$)/g,o=function(e){return"string"==typeof e||e instanceof String};exports.countries=r,exports.electronicFormat=t,exports.fromBBAN=function(e,F){var n=r[e];if(!n)throw new Error("No country with code "+e);return n.fromBBAN(t(F))},exports.isValid=function(e){if(!o(e))return!1;e=t(e);var F=r[e.slice(0,2)];return!!F&&F.isValid(e)},exports.isValidBBAN=function(e,F){if(!o(F))return!1;var n=r[e];return null==n?void 0:n.isValidBBAN(t(F))},exports.printFormat=function(e,F){return void 0===F&&(F=" "),t(e).replace(i,"$1"+F)},exports.toBBAN=function(e,F){void 0===F&&(F=" "),e=t(e);var n=r[e.slice(0,2)];if(!n)throw new Error("No country with code "+e.slice(0,2));return n.toBBAN(e,F)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="A".charCodeAt(0),F=function(){function F(e,F,n,t){this.countryCode=void 0,this.length=void 0,this.structure=void 0,this.example=void 0,this._cachedRegex=null,this.countryCode=e,this.length=F,this.structure=n,this.example=t}var n=F.prototype;return n.isValid=function(e){return this.length===e.length&&this.countryCode===e.slice(0,2)&&this._regex().test(e.slice(4))&&1===this.iso7064Mod97_10(this.iso13616Prepare(e))},n.toBBAN=function(e,F){var n;return void 0===F&&(F=" "),null==(n=this._regex())||null==(n=n.exec(e.slice(4)))?void 0:n.slice(1).join(F)},n.fromBBAN=function(e){if(!this.isValidBBAN(e))throw new Error("Invalid BBAN");var F=this.iso13616Prepare(this.countryCode+"00"+e),n=("0"+(98-this.iso7064Mod97_10(F))).slice(-2);return this.countryCode+n+e},n.isValidBBAN=function(e){return this.length-4===e.length&&this._regex().test(e)},n._regex=function(){return this._cachedRegex||(this._cachedRegex=this.parseStructure(this.structure)),this._cachedRegex},n.iso13616Prepare=function(F){return(F=(F=F.toUpperCase()).substr(4)+F.substr(0,4)).replace(/[A-Z]/g,(function(F){return(F.charCodeAt(0)-e+10).toString()}))},n.parseStructure=function(e){var F,n={A:"0-9A-Za-z",B:"0-9A-Z",C:"A-Za-z",F:"0-9",L:"a-z",U:"A-Z",W:"0-9a-z"},t=null==(F=e.match(/.{3}/g))?void 0:F.map((function(e){var F=[e[0],parseInt(e.slice(1),10)],t=F[0],r=F[1];if(!n[t])throw new Error("Invalid pattern: "+t);return"(["+n[t]+"]{"+r+"})"})).join("");return new RegExp("^"+t+"$")},n.iso7064Mod97_10=function(e){for(var F=e;F.length>2;){var n=F.slice(0,9);F=parseInt(n,10)%97+F.slice(n.length)}return parseInt(F,10)%97},F}(),n=/[^a-zA-Z0-9]/g,t=/(.{4})(?!$)/g,r=function(e){return e.replace(n,"").toUpperCase()},A={},w=function(e){A[e.countryCode]=e};w(new F("AD",24,"F04F04A12","AD1200012030200359100100")),w(new F("AE",23,"F03F16","AE070331234567890123456")),w(new F("AL",28,"F08A16","AL47212110090000000235698741")),w(new F("AT",20,"F05F11","AT611904300234573201")),w(new F("AZ",28,"U04A20","AZ21NABZ00000000137010001944")),w(new F("BA",20,"F03F03F08F02","BA391290079401028494")),w(new F("BE",16,"F03F07F02","BE68539007547034")),w(new F("BG",22,"U04F04F02A08","BG80BNBG96611020345678")),w(new F("BH",22,"U04A14","BH67BMAG00001299123456")),w(new F("BR",29,"F08F05F10U01A01","BR9700360305000010009795493P1")),w(new F("BY",28,"A04F04A16","BY13NBRB3600900000002Z00AB00")),w(new F("CH",21,"F05A12","CH9300762011623852957")),w(new F("CR",22,"F04F14","CR72012300000171549015")),w(new F("CY",28,"F03F05A16","CY17002001280000001200527600")),w(new F("CZ",24,"F04F06F10","CZ6508000000192000145399")),w(new F("DE",22,"F08F10","DE89370400440532013000")),w(new F("DK",18,"F04F09F01","DK5000400440116243")),w(new F("DO",28,"U04F20","DO28BAGR00000001212453611324")),w(new F("EE",20,"F02F02F11F01","EE382200221020145685")),w(new F("EG",29,"F04F04F17","EG800002000156789012345180002")),w(new F("ES",24,"F04F04F01F01F10","ES9121000418450200051332")),w(new F("FI",18,"F06F07F01","FI2112345600000785")),w(new F("FO",18,"F04F09F01","FO6264600001631634")),w(new F("FR",27,"F05F05A11F02","FR1420041010050500013M02606")),w(new F("GB",22,"U04F06F08","GB29NWBK60161331926819")),w(new F("GE",22,"U02F16","GE29NB0000000101904917")),w(new F("GI",23,"U04A15","GI75NWBK000000007099453")),w(new F("GL",18,"F04F09F01","GL8964710001000206")),w(new F("GR",27,"F03F04A16","GR1601101250000000012300695")),w(new F("GT",28,"A04A20","GT82TRAJ01020000001210029690")),w(new F("HR",21,"F07F10","HR1210010051863000160")),w(new F("HU",28,"F03F04F01F15F01","HU42117730161111101800000000")),w(new F("IE",22,"U04F06F08","IE29AIBK93115212345678")),w(new F("IL",23,"F03F03F13","IL620108000000099999999")),w(new F("IS",26,"F04F02F06F10","IS140159260076545510730339")),w(new F("IT",27,"U01F05F05A12","IT60X0542811101000000123456")),w(new F("IQ",23,"U04F03A12","IQ98NBIQ850123456789012")),w(new F("JO",30,"A04F22","JO15AAAA1234567890123456789012")),w(new F("KW",30,"U04A22","KW81CBKU0000000000001234560101")),w(new F("KZ",20,"F03A13","KZ86125KZT5004100100")),w(new F("LB",28,"F04A20","LB62099900000001001901229114")),w(new F("LC",32,"U04F24","LC07HEMM000100010012001200013015")),w(new F("LI",21,"F05A12","LI21088100002324013AA")),w(new F("LT",20,"F05F11","LT121000011101001000")),w(new F("LU",20,"F03A13","LU280019400644750000")),w(new F("LV",21,"U04A13","LV80BANK0000435195001")),w(new F("MC",27,"F05F05A11F02","MC5811222000010123456789030")),w(new F("MD",24,"U02A18","MD24AG000225100013104168")),w(new F("ME",22,"F03F13F02","ME25505000012345678951")),w(new F("MK",19,"F03A10F02","MK07250120000058984")),w(new F("MR",27,"F05F05F11F02","MR1300020001010000123456753")),w(new F("MT",31,"U04F05A18","MT84MALT011000012345MTLCAST001S")),w(new F("MU",30,"U04F02F02F12F03U03","MU17BOMM0101101030300200000MUR")),w(new F("NL",18,"U04F10","NL91ABNA0417164300")),w(new F("NO",15,"F04F06F01","NO9386011117947")),w(new F("PK",24,"U04A16","PK36SCBL0000001123456702")),w(new F("PL",28,"F08F16","PL61109010140000071219812874")),w(new F("PS",29,"U04A21","PS92PALS000000000400123456702")),w(new F("PT",25,"F04F04F11F02","PT50000201231234567890154")),w(new F("QA",29,"U04A21","QA30AAAA123456789012345678901")),w(new F("RO",24,"U04A16","RO49AAAA1B31007593840000")),w(new F("RS",22,"F03F13F02","RS35260005601001611379")),w(new F("SA",24,"F02A18","SA0380000000608010167519")),w(new F("SC",31,"U04F04F16U03","SC18SSCB11010000000000001497USD")),w(new F("SE",24,"F03F16F01","SE4550000000058398257466")),w(new F("SI",19,"F05F08F02","SI56263300012039086")),w(new F("SK",24,"F04F06F10","SK3112000000198742637541")),w(new F("SM",27,"U01F05F05A12","SM86U0322509800000000270100")),w(new F("ST",25,"F08F11F02","ST68000100010051845310112")),w(new F("SV",28,"U04F20","SV62CENR00000000000000700025")),w(new F("TL",23,"F03F14F02","TL380080012345678910157")),w(new F("TN",24,"F02F03F13F02","TN5910006035183598478831")),w(new F("TR",26,"F05F01A16","TR330006100519786457841326")),w(new F("UA",29,"F25","UA511234567890123456789012345")),w(new F("VA",22,"F18","VA59001123000012345678")),w(new F("VG",24,"U04F16","VG96VPVG0000012345678901")),w(new F("XK",20,"F04F10F02","XK051212012345678906")),w(new F("AO",25,"F21","AO69123456789012345678901")),w(new F("BF",27,"F23","BF2312345678901234567890123")),w(new F("BI",16,"F12","BI41123456789012")),w(new F("BJ",28,"F24","BJ39123456789012345678901234")),w(new F("CI",28,"U02F22","CI70CI1234567890123456789012")),w(new F("CM",27,"F23","CM9012345678901234567890123")),w(new F("CV",25,"F21","CV30123456789012345678901")),w(new F("DZ",24,"F20","DZ8612345678901234567890")),w(new F("IR",26,"F22","IR861234568790123456789012")),w(new F("MG",27,"F23","MG1812345678901234567890123")),w(new F("ML",28,"U01F23","ML15A12345678901234567890123")),w(new F("MZ",25,"F21","MZ25123456789012345678901")),w(new F("SN",28,"U01F23","SN52A12345678901234567890123")),w(new F("GF",27,"F05F05A11F02","GF121234512345123456789AB13")),w(new F("GP",27,"F05F05A11F02","GP791234512345123456789AB13")),w(new F("MQ",27,"F05F05A11F02","MQ221234512345123456789AB13")),w(new F("RE",27,"F05F05A11F02","RE131234512345123456789AB13")),w(new F("PF",27,"F05F05A11F02","PF281234512345123456789AB13")),w(new F("TF",27,"F05F05A11F02","TF891234512345123456789AB13")),w(new F("YT",27,"F05F05A11F02","YT021234512345123456789AB13")),w(new F("NC",27,"F05F05A11F02","NC551234512345123456789AB13")),w(new F("BL",27,"F05F05A11F02","BL391234512345123456789AB13")),w(new F("MF",27,"F05F05A11F02","MF551234512345123456789AB13")),w(new F("PM",27,"F05F05A11F02","PM071234512345123456789AB13")),w(new F("WF",27,"F05F05A11F02","WF621234512345123456789AB13"));var i=function(e){return"string"==typeof e||e instanceof String};exports.countries=A,exports.electronicFormat=r,exports.fromBBAN=function(e,F){var n=A[e];if(!n)throw new Error("No country with code "+e);return n.fromBBAN(r(F))},exports.isValid=function(e){if(!i(e))return!1;e=r(e);var F=A[e.slice(0,2)];return!!F&&F.isValid(e)},exports.isValidBBAN=function(e,F){if(!i(F))return!1;var n=A[e];return null==n?void 0:n.isValidBBAN(r(F))},exports.printFormat=function(e,F){return void 0===F&&(F=" "),r(e).replace(t,"$1"+F)},exports.toBBAN=function(e,F){void 0===F&&(F=" "),e=r(e);var n=A[e.slice(0,2)];if(!n)throw new Error("No country with code "+e.slice(0,2));return n.toBBAN(e,F)};
//# sourceMappingURL=iban-ts.cjs.production.min.js.map
var A = /*#__PURE__*/'A'.charCodeAt(0);
var Z = /*#__PURE__*/'Z'.charCodeAt(0);
/**
* Create a new Specification for a valid IBAN number.
*
* @param countryCode the code of the country
* @param length the length of the IBAN
* @param structure the structure of the underlying BBAN (for validation and formatting)
* @param example an example valid IBAN
* @constructor
* Represents a specification for validating and manipulating IBANs (International Bank Account Numbers).
*/
var Specification = /*#__PURE__*/function () {
/**
* Creates a new instance of Specification.
* @param countryCode - The country code associated with the IBAN.
* @param length - The total length of the IBAN.
* @param structure - The structure of the underlying BBAN (Basic Bank Account Number).
* @param example - An example of a valid IBAN for this specification.
*/
function Specification(countryCode, length, structure, example) {

@@ -26,11 +25,7 @@ this.countryCode = void 0;

/**
* Check if the passed iban is valid according to this specification.
*
* @param {string} iban the iban to validate
* @returns {boolean} true if valid, false otherwise
* Checks if the given IBAN is valid according to this specification.
* @param iban - The IBAN to validate.
* @returns True if the IBAN is valid, false otherwise.
*/
var _proto = Specification.prototype;
_proto.isValid = function isValid(iban) {

@@ -40,25 +35,20 @@ return this.length === iban.length && this.countryCode === iban.slice(0, 2) && this._regex().test(iban.slice(4)) && this.iso7064Mod97_10(this.iso13616Prepare(iban)) === 1;

/**
* Convert the passed IBAN to a country-specific BBAN.
*
* @param iban the IBAN to convert
* @param separator the separator to use between BBAN blocks
* @returns {string} the BBAN
*/
;
* Converts the given IBAN to a country-specific BBAN.
* @param iban - The IBAN to convert.
* @param separator - The separator to use between BBAN blocks.
* @returns The BBAN or undefined if the conversion fails.
*/;
_proto.toBBAN = function toBBAN(iban, separator) {
var _this$_regex, _this$_regex$exec;
return (_this$_regex = this._regex()) == null ? void 0 : (_this$_regex$exec = _this$_regex.exec(iban.slice(4))) == null ? void 0 : _this$_regex$exec.slice(1).join(separator);
var _this$_regex;
if (separator === void 0) {
separator = ' ';
}
return (_this$_regex = this._regex()) == null || (_this$_regex = _this$_regex.exec(iban.slice(4))) == null ? void 0 : _this$_regex.slice(1).join(separator);
}
/**
* Convert the passed BBAN to an IBAN for this country specification.
* Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
* This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
*
* @param bban the BBAN to convert to IBAN
* @returns {string} the IBAN
*/
;
* Converts the given BBAN to an IBAN according to this country's specification.
* @param bban - The BBAN to convert to IBAN.
* @returns The corresponding IBAN.
* @throws {Error} If the BBAN is invalid.
*/;
_proto.fromBBAN = function fromBBAN(bban) {

@@ -68,17 +58,11 @@ if (!this.isValidBBAN(bban)) {

}
var remainder = this.iso7064Mod97_10(this.iso13616Prepare(this.countryCode + '00' + bban));
var checkDigit = ('0' + (98 - remainder)).slice(-2);
var prepared = this.iso13616Prepare(this.countryCode + '00' + bban);
var checkDigit = ('0' + (98 - this.iso7064Mod97_10(prepared))).slice(-2);
return this.countryCode + checkDigit + bban;
}
/**
* Check of the passed BBAN is valid.
* This function only checks the format of the BBAN (length and matching the letetr/number specs) but does not
* verify the check digit.
*
* @param bban the BBAN to validate
* @returns {boolean} true if the passed bban is a valid BBAN according to this specification, false otherwise
*/
;
* Checks if the given BBAN is valid according to this specification.
* @param bban - The BBAN to validate.
* @returns True if the BBAN is valid, false otherwise.
*/;
_proto.isValidBBAN = function isValidBBAN(bban) {

@@ -88,126 +72,87 @@ return this.length - 4 === bban.length && this._regex().test(bban);

/**
* Lazy-loaded regex (parse the structure and construct the regular expression the first time we need it for validation)
*/
;
* Gets a lazily-loaded regex constructed based on the BBAN structure.
* @returns The regular expression for validating the BBAN.
*/;
_proto._regex = function _regex() {
return this._cachedRegex || (this._cachedRegex = this.parseStructure(this.structure));
if (!this._cachedRegex) {
this._cachedRegex = this.parseStructure(this.structure);
}
return this._cachedRegex;
}
/**
* Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
* numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
*
* @param {string} iban the IBAN
* @returns {string} the prepared IBAN
*/
;
* Prepares an IBAN for mod 97 computation as specified in ISO13616.
* @param iban - The IBAN to prepare.
* @returns The prepared IBAN.
*/;
_proto.iso13616Prepare = function iso13616Prepare(iban) {
iban = iban.toUpperCase();
iban = iban.substr(4) + iban.substr(0, 4);
return iban.split('').map(function (n) {
var code = n.charCodeAt(0);
if (code >= A && code <= Z) {
// A = 10, B = 11, ... Z = 35
return code - A + 10;
} else {
return n;
}
}).join('');
return iban.replace(/[A-Z]/g, function (match) {
return (match.charCodeAt(0) - A + 10).toString();
});
}
/**
* Parse the BBAN structure used to configure each IBAN Specification and returns a matching regular expression.
* A structure is composed of blocks of 3 characters (one letter and 2 digits). Each block represents
* a logical group in the typical representation of the BBAN. For each group, the letter indicates which characters
* are allowed in this group and the following 2-digits number tells the length of the group.
*
* @param {string} structure the structure to parse
* @returns {RegExp}
*/
;
* Parses the BBAN structure and returns a matching regular expression.
* @param structure - The structure to parse.
* @returns A RegExp derived from the BBAN structure.
*/;
_proto.parseStructure = function parseStructure(structure) {
var _structure$match;
// split in blocks of 3 chars
var regex = (_structure$match = structure.match(/(.{3})/g)) == null ? void 0 : _structure$match.map(function (block) {
// parse each structure block (1-char + 2-digits)
var format;
var pattern = block.slice(0, 1);
var repeats = parseInt(block.slice(1), 10);
switch (pattern) {
case 'A':
format = '0-9A-Za-z';
break;
case 'B':
format = '0-9A-Z';
break;
case 'C':
format = 'A-Za-z';
break;
case 'F':
format = '0-9';
break;
case 'L':
format = 'a-z';
break;
case 'U':
format = 'A-Z';
break;
case 'W':
format = '0-9a-z';
break;
var formats = {
A: '0-9A-Za-z',
B: '0-9A-Z',
C: 'A-Za-z',
F: '0-9',
L: 'a-z',
U: 'A-Z',
W: '0-9a-z'
};
var regex = (_structure$match = structure.match(/.{3}/g)) == null ? void 0 : _structure$match.map(function (block) {
var _ref = [block[0], parseInt(block.slice(1), 10)],
pattern = _ref[0],
repeats = _ref[1];
if (!formats[pattern]) {
throw new Error("Invalid pattern: " + pattern);
}
return '([' + format + ']{' + repeats + '})';
});
return new RegExp('^' + (regex == null ? void 0 : regex.join('')) + '$');
return "([" + formats[pattern] + "]{" + repeats + "})";
}).join('');
return new RegExp("^" + regex + "$");
}
/**
* Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
*
* @param iban
* @returns {number}
*/
;
* @param iban - The IBAN to calculate the MOD 97 10 for.
* @returns The MOD 97 10 result.
*/;
_proto.iso7064Mod97_10 = function iso7064Mod97_10(iban) {
var remainder = iban;
var block;
while (remainder.length > 2) {
block = remainder.slice(0, 9);
var block = remainder.slice(0, 9);
remainder = parseInt(block, 10) % 97 + remainder.slice(block.length);
}
return parseInt(remainder, 10) % 97;
};
return Specification;
}();
var NON_ALPHANUM = /[^a-zA-Z0-9]/g;
var EVERY_FOUR_CHARS = /(.{4})(?!$)/g;
/**
* Removes non-alphanumeric characters from the string and converts it to uppercase.
*
* @param iban
* @returns {string}
* @param iban The IBAN string to format.
* @returns The formatted IBAN string.
*/
var electronicFormat = function electronicFormat(iban) {
return iban.replace(NON_ALPHANUM, '').toUpperCase();
};
// Map of country codes to their respective IBAN specifications
var countries = {};
/**
* Adds a new IBAN specification for a country.
*
* @param IBAN The IBAN specification to add.
*/
var addSpecification = function addSpecification(IBAN) {
countries[IBAN.countryCode] = IBAN;
};
addSpecification(new Specification('AD', 24, 'F04F04A12', 'AD1200012030200359100100'));

@@ -289,31 +234,31 @@ addSpecification(new Specification('AE', 23, 'F03F16', 'AE070331234567890123456'));

addSpecification(new Specification('VG', 24, 'U04F16', 'VG96VPVG0000012345678901'));
addSpecification(new Specification('XK', 20, 'F04F10F02', 'XK051212012345678906')); // The following countries are not included in the official IBAN registry but use the IBAN specification
addSpecification(new Specification('XK', 20, 'F04F10F02', 'XK051212012345678906'));
// The following countries are not included in the official IBAN registry but use the IBAN specification
// Angola
addSpecification(new Specification('AO', 25, 'F21', 'AO69123456789012345678901')); // Burkina
addSpecification(new Specification('BF', 27, 'F23', 'BF2312345678901234567890123')); // Burundi
addSpecification(new Specification('BI', 16, 'F12', 'BI41123456789012')); // Benin
addSpecification(new Specification('BJ', 28, 'F24', 'BJ39123456789012345678901234')); // Ivory
addSpecification(new Specification('CI', 28, 'U02F22', 'CI70CI1234567890123456789012')); // Cameron
addSpecification(new Specification('CM', 27, 'F23', 'CM9012345678901234567890123')); // Cape Verde
addSpecification(new Specification('CV', 25, 'F21', 'CV30123456789012345678901')); // Algeria
addSpecification(new Specification('DZ', 24, 'F20', 'DZ8612345678901234567890')); // Iran
addSpecification(new Specification('IR', 26, 'F22', 'IR861234568790123456789012')); // Madagascar
addSpecification(new Specification('MG', 27, 'F23', 'MG1812345678901234567890123')); // Mali
addSpecification(new Specification('ML', 28, 'U01F23', 'ML15A12345678901234567890123')); // Mozambique
addSpecification(new Specification('MZ', 25, 'F21', 'MZ25123456789012345678901')); // Senegal
addSpecification(new Specification('SN', 28, 'U01F23', 'SN52A12345678901234567890123')); // The following are regional and administrative French Republic subdivision IBAN specification (same structure as FR, only country code vary)
addSpecification(new Specification('AO', 25, 'F21', 'AO69123456789012345678901'));
// Burkina
addSpecification(new Specification('BF', 27, 'F23', 'BF2312345678901234567890123'));
// Burundi
addSpecification(new Specification('BI', 16, 'F12', 'BI41123456789012'));
// Benin
addSpecification(new Specification('BJ', 28, 'F24', 'BJ39123456789012345678901234'));
// Ivory
addSpecification(new Specification('CI', 28, 'U02F22', 'CI70CI1234567890123456789012'));
// Cameron
addSpecification(new Specification('CM', 27, 'F23', 'CM9012345678901234567890123'));
// Cape Verde
addSpecification(new Specification('CV', 25, 'F21', 'CV30123456789012345678901'));
// Algeria
addSpecification(new Specification('DZ', 24, 'F20', 'DZ8612345678901234567890'));
// Iran
addSpecification(new Specification('IR', 26, 'F22', 'IR861234568790123456789012'));
// Madagascar
addSpecification(new Specification('MG', 27, 'F23', 'MG1812345678901234567890123'));
// Mali
addSpecification(new Specification('ML', 28, 'U01F23', 'ML15A12345678901234567890123'));
// Mozambique
addSpecification(new Specification('MZ', 25, 'F21', 'MZ25123456789012345678901'));
// Senegal
addSpecification(new Specification('SN', 28, 'U01F23', 'SN52A12345678901234567890123'));
// The following are regional and administrative French Republic subdivision IBAN specification (same structure as FR, only country code vary)
addSpecification(new Specification('GF', 27, 'F05F05A11F02', 'GF121234512345123456789AB13'));

@@ -331,22 +276,17 @@ addSpecification(new Specification('GP', 27, 'F05F05A11F02', 'GP791234512345123456789AB13'));

addSpecification(new Specification('WF', 27, 'F05F05A11F02', 'WF621234512345123456789AB13'));
var NON_ALPHANUM = /[^a-zA-Z0-9]/g;
var EVERY_FOUR_CHARS = /(.{4})(?!$)/g;
/**
* Utility function to check if a variable is a String.
* Type guard for checking if a value is a string.
*
* @param value
* @returns {boolean} true if the passed variable is a String, false otherwise.
* @param value The value to check.
* @returns True if the value is a string, false otherwise.
*/
var isString = function isString(value) {
return typeof value == 'string' || value instanceof String;
return typeof value === 'string' || value instanceof String;
};
/**
* Check if an IBAN is valid.
* Validates an IBAN number.
*
* @param {string} iban the IBAN to validate.
* @returns {boolean} true if the passed IBAN is valid, false otherwise
* @param iban The IBAN to validate.
* @returns True if the IBAN is valid, false otherwise.
*/
var isValid = function isValid(iban) {

@@ -356,3 +296,2 @@ if (!isString(iban)) {

}
iban = electronicFormat(iban);

@@ -369,4 +308,2 @@ var countryStructure = countries[iban.slice(0, 2)];

*/
var toBBAN = function toBBAN(iban, separator) {

@@ -376,10 +313,7 @@ if (separator === void 0) {

}
iban = electronicFormat(iban);
var countryStructure = countries[iban.slice(0, 2)];
if (!countryStructure) {
throw new Error('No country with code ' + iban.slice(0, 2));
}
return countryStructure.toBBAN(iban, separator);

@@ -396,11 +330,7 @@ };

*/
var fromBBAN = function fromBBAN(countryCode, bban) {
var countryStructure = countries[countryCode];
if (!countryStructure) {
throw new Error('No country with code ' + countryCode);
}
return countryStructure.fromBBAN(electronicFormat(bban));

@@ -414,4 +344,2 @@ };

*/
var isValidBBAN = function isValidBBAN(countryCode, bban) {

@@ -421,3 +349,2 @@ if (!isString(bban)) {

}
var countryStructure = countries[countryCode];

@@ -432,4 +359,2 @@ return countryStructure == null ? void 0 : countryStructure.isValidBBAN(electronicFormat(bban));

*/
var printFormat = function printFormat(iban, separator) {

@@ -439,3 +364,2 @@ if (separator === void 0) {

}
return electronicFormat(iban).replace(EVERY_FOUR_CHARS, '$1' + separator);

@@ -442,0 +366,0 @@ };

import { Specification } from './Specification';
/**
* Removes non-alphanumeric characters from the string and converts it to uppercase.
*
* @param iban
* @returns {string}
* @param iban The IBAN string to format.
* @returns The formatted IBAN string.
*/

@@ -10,6 +11,6 @@ declare const electronicFormat: (iban: string) => string;

/**
* Check if an IBAN is valid.
* Validates an IBAN number.
*
* @param {string} iban the IBAN to validate.
* @returns {boolean} true if the passed IBAN is valid, false otherwise
* @param iban The IBAN to validate.
* @returns True if the IBAN is valid, false otherwise.
*/

@@ -16,0 +17,0 @@ declare const isValid: (iban: string) => boolean;

/**
* Create a new Specification for a valid IBAN number.
*
* @param countryCode the code of the country
* @param length the length of the IBAN
* @param structure the structure of the underlying BBAN (for validation and formatting)
* @param example an example valid IBAN
* @constructor
* Represents a specification for validating and manipulating IBANs (International Bank Account Numbers).
*/

@@ -16,56 +10,51 @@ export declare class Specification {

private _cachedRegex;
/**
* Creates a new instance of Specification.
* @param countryCode - The country code associated with the IBAN.
* @param length - The total length of the IBAN.
* @param structure - The structure of the underlying BBAN (Basic Bank Account Number).
* @param example - An example of a valid IBAN for this specification.
*/
constructor(countryCode: string, length: number, structure: string, example: string);
/**
* Check if the passed iban is valid according to this specification.
*
* @param {string} iban the iban to validate
* @returns {boolean} true if valid, false otherwise
* Checks if the given IBAN is valid according to this specification.
* @param iban - The IBAN to validate.
* @returns True if the IBAN is valid, false otherwise.
*/
isValid(iban: string): boolean;
/**
* Convert the passed IBAN to a country-specific BBAN.
*
* @param iban the IBAN to convert
* @param separator the separator to use between BBAN blocks
* @returns {string} the BBAN
* Converts the given IBAN to a country-specific BBAN.
* @param iban - The IBAN to convert.
* @param separator - The separator to use between BBAN blocks.
* @returns The BBAN or undefined if the conversion fails.
*/
toBBAN(iban: string, separator: string): string | undefined;
toBBAN(iban: string, separator?: string): string | undefined;
/**
* Convert the passed BBAN to an IBAN for this country specification.
* Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
* This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
*
* @param bban the BBAN to convert to IBAN
* @returns {string} the IBAN
* Converts the given BBAN to an IBAN according to this country's specification.
* @param bban - The BBAN to convert to IBAN.
* @returns The corresponding IBAN.
* @throws {Error} If the BBAN is invalid.
*/
fromBBAN(bban: string): string;
/**
* Check of the passed BBAN is valid.
* This function only checks the format of the BBAN (length and matching the letetr/number specs) but does not
* verify the check digit.
*
* @param bban the BBAN to validate
* @returns {boolean} true if the passed bban is a valid BBAN according to this specification, false otherwise
* Checks if the given BBAN is valid according to this specification.
* @param bban - The BBAN to validate.
* @returns True if the BBAN is valid, false otherwise.
*/
isValidBBAN(bban: string): boolean;
/**
* Lazy-loaded regex (parse the structure and construct the regular expression the first time we need it for validation)
* Gets a lazily-loaded regex constructed based on the BBAN structure.
* @returns The regular expression for validating the BBAN.
*/
private _regex;
/**
* Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
* numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
*
* @param {string} iban the IBAN
* @returns {string} the prepared IBAN
* Prepares an IBAN for mod 97 computation as specified in ISO13616.
* @param iban - The IBAN to prepare.
* @returns The prepared IBAN.
*/
private iso13616Prepare;
/**
* Parse the BBAN structure used to configure each IBAN Specification and returns a matching regular expression.
* A structure is composed of blocks of 3 characters (one letter and 2 digits). Each block represents
* a logical group in the typical representation of the BBAN. For each group, the letter indicates which characters
* are allowed in this group and the following 2-digits number tells the length of the group.
*
* @param {string} structure the structure to parse
* @returns {RegExp}
* Parses the BBAN structure and returns a matching regular expression.
* @param structure - The structure to parse.
* @returns A RegExp derived from the BBAN structure.
*/

@@ -75,7 +64,6 @@ private parseStructure;

* Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
*
* @param iban
* @returns {number}
* @param iban - The IBAN to calculate the MOD 97 10 for.
* @returns The MOD 97 10 result.
*/
private iso7064Mod97_10;
}
{
"name": "iban-ts",
"version": "0.2.0",
"description": "A javascript library to validate, format and convert IBAN (International Bank Account Number) and BBAN (Basic Bank Account Number)",
"version": "0.3.0",
"description": "A TypeScript library for validating, formatting, and converting IBAN (International Bank Account Number) and BBAN (Basic Bank Account Number), offering comprehensive support for international banking data standards.",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/iban-ts.esm.js",
"main": "dist/index.js",
"module": "dist/mylib.esm.js",
"typings": "dist/index.d.ts",
"exports": {

@@ -14,3 +15,2 @@ ".": {

},
"typings": "dist/index.d.ts",
"files": [

@@ -32,2 +32,7 @@ "dist",

},
"husky": {
"hooks": {
"pre-commit": "dts lint"
}
},
"prettier": {

@@ -39,3 +44,7 @@ "printWidth": 120,

},
"author": "Laurent VB",
"jest": {
"testEnvironment": "node"
},
"peerDependencies": {},
"author": "Altrim Beqiri",
"repository": "https://github.com/altrim/iban.js",

@@ -53,9 +62,10 @@ "size-limit": [

"devDependencies": {
"@size-limit/preset-small-lib": "7.0.8",
"@tsconfig/recommended": "1.0.1",
"dts-cli": "1.2.0",
"size-limit": "7.0.8",
"tslib": "2.3.1",
"typescript": "4.5.5"
"@size-limit/preset-small-lib": "11.0.1",
"@tsconfig/recommended": "1.0.3",
"dts-cli": "2.0.3",
"husky": "8.0.3",
"size-limit": "11.0.1",
"tslib": "2.6.2",
"typescript": "5.3.3"
}
}

@@ -1,52 +0,51 @@

[![npm version](https://badge.fury.io/js/iban.svg)](https://badge.fury.io/js/iban)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/arhs/iban.js/master/LICENSE)
# iban-ts
## Overview
# iban.js
`iban-ts` is a TypeScript library forked from [iban.js](https://github.com/arhs/iban.js), designed for validating, formatting, and converting International Bank Account Numbers (IBAN) and Basic Bank Account Numbers (BBAN).
IBAN and BBAN validation, formatting and conversion in Javascript.
Check the demo on [demo page] to try it.
## Installation
[demo page]: https://arhs.github.io/iban.js/
To install `iban-ts`, use npm or yarn:
IBAN.js follows the [ISO 13616 IBAN Registry technical specification](https://www.swift.com/standards/data-standards/iban).
```bash
npm install iban-ts
# or
yarn add iban-ts
```
## Usage
### Importing the Library
You can import the entire library or specific functions:
IBAN.js is compatible with both commonjs and AMD module definition. It can be used as a [node.js module](#in-nodejs) and [in the browser](#in-the-browser). It also has a bower manifest, a [Typescript definition](#with-typescript) and a [Meteor wrapper](#with-meteor-framework).
```ts
import * as IBAN from 'iban-ts';
// or
import { isValid, toBBAN, fromBBAN } from 'iban-ts';
```
### In node.js
### Validating an IBAN
To check if an IBAN is valid:
```js
var IBAN = require('iban');
IBAN.isValid('hello world'); // false
IBAN.isValid('BE68539007547034'); // true
```ts
const valid = IBAN.isValid('DE89370400440532013000');
console.log(valid); // true or false
```
### In the browser
### Converting BBAN to IBAN
To convert a BBAN to an IBAN:
Using a module loader (AMD or commonjs) or directly through the global ```IBAN``` object:
```html
<script src="iban.js"></script>
<script>
// the API is now accessible from the window.IBAN global object
IBAN.isValid('hello world'); // false
IBAN.isValid('BE68539007547034'); // true
</script>
```ts
const iban = IBAN.fromBBAN('DE', '370400440532013000');
console.log(iban); // DE89370400440532013000
```
### With TypeScript
The library is also available from the typescript language. To do this, [download the definition](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/iban) and add a reference to this:
```typescript
/// <reference path="iban.d.ts" />
IBAN.isValid('hello world');
IBAN.isValid('BE68539007547034');
### Formatting an IBAN
To format an IBAN for printing:
```ts
const formatted = IBAN.printFormat('DE89370400440532013000', ' ');
console.log(formatted); // DE89 3704 0044 0532 0130 00
```
### With Meteor framework
A wrapper package for the Meteor framework is available [here](https://atmospherejs.com/theduke/iban).
## API
* isValid(iban)

@@ -53,0 +52,0 @@ * toBBAN(iban, separator)

import { Specification } from './Specification';
const NON_ALPHANUM = /[^a-zA-Z0-9]/g;
const EVERY_FOUR_CHARS = /(.{4})(?!$)/g;
/**
* Removes non-alphanumeric characters from the string and converts it to uppercase.
*
* @param iban
* @returns {string}
* @param iban The IBAN string to format.
* @returns The formatted IBAN string.
*/
const electronicFormat = (iban: string): string => iban.replace(NON_ALPHANUM, '').toUpperCase();
// Map of country codes to their respective IBAN specifications
const countries: Record<string, Specification> = {};
/**
* Adds a new IBAN specification for a country.
*
* @param IBAN The IBAN specification to add.
*/
const addSpecification = (IBAN: Specification) => {

@@ -136,18 +146,15 @@ countries[IBAN.countryCode] = IBAN;

const NON_ALPHANUM = /[^a-zA-Z0-9]/g;
const EVERY_FOUR_CHARS = /(.{4})(?!$)/g;
/**
* Utility function to check if a variable is a String.
* Type guard for checking if a value is a string.
*
* @param value
* @returns {boolean} true if the passed variable is a String, false otherwise.
* @param value The value to check.
* @returns True if the value is a string, false otherwise.
*/
const isString = (value: any): boolean => typeof value == 'string' || value instanceof String;
const isString = (value: any): value is string => typeof value === 'string' || value instanceof String;
/**
* Check if an IBAN is valid.
* Validates an IBAN number.
*
* @param {string} iban the IBAN to validate.
* @returns {boolean} true if the passed IBAN is valid, false otherwise
* @param iban The IBAN to validate.
* @returns True if the IBAN is valid, false otherwise.
*/

@@ -160,3 +167,2 @@ const isValid = (iban: string): boolean => {

const countryStructure = countries[iban.slice(0, 2)];
return !!countryStructure && countryStructure.isValid(iban);

@@ -163,0 +169,0 @@ };

const A = 'A'.charCodeAt(0);
const Z = 'Z'.charCodeAt(0);
/**
* Create a new Specification for a valid IBAN number.
*
* @param countryCode the code of the country
* @param length the length of the IBAN
* @param structure the structure of the underlying BBAN (for validation and formatting)
* @param example an example valid IBAN
* @constructor
* Represents a specification for validating and manipulating IBANs (International Bank Account Numbers).
*/

@@ -20,2 +13,9 @@ export class Specification {

/**
* Creates a new instance of Specification.
* @param countryCode - The country code associated with the IBAN.
* @param length - The total length of the IBAN.
* @param structure - The structure of the underlying BBAN (Basic Bank Account Number).
* @param example - An example of a valid IBAN for this specification.
*/
constructor(countryCode: string, length: number, structure: string, example: string) {

@@ -29,6 +29,5 @@ this.countryCode = countryCode;

/**
* Check if the passed iban is valid according to this specification.
*
* @param {string} iban the iban to validate
* @returns {boolean} true if valid, false otherwise
* Checks if the given IBAN is valid according to this specification.
* @param iban - The IBAN to validate.
* @returns True if the IBAN is valid, false otherwise.
*/

@@ -45,9 +44,8 @@ isValid(iban: string): boolean {

/**
* Convert the passed IBAN to a country-specific BBAN.
*
* @param iban the IBAN to convert
* @param separator the separator to use between BBAN blocks
* @returns {string} the BBAN
* Converts the given IBAN to a country-specific BBAN.
* @param iban - The IBAN to convert.
* @param separator - The separator to use between BBAN blocks.
* @returns The BBAN or undefined if the conversion fails.
*/
toBBAN(iban: string, separator: string): string | undefined {
toBBAN(iban: string, separator: string = ' '): string | undefined {
return this._regex()?.exec(iban.slice(4))?.slice(1).join(separator);

@@ -57,8 +55,6 @@ }

/**
* Convert the passed BBAN to an IBAN for this country specification.
* Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
* This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
*
* @param bban the BBAN to convert to IBAN
* @returns {string} the IBAN
* Converts the given BBAN to an IBAN according to this country's specification.
* @param bban - The BBAN to convert to IBAN.
* @returns The corresponding IBAN.
* @throws {Error} If the BBAN is invalid.
*/

@@ -70,4 +66,4 @@ fromBBAN(bban: string): string {

const remainder = this.iso7064Mod97_10(this.iso13616Prepare(this.countryCode + '00' + bban));
const checkDigit = ('0' + (98 - remainder)).slice(-2);
const prepared = this.iso13616Prepare(this.countryCode + '00' + bban);
const checkDigit = ('0' + (98 - this.iso7064Mod97_10(prepared))).slice(-2);

@@ -78,8 +74,5 @@ return this.countryCode + checkDigit + bban;

/**
* Check of the passed BBAN is valid.
* This function only checks the format of the BBAN (length and matching the letetr/number specs) but does not
* verify the check digit.
*
* @param bban the BBAN to validate
* @returns {boolean} true if the passed bban is a valid BBAN according to this specification, false otherwise
* Checks if the given BBAN is valid according to this specification.
* @param bban - The BBAN to validate.
* @returns True if the BBAN is valid, false otherwise.
*/

@@ -91,14 +84,16 @@ isValidBBAN(bban: string): boolean {

/**
* Lazy-loaded regex (parse the structure and construct the regular expression the first time we need it for validation)
* Gets a lazily-loaded regex constructed based on the BBAN structure.
* @returns The regular expression for validating the BBAN.
*/
private _regex(): RegExp {
return this._cachedRegex || (this._cachedRegex = this.parseStructure(this.structure));
if (!this._cachedRegex) {
this._cachedRegex = this.parseStructure(this.structure);
}
return this._cachedRegex;
}
/**
* Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
* numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
*
* @param {string} iban the IBAN
* @returns {string} the prepared IBAN
* Prepares an IBAN for mod 97 computation as specified in ISO13616.
* @param iban - The IBAN to prepare.
* @returns The prepared IBAN.
*/

@@ -109,61 +104,34 @@ private iso13616Prepare(iban: string): string {

return iban
.split('')
.map(function (n) {
const code = n.charCodeAt(0);
if (code >= A && code <= Z) {
// A = 10, B = 11, ... Z = 35
return code - A + 10;
} else {
return n;
}
})
.join('');
return iban.replace(/[A-Z]/g, (match) => (match.charCodeAt(0) - A + 10).toString());
}
/**
* Parse the BBAN structure used to configure each IBAN Specification and returns a matching regular expression.
* A structure is composed of blocks of 3 characters (one letter and 2 digits). Each block represents
* a logical group in the typical representation of the BBAN. For each group, the letter indicates which characters
* are allowed in this group and the following 2-digits number tells the length of the group.
*
* @param {string} structure the structure to parse
* @returns {RegExp}
* Parses the BBAN structure and returns a matching regular expression.
* @param structure - The structure to parse.
* @returns A RegExp derived from the BBAN structure.
*/
private parseStructure(structure: string): RegExp {
// split in blocks of 3 chars
const regex = structure.match(/(.{3})/g)?.map(function (block) {
// parse each structure block (1-char + 2-digits)
let format;
const pattern = block.slice(0, 1);
const repeats = parseInt(block.slice(1), 10);
const formats: { [key: string]: string } = {
A: '0-9A-Za-z',
B: '0-9A-Z',
C: 'A-Za-z',
F: '0-9',
L: 'a-z',
U: 'A-Z',
W: '0-9a-z',
};
switch (pattern) {
case 'A':
format = '0-9A-Za-z';
break;
case 'B':
format = '0-9A-Z';
break;
case 'C':
format = 'A-Za-z';
break;
case 'F':
format = '0-9';
break;
case 'L':
format = 'a-z';
break;
case 'U':
format = 'A-Z';
break;
case 'W':
format = '0-9a-z';
break;
}
const regex = structure
.match(/.{3}/g)
?.map((block) => {
const [pattern, repeats] = [block[0], parseInt(block.slice(1), 10)];
return '([' + format + ']{' + repeats + '})';
});
if (!formats[pattern]) {
throw new Error(`Invalid pattern: ${pattern}`);
}
return new RegExp('^' + regex?.join('') + '$');
return `([${formats[pattern]}]{${repeats}})`;
})
.join('');
return new RegExp(`^${regex}$`);
}

@@ -173,12 +141,9 @@

* Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
*
* @param iban
* @returns {number}
* @param iban - The IBAN to calculate the MOD 97 10 for.
* @returns The MOD 97 10 result.
*/
private iso7064Mod97_10(iban: string): number {
let remainder = iban;
let block: string | any[];
while (remainder.length > 2) {
block = remainder.slice(0, 9);
const block = remainder.slice(0, 9);
remainder = (parseInt(block, 10) % 97) + remainder.slice(block.length);

@@ -185,0 +150,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc