ibantools-germany
Version:
IBAN Validator and Generator for German Bank Accounts
52 lines (51 loc) • 2.3 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.method06Core = exports.method06Result = exports.method06CheckDigit = void 0;
const helper_1 = require("../helper");
const method06CheckDigit = (number, weights, modulo = 11) => {
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, remainder } = (0, helper_1.moduloDifference)(sum, modulo, modulo);
return { calculatedCheckDigit, diffRemainder: remainder, givenCheckDigit };
};
exports.method06CheckDigit = method06CheckDigit;
const method06Result = (givenCheckDigit, calculatedCheckDigit, diff10CheckDigit = 0, diff11CheckDigit = 0) => {
if (calculatedCheckDigit === 10) {
if (givenCheckDigit === diff10CheckDigit) {
return "VALID";
}
return "INVALID";
}
if (calculatedCheckDigit === 11) {
if (givenCheckDigit === diff11CheckDigit) {
return "VALID";
}
return "INVALID";
}
if (givenCheckDigit === calculatedCheckDigit) {
return "VALID";
}
return "INVALID";
};
exports.method06Result = method06Result;
/**
* @param number Significant digits for calculation and check digit at the rightmost position
* @param weights Weight for calculation, must be at
* @param diff10CheckDigit Check digit if moduloDifference returns 10
* @param diff11CheckDigit Check digit if moduloDifference returns 11
* @param modulo Moduolo for moduloDifference
* @returns
*/
const method06Core = (number, weights, diff10CheckDigit = 0, diff11CheckDigit = 0, modulo = 11) => {
const { calculatedCheckDigit, givenCheckDigit } = (0, exports.method06CheckDigit)(number, weights, modulo);
return (0, exports.method06Result)(givenCheckDigit, calculatedCheckDigit, diff10CheckDigit, diff11CheckDigit);
};
exports.method06Core = method06Core;
exports.default = (number) => (0, exports.method06Core)(number, [2, 3, 4, 5, 6, 7, 2, 3, 4]);