validator-tax-id 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -9
- package/dist/index.cjs +59 -8
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +59 -8
- package/dist/validators/es.cjs +31 -0
- package/dist/validators/es.d.cts +36 -0
- package/dist/validators/es.d.ts +36 -0
- package/dist/validators/es.js +31 -0
- package/dist/validators/fr.cjs +38 -0
- package/dist/validators/fr.d.cts +46 -0
- package/dist/validators/fr.d.ts +46 -0
- package/dist/validators/fr.js +38 -0
- package/dist/validators/pt.cjs +9 -0
- package/dist/validators/pt.d.cts +18 -0
- package/dist/validators/pt.d.ts +18 -0
- package/dist/validators/pt.js +9 -0
- package/package.json +16 -1
- package/dist/index.global.js +0 -33
package/README.md
CHANGED
|
@@ -36,19 +36,60 @@ The main function `validateIdentification` takes two arguments: the **country co
|
|
|
36
36
|
import { validateIdentification } from "validator-tax-id";
|
|
37
37
|
|
|
38
38
|
// 🇪🇸 Spain (ES)
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Validates NIE (X/Y/Z + 7 digits + letter)
|
|
43
|
-
const isNieValid = validateIdentification("es", "X1234567L"); // true
|
|
39
|
+
validateIdentification("es", "12345678Z"); // true (DNI)
|
|
40
|
+
validateIdentification("es", "X1234567L"); // true (NIE)
|
|
41
|
+
validateIdentification("es", "A58818501"); // true (CIF)
|
|
44
42
|
|
|
45
43
|
// 🇵🇹 Portugal (PT)
|
|
46
|
-
//
|
|
47
|
-
const isNifValid = validateIdentification("pt", "232013969"); // true
|
|
44
|
+
validateIdentification("pt", "232013969"); // true (NIF)
|
|
48
45
|
|
|
49
46
|
// 🇫🇷 France (FR)
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
validateIdentification("fr", "443061841"); // true (SIREN)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Individual Validators (Recommended) ✨
|
|
51
|
+
|
|
52
|
+
For better tree-shaking and direct access, use individual validators:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import {
|
|
56
|
+
// Spain
|
|
57
|
+
validateDNI,
|
|
58
|
+
validateNIE,
|
|
59
|
+
validateCIF,
|
|
60
|
+
// France
|
|
61
|
+
validateSIREN,
|
|
62
|
+
validateSIRET,
|
|
63
|
+
validateNIR,
|
|
64
|
+
// Portugal
|
|
65
|
+
validateNIF,
|
|
66
|
+
} from "validator-tax-id";
|
|
67
|
+
|
|
68
|
+
// 🇪🇸 Spain - Direct validation
|
|
69
|
+
validateDNI("12345678Z"); // true
|
|
70
|
+
validateNIE("X1234567L"); // true
|
|
71
|
+
validateCIF("A58818501"); // true
|
|
72
|
+
|
|
73
|
+
// 🇫🇷 France - Direct validation
|
|
74
|
+
validateSIREN("443061841"); // true
|
|
75
|
+
validateSIRET("44306184100047"); // true
|
|
76
|
+
validateNIR("188057512301180"); // true
|
|
77
|
+
|
|
78
|
+
// 🇵🇹 Portugal - Direct validation
|
|
79
|
+
validateNIF("123456789"); // true
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Country Auto-detect
|
|
83
|
+
|
|
84
|
+
If you don't know the specific document type:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { validateES, validateFR, validatePT } from "validator-tax-id";
|
|
88
|
+
|
|
89
|
+
validateES("12345678Z"); // true (auto-detects DNI)
|
|
90
|
+
validateES("A58818501"); // true (auto-detects CIF)
|
|
91
|
+
validateFR("443061841"); // true (auto-detects SIREN)
|
|
92
|
+
validatePT("123456789"); // true
|
|
52
93
|
```
|
|
53
94
|
|
|
54
95
|
## API Reference
|
|
@@ -73,6 +114,17 @@ _Note: The validator sanitizes the input automatically (removes spaces, hyphens,
|
|
|
73
114
|
|
|
74
115
|
All notable changes to this project will be documented in this file.
|
|
75
116
|
|
|
117
|
+
## [1.2.0] - 2026-01-19
|
|
118
|
+
|
|
119
|
+
### Added 🚀
|
|
120
|
+
|
|
121
|
+
- **Individual Validators**: New exported functions for direct validation:
|
|
122
|
+
- Spain: `validateDNI`, `validateNIE`, `validateCIF`, `validateES`
|
|
123
|
+
- France: `validateSIREN`, `validateSIRET`, `validateNIR`, `validateFR`
|
|
124
|
+
- Portugal: `validateNIF`, `validatePT`
|
|
125
|
+
- Better tree-shaking support with individual exports
|
|
126
|
+
- Country auto-detect validators (`validateES`, `validateFR`, `validatePT`)
|
|
127
|
+
|
|
76
128
|
## [1.1.3] - 2026-01-18
|
|
77
129
|
|
|
78
130
|
### Added 🚀
|
package/dist/index.cjs
CHANGED
|
@@ -1,24 +1,75 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var r in t)f(e,r,{get:t[r],enumerable:!0})},A=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of F(t))!_.call(e,n)&&n!==r&&f(e,n,{get:()=>t[n],enumerable:!(s=T(t,n))||s.enumerable});return e};var $=e=>A(f({},"__esModule",{value:!0}),e);var H={};D(H,{validateCIF:()=>u,validateDNI:()=>p,validateES:()=>I,validateFR:()=>R,validateIdentification:()=>Z,validateNIE:()=>d,validateNIF:()=>N,validateNIR:()=>g,validatePT:()=>b,validateSIREN:()=>E,validateSIRET:()=>y});module.exports=$(H);var x="TRWAGMYFPDXBNJZSQVHLCKE",h="JABCDEFGHI",G=/^[0-9]{8}[A-Z]$/,L=/^[XYZ][0-9]{7}[A-Z]$/,B=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/;var p=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!G.test(t))return!1;let r=t.slice(0,-1),s=t.slice(-1),n=parseInt(r,10);return x[n%23]===s};var d=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!L.test(t))return!1;let r=t.slice(0,-1),s=t.slice(-1);r=r.replace("X","0").replace("Y","1").replace("Z","2");let n=parseInt(r,10);return x[n%23]===s};var u=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!B.test(t))return!1;let r=t[0],s=t.slice(1,8),n=t[8],o=0,l=0;for(let i=0;i<s.length;i++){let v=parseInt(s[i],10);if(i%2===0){let c=v*2;l+=c>9?c-9:c}else o+=v}let a=(10-(o+l)%10)%10,S=h[a];return"PQRSNW".includes(r)?n===S:"ABEH".includes(r)?n===String(a):n===String(a)||n===S};var I=e=>p(e)||d(e)||u(e);var P=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/,C=e=>{let t=0,r=!1;for(let s=e.length-1;s>=0;s--){let n=parseInt(e[s],10);r&&(n*=2,n>9&&(n-=9)),t+=n,r=!r}return t%10===0};var g=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!P.test(t))return!1;let r=parseInt(t.slice(-2),10),s=t.slice(0,-2),n=s.slice(5,7);n==="2A"&&(s=s.slice(0,5)+"19"+s.slice(7)),n==="2B"&&(s=s.slice(0,5)+"18"+s.slice(7));let o=BigInt(s);return Number(97n-o%97n)===r};var E=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");return!/^\d{9}$/.test(t)||/^(\d)\1+$/.test(t)?!1:C(t)};var y=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");return!/^\d{14}$/.test(t)||/^(\d)\1+$/.test(t)?!1:C(t)};var R=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");return t.length===15?g(e):t.length===9?E(e):t.length===14?y(e):!1};var X=["1","2","3","5","6","8","9"];var N=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");if(!/^[0-9]{9}$/.test(t)||!X.includes(t[0]))return!1;let n=11-t.slice(0,8).split("").reduce((o,l,m)=>{let a=9-m;return o+parseInt(l,10)*a},0)%11;return n>=10&&(n=0),n===parseInt(t[8],10)},b=N;var U={es:I,pt:b,fr:R};var Z=(e,t)=>{let r=U[e];return r?r(t):(console.warn(`[TaxIDValidator] Country '${e}' not supported yet.`),!1)};0&&(module.exports={validateCIF,validateDNI,validateES,validateFR,validateIdentification,validateNIE,validateNIF,validateNIR,validatePT,validateSIREN,validateSIRET});
|
|
2
2
|
/**
|
|
3
|
-
* Validate Spanish DNI
|
|
4
|
-
* @param value - The DNI
|
|
5
|
-
* @returns boolean indicating whether the DNI
|
|
3
|
+
* Validate Spanish DNI (Documento Nacional de Identidad).
|
|
4
|
+
* @param value - The DNI number to validate (8 digits + letter)
|
|
5
|
+
* @returns boolean indicating whether the DNI is valid
|
|
6
6
|
* @author AngelBlanco97
|
|
7
7
|
* @license MIT
|
|
8
8
|
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Validate Spanish NIE (Número de Identidad de Extranjero).
|
|
12
|
+
* @param value - The NIE number to validate (X/Y/Z + 7 digits + letter)
|
|
13
|
+
* @returns boolean indicating whether the NIE is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Validate Spanish CIF (Código de Identificación Fiscal).
|
|
20
|
+
* @param value - The CIF number to validate (letter + 7 digits + control)
|
|
21
|
+
* @returns boolean indicating whether the CIF is valid
|
|
22
|
+
* @author AngelBlanco97
|
|
23
|
+
* @license MIT
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Validate Spanish DNI/NIE/CIF numbers (auto-detect type).
|
|
12
27
|
* @param value - The identification number to validate
|
|
13
|
-
* @returns boolean indicating whether the identification
|
|
28
|
+
* @returns boolean indicating whether the identification is valid
|
|
29
|
+
* @author AngelBlanco97
|
|
30
|
+
* @license MIT
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Validate French NIR (Numéro d'Inscription au Répertoire) - Social Security Number.
|
|
34
|
+
* @param value - The NIR number to validate (15 digits)
|
|
35
|
+
* @returns boolean indicating whether the NIR is valid
|
|
36
|
+
* @author AngelBlanco97
|
|
37
|
+
* @license MIT
|
|
38
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Validate French SIREN (Système d'Identification du Répertoire des Entreprises).
|
|
42
|
+
* @param value - The SIREN number to validate (9 digits)
|
|
43
|
+
* @returns boolean indicating whether the SIREN is valid
|
|
44
|
+
* @author AngelBlanco97
|
|
45
|
+
* @license MIT
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Validate French SIRET (Système d'Identification du Répertoire des Établissements).
|
|
49
|
+
* @param value - The SIRET number to validate (14 digits = SIREN + NIC)
|
|
50
|
+
* @returns boolean indicating whether the SIRET is valid
|
|
51
|
+
* @author AngelBlanco97
|
|
52
|
+
* @license MIT
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Validate French SIREN or SIRET numbers (auto-detect by length).
|
|
56
|
+
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
57
|
+
* @returns boolean indicating whether the number is valid
|
|
58
|
+
* @author AngelBlanco97
|
|
59
|
+
* @license MIT
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Validates French identification numbers: NIR, SIREN, and SIRET (auto-detect).
|
|
63
|
+
* @param value - The identification number to validate
|
|
64
|
+
* @returns boolean indicating whether the identification number is valid
|
|
14
65
|
* @author AngelBlanco97
|
|
15
66
|
* @license MIT
|
|
16
67
|
* @documentation https://www.service-public.gouv.fr/
|
|
17
68
|
*/
|
|
18
69
|
/**
|
|
19
70
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
20
|
-
* @param value - The NIF number to validate
|
|
21
|
-
* @returns boolean indicating whether the NIF is valid
|
|
71
|
+
* @param value - The NIF number to validate (9 digits)
|
|
72
|
+
* @returns boolean indicating whether the NIF is valid
|
|
22
73
|
* @author AngelBlanco97
|
|
23
74
|
* @license MIT
|
|
24
75
|
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { validateCIF, validateDNI, validateES, validateNIE } from './validators/es.cjs';
|
|
2
|
+
export { validateFR, validateNIR, validateSIREN, validateSIRET } from './validators/fr.cjs';
|
|
3
|
+
export { validateNIF, validatePT } from './validators/pt.cjs';
|
|
4
|
+
|
|
1
5
|
declare const validators: {
|
|
2
6
|
es: (value: any) => boolean;
|
|
3
7
|
pt: (value: any) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { validateCIF, validateDNI, validateES, validateNIE } from './validators/es.js';
|
|
2
|
+
export { validateFR, validateNIR, validateSIREN, validateSIRET } from './validators/fr.js';
|
|
3
|
+
export { validateNIF, validatePT } from './validators/pt.js';
|
|
4
|
+
|
|
1
5
|
declare const validators: {
|
|
2
6
|
es: (value: any) => boolean;
|
|
3
7
|
pt: (value: any) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,75 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u="TRWAGMYFPDXBNJZSQVHLCKE",C="JABCDEFGHI",T=/^[0-9]{8}[A-Z]$/,F=/^[XYZ][0-9]{7}[A-Z]$/,_=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/;var I=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!T.test(t))return!1;let s=t.slice(0,-1),n=t.slice(-1),r=parseInt(s,10);return u[r%23]===n};var g=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!F.test(t))return!1;let s=t.slice(0,-1),n=t.slice(-1);s=s.replace("X","0").replace("Y","1").replace("Z","2");let r=parseInt(s,10);return u[r%23]===n};var E=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!_.test(t))return!1;let s=t[0],n=t.slice(1,8),r=t[8],o=0,l=0;for(let i=0;i<n.length;i++){let d=parseInt(n[i],10);if(i%2===0){let c=d*2;l+=c>9?c-9:c}else o+=d}let a=(10-(o+l)%10)%10,p=C[a];return"PQRSNW".includes(s)?r===p:"ABEH".includes(s)?r===String(a):r===String(a)||r===p};var y=e=>I(e)||g(e)||E(e);var D=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/,R=e=>{let t=0,s=!1;for(let n=e.length-1;n>=0;n--){let r=parseInt(e[n],10);s&&(r*=2,r>9&&(r-=9)),t+=r,s=!s}return t%10===0};var N=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!D.test(t))return!1;let s=parseInt(t.slice(-2),10),n=t.slice(0,-2),r=n.slice(5,7);r==="2A"&&(n=n.slice(0,5)+"19"+n.slice(7)),r==="2B"&&(n=n.slice(0,5)+"18"+n.slice(7));let o=BigInt(n);return Number(97n-o%97n)===s};var b=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");return!/^\d{9}$/.test(t)||/^(\d)\1+$/.test(t)?!1:R(t)};var m=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");return!/^\d{14}$/.test(t)||/^(\d)\1+$/.test(t)?!1:R(t)};var S=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");return t.length===15?N(e):t.length===9?b(e):t.length===14?m(e):!1};var A=["1","2","3","5","6","8","9"];var v=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");if(!/^[0-9]{9}$/.test(t)||!A.includes(t[0]))return!1;let r=11-t.slice(0,8).split("").reduce((o,l,f)=>{let a=9-f;return o+parseInt(l,10)*a},0)%11;return r>=10&&(r=0),r===parseInt(t[8],10)},x=v;var $={es:y,pt:x,fr:S};var U=(e,t)=>{let s=$[e];return s?s(t):(console.warn(`[TaxIDValidator] Country '${e}' not supported yet.`),!1)};export{E as validateCIF,I as validateDNI,y as validateES,S as validateFR,U as validateIdentification,g as validateNIE,v as validateNIF,N as validateNIR,x as validatePT,b as validateSIREN,m as validateSIRET};
|
|
2
2
|
/**
|
|
3
|
-
* Validate Spanish DNI
|
|
4
|
-
* @param value - The DNI
|
|
5
|
-
* @returns boolean indicating whether the DNI
|
|
3
|
+
* Validate Spanish DNI (Documento Nacional de Identidad).
|
|
4
|
+
* @param value - The DNI number to validate (8 digits + letter)
|
|
5
|
+
* @returns boolean indicating whether the DNI is valid
|
|
6
6
|
* @author AngelBlanco97
|
|
7
7
|
* @license MIT
|
|
8
8
|
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Validate Spanish NIE (Número de Identidad de Extranjero).
|
|
12
|
+
* @param value - The NIE number to validate (X/Y/Z + 7 digits + letter)
|
|
13
|
+
* @returns boolean indicating whether the NIE is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Validate Spanish CIF (Código de Identificación Fiscal).
|
|
20
|
+
* @param value - The CIF number to validate (letter + 7 digits + control)
|
|
21
|
+
* @returns boolean indicating whether the CIF is valid
|
|
22
|
+
* @author AngelBlanco97
|
|
23
|
+
* @license MIT
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Validate Spanish DNI/NIE/CIF numbers (auto-detect type).
|
|
12
27
|
* @param value - The identification number to validate
|
|
13
|
-
* @returns boolean indicating whether the identification
|
|
28
|
+
* @returns boolean indicating whether the identification is valid
|
|
29
|
+
* @author AngelBlanco97
|
|
30
|
+
* @license MIT
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Validate French NIR (Numéro d'Inscription au Répertoire) - Social Security Number.
|
|
34
|
+
* @param value - The NIR number to validate (15 digits)
|
|
35
|
+
* @returns boolean indicating whether the NIR is valid
|
|
36
|
+
* @author AngelBlanco97
|
|
37
|
+
* @license MIT
|
|
38
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Validate French SIREN (Système d'Identification du Répertoire des Entreprises).
|
|
42
|
+
* @param value - The SIREN number to validate (9 digits)
|
|
43
|
+
* @returns boolean indicating whether the SIREN is valid
|
|
44
|
+
* @author AngelBlanco97
|
|
45
|
+
* @license MIT
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Validate French SIRET (Système d'Identification du Répertoire des Établissements).
|
|
49
|
+
* @param value - The SIRET number to validate (14 digits = SIREN + NIC)
|
|
50
|
+
* @returns boolean indicating whether the SIRET is valid
|
|
51
|
+
* @author AngelBlanco97
|
|
52
|
+
* @license MIT
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Validate French SIREN or SIRET numbers (auto-detect by length).
|
|
56
|
+
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
57
|
+
* @returns boolean indicating whether the number is valid
|
|
58
|
+
* @author AngelBlanco97
|
|
59
|
+
* @license MIT
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Validates French identification numbers: NIR, SIREN, and SIRET (auto-detect).
|
|
63
|
+
* @param value - The identification number to validate
|
|
64
|
+
* @returns boolean indicating whether the identification number is valid
|
|
14
65
|
* @author AngelBlanco97
|
|
15
66
|
* @license MIT
|
|
16
67
|
* @documentation https://www.service-public.gouv.fr/
|
|
17
68
|
*/
|
|
18
69
|
/**
|
|
19
70
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
20
|
-
* @param value - The NIF number to validate
|
|
21
|
-
* @returns boolean indicating whether the NIF is valid
|
|
71
|
+
* @param value - The NIF number to validate (9 digits)
|
|
72
|
+
* @returns boolean indicating whether the NIF is valid
|
|
22
73
|
* @author AngelBlanco97
|
|
23
74
|
* @license MIT
|
|
24
75
|
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var R=(e,t)=>{for(var r in t)a(e,r,{get:t[r],enumerable:!0})},S=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of C(t))!N.call(e,n)&&n!==r&&a(e,n,{get:()=>t[n],enumerable:!(s=g(t,n))||s.enumerable});return e};var m=e=>S(a({},"__esModule",{value:!0}),e);var L={};R(L,{validateCIF:()=>d,validateDNI:()=>I,validateES:()=>G,validateNIE:()=>b});module.exports=m(L);var u="TRWAGMYFPDXBNJZSQVHLCKE",y="JABCDEFGHI",A=/^[0-9]{8}[A-Z]$/,D=/^[XYZ][0-9]{7}[A-Z]$/,F=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/;var I=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!A.test(t))return!1;let r=t.slice(0,-1),s=t.slice(-1),n=parseInt(r,10);return u[n%23]===s};var b=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!D.test(t))return!1;let r=t.slice(0,-1),s=t.slice(-1);r=r.replace("X","0").replace("Y","1").replace("Z","2");let n=parseInt(r,10);return u[n%23]===s};var d=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(!F.test(t))return!1;let r=t[0],s=t.slice(1,8),n=t[8],i=0,p=0;for(let o=0;o<s.length;o++){let E=parseInt(s[o],10);if(o%2===0){let l=E*2;p+=l>9?l-9:l}else i+=E}let c=(10-(i+p)%10)%10,f=y[c];return"PQRSNW".includes(r)?n===f:"ABEH".includes(r)?n===String(c):n===String(c)||n===f};var G=e=>I(e)||b(e)||d(e);0&&(module.exports={validateCIF,validateDNI,validateES,validateNIE});
|
|
2
|
+
/**
|
|
3
|
+
* Validate Spanish DNI (Documento Nacional de Identidad).
|
|
4
|
+
* @param value - The DNI number to validate (8 digits + letter)
|
|
5
|
+
* @returns boolean indicating whether the DNI is valid
|
|
6
|
+
* @author AngelBlanco97
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Validate Spanish NIE (Número de Identidad de Extranjero).
|
|
12
|
+
* @param value - The NIE number to validate (X/Y/Z + 7 digits + letter)
|
|
13
|
+
* @returns boolean indicating whether the NIE is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Validate Spanish CIF (Código de Identificación Fiscal).
|
|
20
|
+
* @param value - The CIF number to validate (letter + 7 digits + control)
|
|
21
|
+
* @returns boolean indicating whether the CIF is valid
|
|
22
|
+
* @author AngelBlanco97
|
|
23
|
+
* @license MIT
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Validate Spanish DNI/NIE/CIF numbers (auto-detect type).
|
|
27
|
+
* @param value - The identification number to validate
|
|
28
|
+
* @returns boolean indicating whether the identification is valid
|
|
29
|
+
* @author AngelBlanco97
|
|
30
|
+
* @license MIT
|
|
31
|
+
*/
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate Spanish DNI (Documento Nacional de Identidad).
|
|
3
|
+
* @param value - The DNI number to validate (8 digits + letter)
|
|
4
|
+
* @returns boolean indicating whether the DNI is valid
|
|
5
|
+
* @author AngelBlanco97
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
8
|
+
*/
|
|
9
|
+
declare const validateDNI: (value: any) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validate Spanish NIE (Número de Identidad de Extranjero).
|
|
12
|
+
* @param value - The NIE number to validate (X/Y/Z + 7 digits + letter)
|
|
13
|
+
* @returns boolean indicating whether the NIE is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
17
|
+
*/
|
|
18
|
+
declare const validateNIE: (value: any) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Validate Spanish CIF (Código de Identificación Fiscal).
|
|
21
|
+
* @param value - The CIF number to validate (letter + 7 digits + control)
|
|
22
|
+
* @returns boolean indicating whether the CIF is valid
|
|
23
|
+
* @author AngelBlanco97
|
|
24
|
+
* @license MIT
|
|
25
|
+
*/
|
|
26
|
+
declare const validateCIF: (value: any) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Validate Spanish DNI/NIE/CIF numbers (auto-detect type).
|
|
29
|
+
* @param value - The identification number to validate
|
|
30
|
+
* @returns boolean indicating whether the identification is valid
|
|
31
|
+
* @author AngelBlanco97
|
|
32
|
+
* @license MIT
|
|
33
|
+
*/
|
|
34
|
+
declare const validateES: (value: any) => boolean;
|
|
35
|
+
|
|
36
|
+
export { validateCIF, validateDNI, validateES, validateNIE };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate Spanish DNI (Documento Nacional de Identidad).
|
|
3
|
+
* @param value - The DNI number to validate (8 digits + letter)
|
|
4
|
+
* @returns boolean indicating whether the DNI is valid
|
|
5
|
+
* @author AngelBlanco97
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
8
|
+
*/
|
|
9
|
+
declare const validateDNI: (value: any) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validate Spanish NIE (Número de Identidad de Extranjero).
|
|
12
|
+
* @param value - The NIE number to validate (X/Y/Z + 7 digits + letter)
|
|
13
|
+
* @returns boolean indicating whether the NIE is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
17
|
+
*/
|
|
18
|
+
declare const validateNIE: (value: any) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Validate Spanish CIF (Código de Identificación Fiscal).
|
|
21
|
+
* @param value - The CIF number to validate (letter + 7 digits + control)
|
|
22
|
+
* @returns boolean indicating whether the CIF is valid
|
|
23
|
+
* @author AngelBlanco97
|
|
24
|
+
* @license MIT
|
|
25
|
+
*/
|
|
26
|
+
declare const validateCIF: (value: any) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Validate Spanish DNI/NIE/CIF numbers (auto-detect type).
|
|
29
|
+
* @param value - The identification number to validate
|
|
30
|
+
* @returns boolean indicating whether the identification is valid
|
|
31
|
+
* @author AngelBlanco97
|
|
32
|
+
* @license MIT
|
|
33
|
+
*/
|
|
34
|
+
declare const validateES: (value: any) => boolean;
|
|
35
|
+
|
|
36
|
+
export { validateCIF, validateDNI, validateES, validateNIE };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var E="TRWAGMYFPDXBNJZSQVHLCKE",u="JABCDEFGHI",I=/^[0-9]{8}[A-Z]$/,b=/^[XYZ][0-9]{7}[A-Z]$/,d=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/;var g=t=>{if(typeof t!="string")return!1;let e=t.toUpperCase().replace(/\s|-/g,"");if(!I.test(e))return!1;let n=e.slice(0,-1),s=e.slice(-1),r=parseInt(n,10);return E[r%23]===s};var C=t=>{if(typeof t!="string")return!1;let e=t.toUpperCase().replace(/\s|-/g,"");if(!b.test(e))return!1;let n=e.slice(0,-1),s=e.slice(-1);n=n.replace("X","0").replace("Y","1").replace("Z","2");let r=parseInt(n,10);return E[r%23]===s};var N=t=>{if(typeof t!="string")return!1;let e=t.toUpperCase().replace(/\s|-/g,"");if(!d.test(e))return!1;let n=e[0],s=e.slice(1,8),r=e[8],a=0,i=0;for(let o=0;o<s.length;o++){let f=parseInt(s[o],10);if(o%2===0){let l=f*2;i+=l>9?l-9:l}else a+=f}let c=(10-(a+i)%10)%10,p=u[c];return"PQRSNW".includes(n)?r===p:"ABEH".includes(n)?r===String(c):r===String(c)||r===p};var S=t=>g(t)||C(t)||N(t);export{N as validateCIF,g as validateDNI,S as validateES,C as validateNIE};
|
|
2
|
+
/**
|
|
3
|
+
* Validate Spanish DNI (Documento Nacional de Identidad).
|
|
4
|
+
* @param value - The DNI number to validate (8 digits + letter)
|
|
5
|
+
* @returns boolean indicating whether the DNI is valid
|
|
6
|
+
* @author AngelBlanco97
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Validate Spanish NIE (Número de Identidad de Extranjero).
|
|
12
|
+
* @param value - The NIE number to validate (X/Y/Z + 7 digits + letter)
|
|
13
|
+
* @returns boolean indicating whether the NIE is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Validate Spanish CIF (Código de Identificación Fiscal).
|
|
20
|
+
* @param value - The CIF number to validate (letter + 7 digits + control)
|
|
21
|
+
* @returns boolean indicating whether the CIF is valid
|
|
22
|
+
* @author AngelBlanco97
|
|
23
|
+
* @license MIT
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Validate Spanish DNI/NIE/CIF numbers (auto-detect type).
|
|
27
|
+
* @param value - The identification number to validate
|
|
28
|
+
* @returns boolean indicating whether the identification is valid
|
|
29
|
+
* @author AngelBlanco97
|
|
30
|
+
* @license MIT
|
|
31
|
+
*/
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var s in e)o(t,s,{get:e[s],enumerable:!0})},I=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of g(e))!u.call(t,r)&&r!==s&&o(t,r,{get:()=>e[r],enumerable:!(n=d(e,r))||n.enumerable});return t};var y=t=>I(o({},"__esModule",{value:!0}),t);var N={};R(N,{validateFR:()=>E,validateFR_NIR:()=>x,validateFR_SIREN_SIRET:()=>h,validateNIR:()=>i,validateSIREN:()=>l,validateSIREN_SIRET:()=>c,validateSIRET:()=>a});module.exports=y(N);var b=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/,f=t=>{let e=0,s=!1;for(let n=t.length-1;n>=0;n--){let r=parseInt(t[n],10);s&&(r*=2,r>9&&(r-=9)),e+=r,s=!s}return e%10===0};var i=t=>{if(typeof t!="string")return!1;let e=t.toUpperCase().replace(/\s|-/g,"");if(!b.test(e))return!1;let s=parseInt(e.slice(-2),10),n=e.slice(0,-2),r=n.slice(5,7);r==="2A"&&(n=n.slice(0,5)+"19"+n.slice(7)),r==="2B"&&(n=n.slice(0,5)+"18"+n.slice(7));let p=BigInt(n);return Number(97n-p%97n)===s};var l=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s|-/g,"");return!/^\d{9}$/.test(e)||/^(\d)\1+$/.test(e)?!1:f(e)};var a=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s|-/g,"");return!/^\d{14}$/.test(e)||/^(\d)\1+$/.test(e)?!1:f(e)};var c=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s|-/g,"");return e.length===9?l(e):e.length===14?a(e):!1};var E=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s|-/g,"");return e.length===15?i(t):e.length===9?l(t):e.length===14?a(t):!1},h=c,x=i;0&&(module.exports={validateFR,validateFR_NIR,validateFR_SIREN_SIRET,validateNIR,validateSIREN,validateSIREN_SIRET,validateSIRET});
|
|
2
|
+
/**
|
|
3
|
+
* Validate French NIR (Numéro d'Inscription au Répertoire) - Social Security Number.
|
|
4
|
+
* @param value - The NIR number to validate (15 digits)
|
|
5
|
+
* @returns boolean indicating whether the NIR is valid
|
|
6
|
+
* @author AngelBlanco97
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Validate French SIREN (Système d'Identification du Répertoire des Entreprises).
|
|
12
|
+
* @param value - The SIREN number to validate (9 digits)
|
|
13
|
+
* @returns boolean indicating whether the SIREN is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Validate French SIRET (Système d'Identification du Répertoire des Établissements).
|
|
19
|
+
* @param value - The SIRET number to validate (14 digits = SIREN + NIC)
|
|
20
|
+
* @returns boolean indicating whether the SIRET is valid
|
|
21
|
+
* @author AngelBlanco97
|
|
22
|
+
* @license MIT
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Validate French SIREN or SIRET numbers (auto-detect by length).
|
|
26
|
+
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
27
|
+
* @returns boolean indicating whether the number is valid
|
|
28
|
+
* @author AngelBlanco97
|
|
29
|
+
* @license MIT
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Validates French identification numbers: NIR, SIREN, and SIRET (auto-detect).
|
|
33
|
+
* @param value - The identification number to validate
|
|
34
|
+
* @returns boolean indicating whether the identification number is valid
|
|
35
|
+
* @author AngelBlanco97
|
|
36
|
+
* @license MIT
|
|
37
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
38
|
+
*/
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate French NIR (Numéro d'Inscription au Répertoire) - Social Security Number.
|
|
3
|
+
* @param value - The NIR number to validate (15 digits)
|
|
4
|
+
* @returns boolean indicating whether the NIR is valid
|
|
5
|
+
* @author AngelBlanco97
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
8
|
+
*/
|
|
9
|
+
declare const validateNIR: (value: any) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validate French SIREN (Système d'Identification du Répertoire des Entreprises).
|
|
12
|
+
* @param value - The SIREN number to validate (9 digits)
|
|
13
|
+
* @returns boolean indicating whether the SIREN is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
*/
|
|
17
|
+
declare const validateSIREN: (value: any) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Validate French SIRET (Système d'Identification du Répertoire des Établissements).
|
|
20
|
+
* @param value - The SIRET number to validate (14 digits = SIREN + NIC)
|
|
21
|
+
* @returns boolean indicating whether the SIRET is valid
|
|
22
|
+
* @author AngelBlanco97
|
|
23
|
+
* @license MIT
|
|
24
|
+
*/
|
|
25
|
+
declare const validateSIRET: (value: any) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Validate French SIREN or SIRET numbers (auto-detect by length).
|
|
28
|
+
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
29
|
+
* @returns boolean indicating whether the number is valid
|
|
30
|
+
* @author AngelBlanco97
|
|
31
|
+
* @license MIT
|
|
32
|
+
*/
|
|
33
|
+
declare const validateSIREN_SIRET: (value: any) => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Validates French identification numbers: NIR, SIREN, and SIRET (auto-detect).
|
|
36
|
+
* @param value - The identification number to validate
|
|
37
|
+
* @returns boolean indicating whether the identification number is valid
|
|
38
|
+
* @author AngelBlanco97
|
|
39
|
+
* @license MIT
|
|
40
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
41
|
+
*/
|
|
42
|
+
declare const validateFR: (value: any) => boolean;
|
|
43
|
+
declare const validateFR_SIREN_SIRET: (value: any) => boolean;
|
|
44
|
+
declare const validateFR_NIR: (value: any) => boolean;
|
|
45
|
+
|
|
46
|
+
export { validateFR, validateFR_NIR, validateFR_SIREN_SIRET, validateNIR, validateSIREN, validateSIREN_SIRET, validateSIRET };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate French NIR (Numéro d'Inscription au Répertoire) - Social Security Number.
|
|
3
|
+
* @param value - The NIR number to validate (15 digits)
|
|
4
|
+
* @returns boolean indicating whether the NIR is valid
|
|
5
|
+
* @author AngelBlanco97
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
8
|
+
*/
|
|
9
|
+
declare const validateNIR: (value: any) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validate French SIREN (Système d'Identification du Répertoire des Entreprises).
|
|
12
|
+
* @param value - The SIREN number to validate (9 digits)
|
|
13
|
+
* @returns boolean indicating whether the SIREN is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
*/
|
|
17
|
+
declare const validateSIREN: (value: any) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Validate French SIRET (Système d'Identification du Répertoire des Établissements).
|
|
20
|
+
* @param value - The SIRET number to validate (14 digits = SIREN + NIC)
|
|
21
|
+
* @returns boolean indicating whether the SIRET is valid
|
|
22
|
+
* @author AngelBlanco97
|
|
23
|
+
* @license MIT
|
|
24
|
+
*/
|
|
25
|
+
declare const validateSIRET: (value: any) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Validate French SIREN or SIRET numbers (auto-detect by length).
|
|
28
|
+
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
29
|
+
* @returns boolean indicating whether the number is valid
|
|
30
|
+
* @author AngelBlanco97
|
|
31
|
+
* @license MIT
|
|
32
|
+
*/
|
|
33
|
+
declare const validateSIREN_SIRET: (value: any) => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Validates French identification numbers: NIR, SIREN, and SIRET (auto-detect).
|
|
36
|
+
* @param value - The identification number to validate
|
|
37
|
+
* @returns boolean indicating whether the identification number is valid
|
|
38
|
+
* @author AngelBlanco97
|
|
39
|
+
* @license MIT
|
|
40
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
41
|
+
*/
|
|
42
|
+
declare const validateFR: (value: any) => boolean;
|
|
43
|
+
declare const validateFR_SIREN_SIRET: (value: any) => boolean;
|
|
44
|
+
declare const validateFR_NIR: (value: any) => boolean;
|
|
45
|
+
|
|
46
|
+
export { validateFR, validateFR_NIR, validateFR_SIREN_SIRET, validateNIR, validateSIREN, validateSIREN_SIRET, validateSIRET };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var c=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/,o=t=>{let e=0,s=!1;for(let n=t.length-1;n>=0;n--){let r=parseInt(t[n],10);s&&(r*=2,r>9&&(r-=9)),e+=r,s=!s}return e%10===0};var i=t=>{if(typeof t!="string")return!1;let e=t.toUpperCase().replace(/\s|-/g,"");if(!c.test(e))return!1;let s=parseInt(e.slice(-2),10),n=e.slice(0,-2),r=n.slice(5,7);r==="2A"&&(n=n.slice(0,5)+"19"+n.slice(7)),r==="2B"&&(n=n.slice(0,5)+"18"+n.slice(7));let f=BigInt(n);return Number(97n-f%97n)===s};var l=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s|-/g,"");return!/^\d{9}$/.test(e)||/^(\d)\1+$/.test(e)?!1:o(e)};var a=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s|-/g,"");return!/^\d{14}$/.test(e)||/^(\d)\1+$/.test(e)?!1:o(e)};var p=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s|-/g,"");return e.length===9?l(e):e.length===14?a(e):!1};var d=t=>{if(typeof t!="string")return!1;let e=t.replace(/\s|-/g,"");return e.length===15?i(t):e.length===9?l(t):e.length===14?a(t):!1},g=p,u=i;export{d as validateFR,u as validateFR_NIR,g as validateFR_SIREN_SIRET,i as validateNIR,l as validateSIREN,p as validateSIREN_SIRET,a as validateSIRET};
|
|
2
|
+
/**
|
|
3
|
+
* Validate French NIR (Numéro d'Inscription au Répertoire) - Social Security Number.
|
|
4
|
+
* @param value - The NIR number to validate (15 digits)
|
|
5
|
+
* @returns boolean indicating whether the NIR is valid
|
|
6
|
+
* @author AngelBlanco97
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Validate French SIREN (Système d'Identification du Répertoire des Entreprises).
|
|
12
|
+
* @param value - The SIREN number to validate (9 digits)
|
|
13
|
+
* @returns boolean indicating whether the SIREN is valid
|
|
14
|
+
* @author AngelBlanco97
|
|
15
|
+
* @license MIT
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Validate French SIRET (Système d'Identification du Répertoire des Établissements).
|
|
19
|
+
* @param value - The SIRET number to validate (14 digits = SIREN + NIC)
|
|
20
|
+
* @returns boolean indicating whether the SIRET is valid
|
|
21
|
+
* @author AngelBlanco97
|
|
22
|
+
* @license MIT
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Validate French SIREN or SIRET numbers (auto-detect by length).
|
|
26
|
+
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
27
|
+
* @returns boolean indicating whether the number is valid
|
|
28
|
+
* @author AngelBlanco97
|
|
29
|
+
* @license MIT
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Validates French identification numbers: NIR, SIREN, and SIRET (auto-detect).
|
|
33
|
+
* @param value - The identification number to validate
|
|
34
|
+
* @returns boolean indicating whether the identification number is valid
|
|
35
|
+
* @author AngelBlanco97
|
|
36
|
+
* @license MIT
|
|
37
|
+
* @documentation https://www.service-public.gouv.fr/
|
|
38
|
+
*/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var d=(e,t)=>{for(var o in t)s(e,o,{get:t[o],enumerable:!0})},T=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of p(t))!I.call(e,n)&&n!==o&&s(e,n,{get:()=>t[n],enumerable:!(r=u(t,n))||r.enumerable});return e};var g=e=>T(s({},"__esModule",{value:!0}),e);var x={};d(x,{validateNIF:()=>l,validatePT:()=>D});module.exports=g(x);var m=["1","2","3","5","6","8","9"];var l=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");if(!/^[0-9]{9}$/.test(t)||!m.includes(t[0]))return!1;let n=11-t.slice(0,8).split("").reduce((i,a,c)=>{let f=9-c;return i+parseInt(a,10)*f},0)%11;return n>=10&&(n=0),n===parseInt(t[8],10)},D=l;0&&(module.exports={validateNIF,validatePT});
|
|
2
|
+
/**
|
|
3
|
+
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
4
|
+
* @param value - The NIF number to validate (9 digits)
|
|
5
|
+
* @returns boolean indicating whether the NIF is valid
|
|
6
|
+
* @author AngelBlanco97
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
9
|
+
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
3
|
+
* @param value - The NIF number to validate (9 digits)
|
|
4
|
+
* @returns boolean indicating whether the NIF is valid
|
|
5
|
+
* @author AngelBlanco97
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
8
|
+
*/
|
|
9
|
+
declare const validateNIF: (value: any) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
12
|
+
* Alias for validateNIF for consistency with other country validators.
|
|
13
|
+
* @param value - The NIF number to validate
|
|
14
|
+
* @returns boolean indicating whether the NIF is valid
|
|
15
|
+
*/
|
|
16
|
+
declare const validatePT: (value: any) => boolean;
|
|
17
|
+
|
|
18
|
+
export { validateNIF, validatePT };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
3
|
+
* @param value - The NIF number to validate (9 digits)
|
|
4
|
+
* @returns boolean indicating whether the NIF is valid
|
|
5
|
+
* @author AngelBlanco97
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
8
|
+
*/
|
|
9
|
+
declare const validateNIF: (value: any) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
12
|
+
* Alias for validateNIF for consistency with other country validators.
|
|
13
|
+
* @param value - The NIF number to validate
|
|
14
|
+
* @returns boolean indicating whether the NIF is valid
|
|
15
|
+
*/
|
|
16
|
+
declare const validatePT: (value: any) => boolean;
|
|
17
|
+
|
|
18
|
+
export { validateNIF, validatePT };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var i=["1","2","3","5","6","8","9"];var a=n=>{if(typeof n!="string")return!1;let t=n.replace(/\s|-/g,"");if(!/^[0-9]{9}$/.test(t)||!i.includes(t[0]))return!1;let e=11-t.slice(0,8).split("").reduce((o,r,s)=>{let l=9-s;return o+parseInt(r,10)*l},0)%11;return e>=10&&(e=0),e===parseInt(t[8],10)},u=a;export{a as validateNIF,u as validatePT};
|
|
2
|
+
/**
|
|
3
|
+
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
4
|
+
* @param value - The NIF number to validate (9 digits)
|
|
5
|
+
* @returns boolean indicating whether the NIF is valid
|
|
6
|
+
* @author AngelBlanco97
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
9
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "validator-tax-id",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -11,6 +11,21 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./es": {
|
|
16
|
+
"types": "./dist/validators/es.d.ts",
|
|
17
|
+
"import": "./dist/validators/es.js",
|
|
18
|
+
"require": "./dist/validators/es.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./fr": {
|
|
21
|
+
"types": "./dist/validators/fr.d.ts",
|
|
22
|
+
"import": "./dist/validators/fr.js",
|
|
23
|
+
"require": "./dist/validators/fr.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./pt": {
|
|
26
|
+
"types": "./dist/validators/pt.d.ts",
|
|
27
|
+
"import": "./dist/validators/pt.js",
|
|
28
|
+
"require": "./dist/validators/pt.cjs"
|
|
14
29
|
}
|
|
15
30
|
},
|
|
16
31
|
"files": [
|
package/dist/index.global.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";var TaxIdValidator=(()=>{var u=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var y=(e,t)=>{for(var o in t)u(e,o,{get:t[o],enumerable:!0})},C=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of m(t))!b.call(e,n)&&n!==o&&u(e,n,{get:()=>t[n],enumerable:!(r=R(t,n))||r.enumerable});return e};var S=e=>C(u({},"__esModule",{value:!0}),e);var h={};y(h,{validateIdentification:()=>$});var T="TRWAGMYFPDXBNJZSQVHLCKE",v="JABCDEFGHI",N=/^([0-9]{8}|[XYZ][0-9]{7})[A-Z]$/,_=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/;var I=e=>{if(typeof e!="string")return!1;let t=e.toUpperCase().replace(/\s|-/g,"");if(N.test(t)){let s=t.slice(0,-1),f=t.slice(-1);s=s.replace("X","0").replace("Y","1").replace("Z","2");let a=parseInt(s,10);return T[a%23]===f}if(!_.test(t))return!1;let o=t[0],r=t.slice(1,8),n=t[8],l=0,c=0;for(let s=0;s<r.length;s++){let f=parseInt(r[s],10);if(s%2===0){let a=f*2;c+=a>9?a-9:a}else l+=f}let i=(10-(l+c)%10)%10,p=v[i];return"PQRSNW".includes(o)?n===p:"ABEH".includes(o)?n===String(i):n===String(i)||n===p};var A=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/;var g=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");return t.length===15?x(t):t.length===9||t.length===14?F(t):!1},D=e=>{let t=0,o=!1;for(let r=e.length-1;r>=0;r--){let n=parseInt(e[r],10);o&&(n*=2,n>9&&(n-=9)),t+=n,o=!o}return t%10===0},F=e=>{let t=e.replace(/\s|-/g,"");return!/^\d{9}$/.test(t)&&!/^\d{14}$/.test(t)||/^(\d)\1+$/.test(t)?!1:D(t)},x=e=>{let t=e.toUpperCase().replace(/\s|-/g,"");if(!A.test(t))return!1;let o=parseInt(t.slice(-2),10),r=t.slice(0,-2),n=r.slice(5,7);n==="2A"&&(r=r.slice(0,5)+"19"+r.slice(7)),n==="2B"&&(r=r.slice(0,5)+"18"+r.slice(7));let l=BigInt(r);return Number(97n-l%97n)===o};var G=["1","2","3","5","6","8","9"];var E=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");if(!/^[0-9]{9}$/.test(t)||!G.includes(t[0]))return!1;let n=11-t.slice(0,8).split("").reduce((l,c,d)=>{let i=9-d;return l+parseInt(c,10)*i},0)%11;return n>=10&&(n=0),n===parseInt(t[8],10)};var L={es:I,pt:E,fr:g};var $=(e,t)=>{let o=L[e];return o?o(t):(console.warn(`[TaxIDValidator] Country '${e}' not supported yet.`),!1)};return S(h);})();
|
|
2
|
-
/**
|
|
3
|
-
* Validate Spanish DNI/NIE/CIF numbers.
|
|
4
|
-
* @param value - The DNI or NIE number to validate
|
|
5
|
-
* @returns boolean indicating whether the DNI/NIE is valid (true) or not (false)
|
|
6
|
-
* @author AngelBlanco97
|
|
7
|
-
* @license MIT
|
|
8
|
-
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Validates French identification numbers: NIR (Numéro d'Inscription au Répertoire), SIREN, and SIRET.
|
|
12
|
-
* @param value - The identification number to validate
|
|
13
|
-
* @returns boolean indicating whether the identification number is valid (true) or not (false)
|
|
14
|
-
* @author AngelBlanco97
|
|
15
|
-
* @license MIT
|
|
16
|
-
* @documentation https://www.service-public.gouv.fr/
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
20
|
-
* @param value - The NIF number to validate
|
|
21
|
-
* @returns boolean indicating whether the NIF is valid (true) or not (false)
|
|
22
|
-
* @author AngelBlanco97
|
|
23
|
-
* @license MIT
|
|
24
|
-
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
25
|
-
*/
|
|
26
|
-
/**
|
|
27
|
-
* Function to validate identification numbers based on country/type.
|
|
28
|
-
* @param Country - The country code representing the type of identification number (e.g., 'es' for Spain, 'pt' for Portugal)
|
|
29
|
-
* @param value - The identification number to validate
|
|
30
|
-
* @returns boolean indicating whether the identification number is valid (true) or not (false)
|
|
31
|
-
* @author AngelBlanco97
|
|
32
|
-
* @license MIT
|
|
33
|
-
*/
|