function DNI_CL({ run, string }){
if(run !== '' && (typeof run === "string" || typeof run === "number")){
function format(n){
if (typeof n === 'string') {
// Remove '.' if exist
n = (n.includes('.')) ? n.split('.').join('') : n;
// Remove '-' if exist
n = (n.includes('-')) ? n.split('-').join('') : n;
}
return n;
}
function DV(n){
// Initialize multiples and total
let m = 2, sum = 0;
// Reverse string
n = n.split('').reverse().join('');
// Algorithm to get the DV
n.split('').map((i) => {
// Multiply digit by multiples [2,7]
sum += (Number(i) * m);
// Add one to mutiple variable
m = (m < 7) ? m+1 : 2;
});
// Get remainder of the division and after get subtraction
const dv = (11 - (sum % 11));
return (dv === 10) ? 'K' : (dv === 11) ? 0 : dv ;
}
function formatter({run, dv}){
// Get the first numbers
const a1 = run.slice(0, run.length - 6);
// Get the last 6 numbrs
const a2 = run.slice(run.length - 6, run.length).match(/.{1,3}/g).join('.');
// Return in string or number format
return (string) ? ((dv) ? `${a1}.${a2}-${DV(run)}` : `${a1}.${a2}`) : ((dv && typeof DV(run) === "number") ? Number(`${run}${DV(run)}`) : Number(run));
}
run = format(run);
// Get DV
let dv = run.toString().split('')[run.toString().split('').length - 1];
// If is number convert or set to uppercase
dv = (Number(dv)) ? Number(dv) : dv.toUpperCase();
// Format and remove the last number
run = run.toString().slice(0, -1);
// Return JSON format
return {
run: formatter({run, dv: true}),
adv: formatter({run}),
dv: (string) ? DV(run).toString() : DV(run),
valid: (DV(run).toString() === dv.toString())
}
} else {
return { run: 0, adv: 0, dv: 0, valid: false };
}
}
function DNI_CL({run,string}){if(run!==''&&(typeof run==="string"||typeof run==="number")){function format(n){if(typeof n==='string'){n=(n.includes('.'))?n.split('.').join(''):n;n=(n.includes('-'))?n.split('-').join(''):n}
return n}
function DV(n){let m=2,sum=0;n=n.split('').reverse().join('');n.split('').map((i)=>{sum+=(Number(i)*m);m=(m<7)?m+1:2});const dv=(11-(sum%11));return(dv===10)?'K':(dv===11)?0:dv}
function formatter({run,dv}){const a1=run.slice(0,run.length-6);const a2=run.slice(run.length-6,run.length).match(/.{1,3}/g).join('.');return(string)?((dv)?`${a1}.${a2}-${DV(run)}`:`${a1}.${a2}`):((dv&&typeof DV(run)==="number")?Number(`${run}${DV(run)}`):Number(run))}
run=format(run);let dv=run.toString().split('')[run.toString().split('').length-1];dv=(Number(dv))?Number(dv):dv.toUpperCase();run=run.toString().slice(0,-1);return{run:formatter({run,dv:!0}),adv:formatter({run}),dv:(string)?DV(run).toString():DV(run),valid:(DV(run).toString()===dv.toString())}}else{return{run:0,adv:0,dv:0,valid:!1}}}