Skip to content

Commit

Permalink
release: 1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
singuerinc committed May 24, 2018
1 parent aae4566 commit 61f83fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions index.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
(factory());
}(this, (function () { 'use strict';

const addControlChar = x => x + 'TRWAGMYFPDXBNJZSQVHLCKET'[+x % 23];
const letter = x => 'TRWAGMYFPDXBNJZSQVHLCKET'[+x % 23];
const add = (acc, x) => acc + x;
const sum = numbers => numbers.reduce(add, 0);
const randStrLimit = limit => ('' + Math.random()).substr(-limit);

/**
* Returns a valid NIF string
Expand All @@ -13,9 +16,8 @@
* randomNIF() // => "93375221M"
*/
const randomNIF = () => {
const nif = rn => ('' + rn).substr(-8);
const rn = Math.random();
return addControlChar(nif(rn));
const nn = randStrLimit(8);
return nn + letter(sum(nn.split('')));
};

/**
Expand All @@ -25,11 +27,9 @@
* randomNIE() // => "X4108613P"
*/
const randomNIE = () => {
const firstNIEChar = i => ['X', 'Y', 'Z'][i];
const nif = rn => ('' + rn).substr(-7);
const rn = Math.random();
const r = Math.floor(rn * 3);
return firstNIEChar(r) + addControlChar(nif(rn));
const r = Math.floor(Math.random() * 3);
const nn = randStrLimit(7);
return ['X', 'Y', 'Z'][r] + nn + letter(sum([r, ...nn.split('')]));
};

const _isNIE = v => /^[XYZ]{1}[0-9]{7}[trwagmyfpdxbnjzsqvhlcket]{1}$/i.test(v);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "better-dni",
"version": "1.8.0",
"version": "1.8.1",
"description": "Spanish DNI (NIE / NIF) validation",
"main": "index.min.js",
"license": "MIT",
Expand Down

0 comments on commit 61f83fc

Please sign in to comment.