function elfProefValidation(value, type) {
let returnValue = false;
if (!value || value.length === 0) {
// This is to prevent behaviour that looks like the OWN is required
return true;
}
if (value === '00000000000' || value.length !== 9) {
return false;
}
const values = value.split('');
const lastCharacter = parseInt(values[values.length - 1], 10);
const [a, b, c, d, e, f, g, h, i] = values.map((char) => parseInt(char, 10));
let result = 0;
if (type === 'bsn') {
result = 9 * a + 8 * b + 7 * c + 6 * d + 5 * e + 4 * f + 3 * g + 2 * h + -1 * i;
returnValue = result > 0 && result % 11 === 0;
} else if (type === 'own') {
result = 9 * a + 8 * b + 7 * c + 6 * d + 5 * e + 4 * f + 3 * g + 2 * h;
returnValue = result > 0 && result % 11 === lastCharacter + 5;
} else {
returnValue = false;
}
return returnValue;
}
const bsn = '010464554';
const own = '101211151';
console.log('BSN: ', elfProefValidation(bsn, 'bsn'));
console.log('OWN: ', elfProefValidation(own, 'own'));