ibantools-germany
Version:
IBAN Validator and Generator for German Bank Accounts
57 lines (56 loc) • 1.96 kB
JavaScript
;
/**
* ibantools-germany
* Copyright (c) 2022-2026 Markus Baumer <markus@baumer.dev>
* SPDX-License-Identifier: MIT OR MPL-2.0
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.eserValidate = void 0;
const helper_1 = require("../helper");
const method20_1 = __importDefault(require("./method20"));
const eser8 = (number, blz) => {
if (number.length !== 8) {
return null;
}
const blz58 = blz.slice(4, 8);
const number12 = number.slice(0, 2);
const number3Rest = number.slice(2, 8).replace(/^0+/, "");
return `${blz58}${number12}${number3Rest}`;
};
const eserValidate = (eserAccount) => {
const digits = (0, helper_1.getDigits)(eserAccount);
const givenCheckDigit = digits.slice(5, 6)[0]; // Check digit is last digit
const weigths = [2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4].slice(0, digits.length);
weigths.reverse();
const checkDigitWeight = weigths.splice(5, 1, 0)[0];
const weightedDigits = (0, helper_1.weightDigits)(digits, weigths);
const sum = (0, helper_1.calculateSum)(weightedDigits);
const modulo11 = sum % 11;
for (let i = 0; i < 10; i++) {
const modulo = (modulo11 + i * checkDigitWeight) % 11;
if (modulo === 10) {
if (givenCheckDigit === i) {
return "VALID";
}
break;
}
}
return "INVALID";
};
exports.eserValidate = eserValidate;
exports.default = (number, blz) => {
if (number.length === 10 && number.match(/^9/)) {
return (0, method20_1.default)(number);
}
if (blz.length !== 8 || !blz.match(/^\d{3}5/)) {
return "INVALID";
}
const eserAccount = eser8(number, blz);
if (!eserAccount) {
return "INVALID";
}
return (0, exports.eserValidate)(eserAccount);
};