Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
better-dni
Advanced tools
The fastest Spanish DNI (NIE / NIF) validation out there — And lighter: 660 bytes.
// npm
npm i better-dni
// yarn
yarn add better-dni
import { isValid, isNIF, isNIE, ctrlChar } from "better-dni";
// validates any type of DNI (NIE or NIF)
isValid("Z7662566Y"); //=> true
// checks if it is a valid NIF
isNIF("06672804K"); //=> true
// checks if it is a valid NIE
isNIE("X1302311M"); //=> true
// returns the control letter in upper case
ctrlChar("X1302311M"); //=> 'M'
ctrlChar("X1302311"); //=> 'M'
import { randomNIF, randomNIFWith } from "better-dni";
randomNIF(); //=> '31719111H'
// returns a valid random NIF given the control letter
randomNIFWith("C"); // => '95652190C'
// a seed (Number) can be provided and it will always return the same result
randomNIFWith("G", 1); //=> '95652174G'
randomNIFWith("G", 1); //=> '95652174G'
import { randomNIE, randomNIEWith } from "better-dni";
randomNIE(); //=> 'X1120409X'
// returns a valid random NIE given the first and control letter
randomNIEWith("Y", "C"); //=> 'Y2098020C'
randomNIEWith("Z", "G"); //=> 'Z5670557G'
// a seed (Number) can be provided and it will always return the same result
randomNIEWith("X", "E", 1); //=> 'X2080280E'
randomNIEWith("X", "E", 1); //=> 'X2080280E'
// Returns a "clean" dni string removing spaces, dashes, etc.
normalize(" x-9464186_p "); // => "X9464186P"
better-dni
does a similar job as other libraries like dni-js, dni-js-validator, and @willowi/validate-nif but better-dni
is built with optimization and speed in mind. Take a look at these benchmark results:
yarn run benchmark
lib | method | time | diff |
---|---|---|---|
better-dni | #isValid | 896 ms | |
dni-js-validator | #isValid | 2550 ms | x2.85 slower |
dni-js | #isValid | 2630 ms | x2.94 slower |
@willowi/validate-nif | #validateNif | 11000 ms | x12.27 slower |
lib | method | time | diff |
---|---|---|---|
better-dni | #ctrlChar | 859 ms | |
dni-js | #getLetter | 2190 ms | x2.55 slower |
dni-js-validator | no method | - | |
@willowi/validate-nif | no method | - |
Benchmark on a MacBook Pro (16-inch, 2019) - 2,6 GHz 6-Core Intel Core i7 - 16 GB 2667 MHz DDR4 / Node v14.15.1
https://better-dni.singuerinc.com/
http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie
FAQs
The fastest Spanish DNI (NIE / NIF) validation out there.
The npm package better-dni receives a total of 5,179 weekly downloads. As such, better-dni popularity was classified as popular.
We found that better-dni demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.