Skip to content

Commit

Permalink
fix: randomNIE & randomNIF return uppper case
Browse files Browse the repository at this point in the history
  • Loading branch information
singuerinc committed May 31, 2018
1 parent 77dda45 commit dced6f7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 33 deletions.
26 changes: 12 additions & 14 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "better-dni",
"version": "2.1.1",
"version": "2.1.2",
"description": "The fastest Spanish DNI (NIE / NIF) validation",
"main": "dist/index.js",
"license": "MIT",
Expand Down
12 changes: 10 additions & 2 deletions src/ctrlChar.js
@@ -1,4 +1,4 @@
import { _char } from './internal/_char';
import { _letter } from './internal/_utils';

/**
* Returns the control letter in upper case
Expand All @@ -12,6 +12,14 @@ import { _char } from './internal/_char';
* ctrlChar("03118880B"); // => 'B'
* ctrlChar("03118880"); // => 'B'
*/
const ctrlChar = x => _char(x).toUpperCase();
const ctrlChar = y => {
// Get a number from 0 - 2 when `y` is a NIE
let f = 'xyzXYZ'.indexOf(y[0]) % 3;
// Otherwise default to the number (NIF case only)
if (f === -1) f = y[0];
// Strip the letters
const i = `${f}${y.slice(1, 8)}`;
return _letter(i).toUpperCase();
};

export { ctrlChar };
13 changes: 0 additions & 13 deletions src/internal/_char.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/randomNIE.js
Expand Up @@ -10,7 +10,7 @@ import { _randStrLimit, _letter } from './internal/_utils';
const randomNIE = () => {
const r = Math.floor(Math.random() * 3);
const nn = _randStrLimit(7);
const l = _letter(+`${r}${nn}`);
const l = _letter(+`${r}${nn}`).toUpperCase();
return `${'XYZ'[r]}${nn}${l}`;
};

Expand Down
2 changes: 1 addition & 1 deletion src/randomNIF.js
Expand Up @@ -9,7 +9,7 @@ import { _randStrLimit, _letter } from './internal/_utils';
*/
const randomNIF = () => {
const nn = _randStrLimit(8);
return nn + _letter(nn);
return nn + _letter(nn).toUpperCase();
};

export { randomNIF };

0 comments on commit dced6f7

Please sign in to comment.