0.2.1 • Published 3 years ago

dni-js v0.2.1

Weekly downloads
287
License
MIT
Repository
github
Last release
3 years ago

dni-js

Compute and validate a Spanish DNI/NIE numbers as described here.

Build Status npm version

Install

$ npm install dni-js

Usage

Validation is based on this document.

const dni = require('dni-js');

dni.isValid('12345678-Z'); // => true

API

.dni (number|string)

Returns a DNI number with the control digit appended in the format 12345678-Z. If the input is invalid, returns null.

.nie (number|string)

Returns a NIE number with the control digit appended in the format X1234567-L. If the input is invalid, returns null.

.getControlDigit (number|string)

Returns the control digit for the input.

.getLetter (number|string)

Alias for getControlDigit.

.isValid (string)

Returns true or false by validating the input.

.normalize (string)

Given a string input, it returns a normalized valid DNI. When input is either not a string, or invalid, it returns null. For example:

dni.normalize('   12 34 56 7 8-z'); // 12345678-Z

License

MIT

0.2.1

3 years ago

0.2.0

5 years ago

0.1.1

7 years ago

0.1.0

7 years ago