Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/albertfdp/dni-js
Compute and validate a Spanish DNI/NIE number
https://github.com/albertfdp/dni-js
calculo compute dni nie number numero spain spanish validar validate
Last synced: about 5 hours ago
JSON representation
Compute and validate a Spanish DNI/NIE number
- Host: GitHub
- URL: https://github.com/albertfdp/dni-js
- Owner: albertfdp
- License: mit
- Created: 2017-07-16T10:00:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T03:51:33.000Z (over 1 year ago)
- Last Synced: 2024-10-05T02:18:00.353Z (about 1 month ago)
- Topics: calculo, compute, dni, nie, number, numero, spain, spanish, validar, validate
- Language: JavaScript
- Size: 1.25 MB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dni-js
Compute and validate a Spanish DNI/NIE numbers as described [here](http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie).
[![Build Status](https://travis-ci.org/albertfdp/dni-js.svg?branch=master)](https://travis-ci.org/albertfdp/dni-js)
[![npm version](https://badge.fury.io/js/dni-js.svg)](https://badge.fury.io/js/dni-js)## Install
```
$ npm install dni-js
```## Usage
Validation is based on this [document](http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie).
```js
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:
```js
dni.normalize(' 12 34 56 7 8-z'); // 12345678-Z
```## License
MIT