better-dni
The fastest Spanish DNI (NIE / NIF) validation out there.
Last updated 21 days ago by singuerinc .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install better-dni 
SYNC missed versions from official npm registry.

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

Better DNI

The fastest Spanish DNI (NIE / NIF) validation out there.

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 && yarn build && yarn benchmark

isValid

lib method operations/sec
better-dni #isValid 10,128,148 3.5x faster
dni-js-validator #isValid 2,870,822
dni-js #isValid 2,448,090
@willowi/validate-nif #validateNif 683,573

ctrlChar / getLetter

lib method operations/sec
better-dni #ctrlChar 10,874,568 5.3x faster
dni-js #getLetter 2,032,845
dni-js-validator no method -
@willowi/validate-nif no method -

Benchmark on a MacBook Pro (Retina, 13-inch, Early 2015) - 3,1 GHz Intel Core i7 - 16 GB 1867 MHz DDR3 / Node v10.2.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

Current Tags

  • 4.0.9                                ...           latest (21 days ago)

45 Versions

  • 4.0.9                                ...           21 days ago
  • 4.0.8                                ...           21 days ago
  • 4.0.7                                ...           21 days ago
  • 4.0.6                                ...           21 days ago
  • 4.0.5                                ...           21 days ago
  • 4.0.1                                ...           a month ago
  • 4.0.0                                ...           4 months ago
  • 3.0.9                                ...           4 months ago
  • 3.0.8                                ...           4 months ago
  • 3.0.7                                ...           4 months ago
  • 3.0.6                                ...           7 months ago
  • 3.0.5                                ...           9 months ago
  • 3.0.4                                ...           9 months ago
  • 3.0.3                                ...           a year ago
  • 3.0.2                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.1                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 1.12.0                                ...           2 years ago
  • 1.11.2                                ...           2 years ago
  • 1.11.1                                ...           2 years ago
  • 1.11.0                                ...           2 years ago
  • 1.10.0                                ...           2 years ago
  • 1.9.1                                ...           2 years ago
  • 1.9.0                                ...           2 years ago
  • 1.8.1                                ...           2 years ago
  • 1.8.0                                ...           2 years ago
  • 1.7.3                                ...           2 years ago
  • 1.7.2                                ...           2 years ago
  • 1.7.1                                ...           2 years ago
  • 1.7.0                                ...           2 years ago
  • 1.6.0                                ...           2 years ago
  • 1.5.0                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 88
Last Day 0
Last Week 0
Last Month 23
Dependencies (0)
None
Dev Dependencies (13)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |