ibantools-germany
Version:
IBAN Validator and Generator for German Bank Accounts
32 lines (31 loc) • 1.13 kB
JavaScript
;
/**
* ibantools-germany
* Copyright (c) 2022-2026 Markus Baumer <markus@baumer.dev>
* SPDX-License-Identifier: MIT OR MPL-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.method02Core = void 0;
const helper_1 = require("../helper");
const method02Core = (number, weights) => {
const digits = (0, helper_1.getDigits)(number);
const givenCheckDigit = digits.pop(); // Check digit is last digit
const weightedDigits = (0, helper_1.weightDigitsRTL)(digits, weights);
const sum = (0, helper_1.calculateSum)(weightedDigits);
const { difference: calculatedCheckDigit } = (0, helper_1.moduloDifference)(sum, 11, 11);
if (calculatedCheckDigit === 11) {
if (givenCheckDigit === 0) {
return "VALID";
}
return "INVALID";
}
if (calculatedCheckDigit === 10) {
return "INVALID";
}
if (givenCheckDigit === calculatedCheckDigit) {
return "VALID";
}
return "INVALID";
};
exports.method02Core = method02Core;
exports.default = (number) => (0, exports.method02Core)(number, [2, 3, 4, 5, 6, 7, 8, 9, 2]);