Skip to content

ChoqueCastroLD/peru-dni

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

peru-dni

npm npm bundle size GitHub stars

Node module to fetch real name from peruvian's dni

How to Install:

Using npm:

> $ npm install peru-dni --save

How to use:

(Nodejs example)

const perudni = require('peru-dni');

// using Promises
perudni.getNameFromDNI(71747104)
    .then(data => {
        console.log('Real name is ' + data.fullname);
    })
    .catch(err => {
        console.log('Something went wrong ', err);
    });

// using async/await
async function main() {
    try {
        let data = await perudni.getNameFromDNI(71747104);

        console.log(`${data.dni} > ${data.fullname}`);
    } catch (err) {
        console.log('Something went wrong ', err);
    }
}
main();
    

getNameFromDNI() If everything works well it will return an object like this:

{
    dni: '00000003',
    fullname: 'CARLOTA MEZA DE RUIZ',
    lastname: 'MEZA',
    secondlastname: 'DE RUIZ',
    name: 'CARLOTA'
}

If there's no one with that DNI

{
    dni: '00000000',
    error: 'DNI no encontrado en Padrón Electoral',
    message: 'Cant get name from that DNI'
}

If there's no connection with the external public API, it will throw an error

'Fetch failed'

Run tests with

$ npm run test

About

Node module to fetch real name from peruvian's dni

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published