Skip to content

Commit c21668a

Browse files
committed
Add dni module
1 parent 101b13c commit c21668a

File tree

7 files changed

+3266
-1
lines changed

7 files changed

+3266
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
coverage

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# dni-js
2-
Compute and validate a Spanish DNI/NIE number
2+
Compute and validate a Spanish DNI/NIE numbers.
3+
4+
## Install
5+
6+
```
7+
$ npm install dni-js
8+
```
9+
10+
## Usage
11+
12+
Validation is based on this [document](http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie).
13+
14+
```js
15+
const dni = require('dni-js');
16+
17+
dni.isValid('12345678-Z'); // => true
18+
```
19+
20+
### API
21+
22+
#### `.dni (number|string)`
23+
24+
Returns a DNI number with the control digit appended in the format `12345678-Z`. If the input is invalid,
25+
returns `null`.
26+
27+
#### `.nie (number|string)`
28+
29+
Returns a NIE number with the control digit appended in the format `X1234567-L`. If the input is invalid,
30+
returns `null`.
31+
32+
#### `.getControlDigit (number|string)`
33+
34+
Returns the control digit for the input.
35+
36+
#### `.getLetter (number|string)`
37+
38+
Alias for `getControlDigit`.
39+
40+
#### `.isValid (string)`
41+
42+
Returns `true` or `false` by validating the input.
43+
44+
## License
45+
46+
MIT

0 commit comments

Comments
 (0)