All Projects → singuerinc → better-dni

singuerinc / better-dni

Licence: MIT license
The fastest Spanish DNI (NIE / NIF) validation out there.

Programming Languages

typescript
32286 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
shell
77523 projects

Projects that are alternatives of or similar to better-dni

peru-consult-api
API de Consulta de DNI y RUC - Perú (Docker, GraphQL)
Stars: ✭ 57 (+147.83%)
Mutual labels:  dni
franz
A Kafka client library for Erlang/Elixir based on librdkafka implemented as a safe Rust NIF.
Stars: ✭ 30 (+30.43%)
Mutual labels:  nif
Rustler
Safe Rust bridge for creating Erlang NIF functions
Stars: ✭ 3,052 (+13169.57%)
Mutual labels:  nif
hyperbeam
Experimental NIF-based HTTP Server for the BEAM
Stars: ✭ 22 (-4.35%)
Mutual labels:  nif
gerlang
Calling Go functions from Erlang
Stars: ✭ 26 (+13.04%)
Mutual labels:  nif
eapa
Erlang/Elixir Arbitrary-Precision Arithmetic (EAPA)
Stars: ✭ 36 (+56.52%)
Mutual labels:  nif
UIX-R
Ultima IX: Redemption for Morrowind and OpenMW
Stars: ✭ 32 (+39.13%)
Mutual labels:  nif
webview
Build cross platform desktop apps with Elixir and web technologies.
Stars: ✭ 18 (-21.74%)
Mutual labels:  nif
exor filter
Erlang nif for xor_filter. 'Faster and Smaller Than Bloom and Cuckoo Filters'.
Stars: ✭ 29 (+26.09%)
Mutual labels:  nif
billy
An opensource invoicing engine --
Stars: ✭ 28 (+21.74%)
Mutual labels:  spain
espana
Free open public domain football data (football.db) for España (Spain) / Europe - Primera División / La Liga, etc.
Stars: ✭ 64 (+178.26%)
Mutual labels:  spain
sgrnn
Tensorflow implementation of Synthetic Gradient for RNN (LSTM)
Stars: ✭ 40 (+73.91%)
Mutual labels:  dni
peru-consult
Consulta libre de RUC y DNI
Stars: ✭ 97 (+321.74%)
Mutual labels:  dni

npm Codacy grade Build Coveralls github Known Vulnerabilities npm bundle size (minified)

Better DNI

The fastest Spanish DNI (NIE / NIF) validation out there — And lighter: 660 bytes.

Installation

// npm
npm i better-dni

// yarn
yarn add better-dni

Usage

isValid / isNIF / isNIE / ctrlChar

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'

Generators

NIF

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'

NIE

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'

Normalize

// Returns a "clean" dni string removing spaces, dashes, etc.
normalize(" x-9464186_p   "); // => "X9464186P"

Benchmark

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

isValid

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

ctrlChar / getLetter

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

Demo

https://better-dni.singuerinc.com/

Related

Reference

http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].