ibantools-germany
Version:
IBAN Validator and Generator for German Bank Accounts
77 lines (74 loc) • 3.1 kB
JavaScript
;
/**
* ibantools-germany
* Copyright (C) 2022-2024 Markus Baumer <markus@baumer.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const helper_1 = require("../helper");
const method00_1 = require("./method00");
const method09_1 = __importDefault(require("./method09"));
const method57Variation1 = (number) => {
const firstSixDigits = number.slice(0, 6);
if (firstSixDigits === "777777" || firstSixDigits === "888888") {
return (0, method09_1.default)(number);
}
return (0, method00_1.method00Core)(number, [1, 2, 1, 2, 1, 2, 1, 2, 1], { rtl: false });
};
const method57Variation2 = (number) => (0, method00_1.method00Core)(number, [1, 2, 1, 2, 1, 2, 1, 2, 1], {
checkDigitPosition: 3,
rtl: false,
});
const method57Variation3 = (number) => {
return (0, method09_1.default)(number);
};
const method57Variation4 = (number) => {
if (number === "0185125434") {
return "VALID";
}
const thirdFourthNumber = Number(number.slice(2, 4));
const seventhToNinthNumber = Number(number.slice(6, 9));
if (thirdFourthNumber >= 1 &&
thirdFourthNumber <= 12 &&
seventhToNinthNumber < 500) {
return "VALID";
}
return "INVALID";
};
exports.default = (number) => {
const paddedNumber = (0, helper_1.paddedAccountNumber)(number);
const firstSecondNumber = Number(paddedNumber.slice(0, 2));
if ([51, 55, 61, 64, 65, 66, 70, 88, 94, 95].includes(firstSecondNumber) ||
(firstSecondNumber >= 73 && firstSecondNumber <= 82)) {
return method57Variation1(paddedNumber);
}
if ([
52, 53, 54, 62, 63, 67, 68, 69, 71, 72, 89, 90, 92, 93, 96, 97, 98,
].includes(firstSecondNumber) ||
(firstSecondNumber >= 32 && firstSecondNumber <= 39) ||
(firstSecondNumber >= 41 && firstSecondNumber <= 49) ||
(firstSecondNumber >= 56 && firstSecondNumber <= 60) ||
(firstSecondNumber >= 83 && firstSecondNumber <= 87)) {
return method57Variation2(paddedNumber);
}
if ([40, 50, 91, 99].includes(firstSecondNumber)) {
return method57Variation3(paddedNumber);
}
if (firstSecondNumber >= 1 && firstSecondNumber <= 31) {
return method57Variation4(paddedNumber);
}
return "INVALID";
};