Skip to content

Commit

Permalink
fix: validate nie with x fails
Browse files Browse the repository at this point in the history
  • Loading branch information
singuerinc committed May 22, 2018
1 parent 08a3446 commit f2773cf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions dni.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ describe('dni', () => {

describe('valid', () => {
describe('nif', () => {
it('should validate x9464186p', () => {
assert.equal(isValid('x9464186p'), true);
});

it('should validate 55799910R', () => {
assert.equal(isValid('55799910R'), true);
});
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const isValid = value => {

if (!value && !_isNIF(dni) && !_isNIE(dni)) return false;

const f = { x: 0, y: 1, z: 2 }[dni[0]] || dni[0];
const f = { x: '0', y: '1', z: '2' }[dni[0]] || dni[0];
const dni_1_to_7 = dni.substr(1, 7);
const i = +(f + dni_1_to_7) % 23;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.min.js",
"license": "MIT",
"author": "Nahuel Scotti <nahuel.scotti@gmail.com> (https://www.singuerinc.com)",
"repository": "singuerinc/better-dni.git",
"repository": "singuerinc/better-dni",
"engines": {
"node": ">=6"
},
Expand Down

0 comments on commit f2773cf

Please sign in to comment.