Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
raupach-e2n committed Nov 1, 2023
1 parent 4982507 commit 295e929
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 45 deletions.
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 14 additions & 20 deletions validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
* SOFTWARE.
/*
/* IBAN REGISTRY Release 94 - Apr 2023 */
/* IBAN REGISTRY Release 95 – Jul 2023 */
const iban_registry = new Map(Object.entries({
"AD": 24, "AE": 23, "AL": 28, "AT": 20, "AZ": 28, "BA": 20, "BE": 16, "BG": 22, "BH": 22, "BI": 27, "BR": 29,
"BY": 28, "CH": 21, "CR": 22, "CY": 28, "CZ": 24, "DE": 22, "DJ": 27, "DK": 18, "DO": 28, "EE": 20, "EG": 29,
"ES": 24, "FI": 18, "FO": 18, "FR": 27, "GB": 22, "GE": 22, "GI": 23, "GL": 18, "GR": 27, "GT": 28, "HR": 21,
"HU": 28, "IE": 22, "IL": 23, "IQ": 23, "IS": 26, "IT": 27, "JO": 30, "KW": 30, "KZ": 20, "LB": 28, "LC": 32,
"LI": 21, "LT": 20, "LU": 20, "LV": 21, "LY": 25, "MC": 27, "MD": 24, "ME": 22, "MK": 19, "MN": 20, "MR": 27,
"MT": 31, "MU": 30, "NI": 28, "NL": 18, "NO": 15, "PK": 24, "PL": 28, "PS": 29, "PT": 25, "QA": 29, "RO": 24,
"RS": 22, "RU": 33, "SA": 24, "SC": 31, "SD": 18, "SE": 24, "SI": 19, "SK": 24, "SM": 27, "SO": 23, "ST": 25,
"SV": 28, "TL": 23, "TN": 24, "TR": 26, "UA": 29, "VA": 22, "VG": 24, "XK": 20,
"ES": 24, "FI": 18, "FK": 18, "FO": 18, "FR": 27, "GB": 22, "GE": 22, "GI": 23, "GL": 18, "GR": 27, "GT": 28,
"HR": 21, "HU": 28, "IE": 22, "IL": 23, "IQ": 23, "IS": 26, "IT": 27, "JO": 30, "KW": 30, "KZ": 20, "LB": 28,
"LC": 32, "LI": 21, "LT": 20, "LU": 20, "LV": 21, "LY": 25, "MC": 27, "MD": 24, "ME": 22, "MK": 19, "MN": 20,
"MR": 27, "MT": 31, "MU": 30, "NI": 28, "NL": 18, "NO": 15, "PK": 24, "PL": 28, "PS": 29, "PT": 25, "QA": 29,
"RO": 24, "RS": 22, "RU": 33, "SA": 24, "SC": 31, "SD": 18, "SE": 24, "SI": 19, "SK": 24, "SM": 27, "SO": 23,
"ST": 25, "SV": 28, "TL": 23, "TN": 24, "TR": 26, "UA": 29, "VA": 22, "VG": 24, "XK": 20,
}));

/* EAN8, 13 and 18 weights */
Expand Down Expand Up @@ -64,17 +64,13 @@ function digit_sum(value) {
return digit_sum;
}

/* Luhn algorithm */


/**
* International Bank Account Numbers (IBAN).
* IBAN stands for International Bank Account Number. It is the ISO 13616 international
* standard for numbering bank accounts.
*
* Returns true if the input is in a compliant format and passes the check-digit validation.
* An IBAN is validated by converting it into an integer and performing mod-97 operation (as described in ISO 7064) on it.
* @public
* @param {string} input
* @returns {boolean}
* @returns {boolean} true, if the input is in ISO 13616-compliant national IBAN formats and passes the check-digit validation.
*/
function iban(input) {
/* Null, undefined and blank check */
Expand All @@ -90,21 +86,19 @@ function iban(input) {
/* Transform IBAN print format to IBAN electronic format */
input = input.replace(/\s/g, "");

/* Check that the IBAN length matches the country's IBAN length */
/* Check the country code for existence */
let country_code = input.slice(0, 2);
/* Check that the IBAN length matches the country's IBAN length */
let country_iban_length = iban_registry.get(country_code);

if (country_iban_length === undefined) {
return false;
}

if (country_iban_length !== input.length) {
if (country_iban_length === undefined || country_iban_length !== input.length) {
return false;
}

/* Move the four initial characters to the end of the string */
let d = input.slice(4) + input.slice(0, 4);

/* An IBAN is validated by converting it into an integer and performing mod-97 operation (as described in ISO 7064) on it. */

/* Replace each letter in the string with two digits */
d = d.replaceAll("A", "10");
Expand Down
11 changes: 9 additions & 2 deletions validators.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { iban, vsnr, ean, isbn, nir, pan } = require("./validators");

describe('iban', function() {
describe("International Bank Account Number (IBAN)", function() {
test.each([
["AD1200012030200359100100", true],
["AD12 0001 2030 2003 5910 0100", true],
Expand Down Expand Up @@ -49,6 +49,8 @@ describe('iban', function() {
["ES91 2100 0418 4502 0005 1332", true],
["FI2112345600000785", true],
["FI21 1234 5600 0007 85", true],
["FK88SC123456789012", true],
["FK88 SC12 3456 7890 12", true],
["FO6264600001631634", true],
["FO62 6460 0001 6316 34", true],
["FR1420041010050500013M02606", true],
Expand Down Expand Up @@ -146,7 +148,12 @@ describe('iban', function() {
["XK051212012345678906", true],
["DE89 3740 0044 0532 0130 00", false],
["DE89 3740 0044 0532 0130", false],
["US64SVBKUS6S3300958879", false]
["US64SVBKUS6S3300958879", false],
["XX1200012030200359100100", false],
[undefined, false],
[null, false],
[0, false],
["", false],
])('%s', (input, expected) => {
expect(iban(input)).toBe(expected);
});
Expand Down

0 comments on commit 295e929

Please # to comment.