Skip to content

Commit

Permalink
WIP: getRegionByDni
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavochavarria committed Sep 26, 2019
1 parent d6c1ac1 commit 32336b7
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
export 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])/;

return regex.test(dni);
};

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

Expand All @@ -19,3 +23,24 @@ export const dnicWithDateValidation = dni => {

return !!newDate;
};


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

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 foundRegion = mapRegions.find(r => r[region]);

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

0 comments on commit 32336b7

Please sign in to comment.