ibantools-germany
Version:
IBAN Validator and Generator for German Bank Accounts
81 lines (78 loc) • 3.77 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 });
exports.method51NominalAccount = void 0;
const helper_1 = require("../helper");
const method00_1 = __importDefault(require("./method00"));
const method06_1 = require("./method06");
const method33_1 = require("./method33");
const method51aCore = (number) => {
const digits = (0, helper_1.getDigits)(number.slice(3, 10));
const givenCheckDigit = digits.pop(); // Check digit is last digit
const weightedDigits = (0, helper_1.weightDigitsRTL)(digits, [2, 3, 4, 5, 6, 7]);
const sum = (0, helper_1.calculateSum)(weightedDigits);
const { difference: calculatedCheckDigit } = (0, helper_1.moduloDifference)(sum, 11, 11);
return (0, method06_1.method06Result)(givenCheckDigit, calculatedCheckDigit);
};
const method51bCore = (number) => (0, method33_1.method33Core)(number, [2, 3, 4, 5, 6]);
const method51cCore = (number) => (0, method00_1.default)(number.slice(3, 10));
const method51dCore = (number) => (0, method33_1.method33Core)(number, [2, 3, 4, 5, 6], 7, 0);
const method51dVariation1 = (number) => {
const digits = (0, helper_1.getDigits)(number.slice(2, 10));
const givenCheckDigit = digits.pop(); // Check digit is last digit
const weightedDigits = (0, helper_1.weightDigitsRTL)(digits, [2, 3, 4, 5, 6, 7, 8]);
const sum = (0, helper_1.calculateSum)(weightedDigits);
const { difference: calculatedCheckDigit } = (0, helper_1.moduloDifference)(sum, 11, 11);
return (0, method06_1.method06Result)(givenCheckDigit, calculatedCheckDigit);
};
const method51dVariation2 = (number) => {
const digits = (0, helper_1.getDigits)(number);
const givenCheckDigit = digits.pop(); // Check digit is last digit
const weightedDigits = (0, helper_1.weightDigitsRTL)(digits, [2, 3, 4, 5, 6, 7, 8, 9, 10]);
const sum = (0, helper_1.calculateSum)(weightedDigits);
const { difference: calculatedCheckDigit } = (0, helper_1.moduloDifference)(sum, 11, 11);
return (0, method06_1.method06Result)(givenCheckDigit, calculatedCheckDigit);
};
const method51NominalAccount = (number) => {
if (method51dVariation1(number) === "VALID") {
return "VALID";
}
return method51dVariation2(number);
};
exports.method51NominalAccount = method51NominalAccount;
exports.default = (number) => {
const paddedNumber = (0, helper_1.paddedAccountNumber)(number);
if (method51aCore(paddedNumber) === "VALID") {
return "VALID";
}
if (method51bCore(paddedNumber) === "VALID") {
return "VALID";
}
if (method51cCore(paddedNumber) === "VALID") {
return "VALID";
}
if (Number(paddedNumber.slice(9, 10)) >= 7) {
return "INVALID";
}
if (paddedNumber.slice(2, 3) === "9") {
return (0, exports.method51NominalAccount)(paddedNumber);
}
return method51dCore(paddedNumber);
};