peru-dni

6.0.7 • Public • Published

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

Package Sidebar

Install

npm i peru-dni

Weekly Downloads

4

Version

6.0.7

License

GNU V3

Unpacked Size

39.1 kB

Total Files

5

Last publish

Collaborators

  • shokocc