Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
hosmelq committed Sep 26, 2019
1 parent 7006211 commit 5e2ecc3
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
export const dnic = dni => {
if(!dni){
return false;
}
const dnic = dni => {
if (!dni) {
return false;
}

const regex = /([0-6][d]{2})-([0-2][d]|3[0-1])(0[1-9]|1[0-2])([d]{2})-([d]{4}[A-X])/;
const regex = /([0-6][d]{2})-([0-2][d]|3[0-1])(0[1-9]|1[0-2])([d]{2})-([d]{4}[A-X])/;

return regex.test(dni);
return regex.test(dni);
};

export default dnic;

export const dnicWithDateValidation = dni => {
if (!dnic(dni)) {
return false;
}
if (!dnic(dni)) {
return false;
}

const date = dni.split('-')[1];
const date = dni.split('-')[1];

const day = date.slice(0,2);
const month = date.slice(2, 4);
const year = date.slice(4,6);
const day = date.slice(0, 2);
const month = date.slice(2, 4);
const year = date.slice(4, 6);

const newDate = new Date(year, (month -1), day);

return !!newDate;
};
const newDate = new Date(year, month - 1, day);

return Boolean(newDate);
};

export const getRegionByDni = dni => {
if (!dnic(dni)) {
return false;
}
if (!dnic(dni)) {
return false;
}

const region = dni.split('-')[0];
const region = dni.split('-')[0];

const mapRegions = [
{'001' : 'Managua'},
{'002' : 'San Rafael Del Sur'},
{'003' : 'Tipitapa'},
{'004' : 'Villa Carlos Fonseca'},
{'005' : 'San Francisco Libre'}
];
const mapRegions = [
{'001': 'Managua'},
{'002': 'San Rafael Del Sur'},
{'003': 'Tipitapa'},
{'004': 'Villa Carlos Fonseca'},
{'005': 'San Francisco Libre'}
];

const foundRegion = mapRegions.find(r => r[region]);
const foundRegion = mapRegions.find(r => r[region]);

return Object.values(foundRegion)[0];
}
return Object.values(foundRegion)[0];
};

0 comments on commit 5e2ecc3

Please sign in to comment.