Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dni-js

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dni-js - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

package.json
{
"name": "dni-js",
"version": "0.1.0",
"version": "0.1.1",
"description": "Compute and validate a Spanish DNI/NIE number",

@@ -5,0 +5,0 @@ "main": "src/index.js",

# dni-js
Compute and validate a Spanish DNI/NIE numbers.
Compute and validate a Spanish DNI/NIE numbers as described [here](http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie).

@@ -4,0 +4,0 @@ [![Build Status](https://travis-ci.org/albertfdp/dni-js.svg?branch=master)](https://travis-ci.org/albertfdp/dni-js)

const LETTERS = require('./letterMap');
const DNI_REGEXP = /(\d{8})(\s|-)?(\w)/;
const NIE_REGEXP = /([X|Y|Z]\d{7})(\s|-)?(\w)/;
const DNI_REGEXP = /^(\d{8})(\s|-)?(\w)$/;
const NIE_REGEXP = /^([X|Y|Z]\d{7})(\s|-)?(\w)$/;
const DNI_NUMBER_REGEXP = /\d{8}/;
const NIE_NUMBER_REGEXP = /([X|Y|Z]\d{7})/;
const DNI_NUMBER_REGEXP = /^\d{8}$/;
const NIE_NUMBER_REGEXP = /^([X|Y|Z]\d{7})$/;

@@ -9,0 +9,0 @@ const dni = number => {

@@ -1,5 +0,17 @@

const expect = require('unexpected').clone();
const unexpected = require('unexpected');
const { dni, nie, isNIE, getControlDigit, isValid } = require('.');
const expect = unexpected
.clone()
.addAssertion(['<any> [not] to be a valid DNI'], (expect, subject) =>
expect(isValid(subject), '[not] to be', true)
)
.addAssertion(
['<any> [not] to have control digit <string>'],
(expect, subject, value) => {
return expect(getControlDigit(subject), '[not] to equal', value);
}
);
describe('dni-js', () => {

@@ -11,4 +23,9 @@ describe('dni', () => {

});
describe('when passing an invalid number', () => {
it('returns null if DNI contains extra chars', () => {
expect(dni('12345678FFF'), 'to equal', null);
expect(dni('X1234567FFF'), 'to equal', null);
});
it('returns null', () => {

@@ -20,3 +37,3 @@ expect(dni(), 'to equal', null);

});
})
});
});

@@ -33,3 +50,3 @@

it(`returns true for valid number ${number}`, () => {
expect(isValid(number), 'to be true');
expect(number, 'to be a valid DNI');
});

@@ -50,3 +67,3 @@ });

it(`returns false for invalid number ${number}`, () => {
expect(isValid(number), 'to be false');
expect(number, 'not to be a valid DNI');
});

@@ -58,7 +75,7 @@ });

it('when passing an integer returns Z', () => {
expect(getControlDigit(12345678), 'to equal', 'Z');
expect(12345678, 'to have control digit', 'Z');
});
it('when passing a string returns Z', () => {
expect(getControlDigit('12345678'), 'to equal', 'Z');
expect('12345678', 'to have control digit', 'Z');
});

@@ -68,3 +85,3 @@

it('when passing an integer returns Z', () => {
expect(getControlDigit('X1234567'), 'to equal', 'L');
expect('X1234567', 'to have control digit', 'L');
});

@@ -71,0 +88,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc