Skip to content

Latest commit

 

History

History
72 lines (56 loc) · 1.43 KB

README.md

File metadata and controls

72 lines (56 loc) · 1.43 KB

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