validator-tax-id 1.2.0 → 1.3.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 +38 -49
- package/dist/index.cjs +13 -52
- package/dist/index.d.cts +76 -11
- package/dist/index.d.ts +76 -11
- package/dist/index.js +13 -52
- package/dist/validators/es.cjs +7 -15
- package/dist/validators/es.d.cts +9 -12
- package/dist/validators/es.d.ts +9 -12
- package/dist/validators/es.js +7 -15
- package/dist/validators/fr.cjs +7 -22
- package/dist/validators/fr.d.cts +12 -17
- package/dist/validators/fr.d.ts +12 -17
- package/dist/validators/fr.js +7 -22
- package/dist/validators/pt.cjs +19 -5
- package/dist/validators/pt.d.cts +7 -4
- package/dist/validators/pt.d.ts +7 -4
- package/dist/validators/pt.js +19 -5
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
# Tax ID Validator
|
|
2
2
|
|
|
3
|
+
A lightweight, zero-dependency, and universal TypeScript library to validate Tax IDs (Identification Numbers)
|
|
4
|
+
|
|
5
|
+
It uses precise mathematical algorithms to verify the integrity of the document number and follow guides of the country governments
|
|
6
|
+
|
|
3
7
|
[](https://www.npmjs.com/package/validator-tax-id)
|
|
4
8
|
[](https://www.npmjs.com/package/validator-tax-id)
|
|
5
9
|
[](https://github.com/AngelBlanco97/tax-id-validator/blob/main/LICENSE)
|
|
6
10
|
[](https://github.com/AngelBlanco97/tax-id-validator/actions)
|
|
11
|
+
[](https://paypal.me/AngelBlanco747)
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
## Supported Countries
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
| Country | Code | Documents Supported | Algorithm |
|
|
16
|
+
| ----------- | ---- | ------------------------------ | ------------------ |
|
|
17
|
+
| 🇪🇸 Spain | es | DNI, NIE, CIF | Module 23 |
|
|
18
|
+
| 🇵🇹 Portugal | pt | NIF (Personal) | Module 11 |
|
|
19
|
+
| 🇫🇷 France | fr | SIREN, SIRET, NIR | Luhn + Mod.97 |
|
|
20
|
+
| 🇩🇪 Germany | de | SteuerIdNr, VAT Number, W-IdNr | ISO 7064 Mod 10,11 |
|
|
11
21
|
|
|
12
22
|
## Features
|
|
13
23
|
|
|
@@ -45,6 +55,10 @@ validateIdentification("pt", "232013969"); // true (NIF)
|
|
|
45
55
|
|
|
46
56
|
// 🇫🇷 France (FR)
|
|
47
57
|
validateIdentification("fr", "443061841"); // true (SIREN)
|
|
58
|
+
|
|
59
|
+
// 🇩🇪 Germany (DE)
|
|
60
|
+
validateIdentification("de", "86095742719"); // true (SteuerIdNr)
|
|
61
|
+
validateIdentification("de", "DE136695976"); // true (VAT Number)
|
|
48
62
|
```
|
|
49
63
|
|
|
50
64
|
### Individual Validators (Recommended) ✨
|
|
@@ -63,6 +77,10 @@ import {
|
|
|
63
77
|
validateNIR,
|
|
64
78
|
// Portugal
|
|
65
79
|
validateNIF,
|
|
80
|
+
// Germany
|
|
81
|
+
validateSteuerIdNr,
|
|
82
|
+
validateVatNumber,
|
|
83
|
+
validateWidnr,
|
|
66
84
|
} from "validator-tax-id";
|
|
67
85
|
|
|
68
86
|
// 🇪🇸 Spain - Direct validation
|
|
@@ -77,6 +95,11 @@ validateNIR("188057512301180"); // true
|
|
|
77
95
|
|
|
78
96
|
// 🇵🇹 Portugal - Direct validation
|
|
79
97
|
validateNIF("123456789"); // true
|
|
98
|
+
|
|
99
|
+
// 🇩🇪 Germany - Direct validation
|
|
100
|
+
validateSteuerIdNr("86095742719"); // true
|
|
101
|
+
validateVatNumber("DE136695976"); // true
|
|
102
|
+
validateWidnr("136695976"); // true
|
|
80
103
|
```
|
|
81
104
|
|
|
82
105
|
### Country Auto-detect
|
|
@@ -84,70 +107,36 @@ validateNIF("123456789"); // true
|
|
|
84
107
|
If you don't know the specific document type:
|
|
85
108
|
|
|
86
109
|
```typescript
|
|
87
|
-
import {
|
|
110
|
+
import {
|
|
111
|
+
validateES,
|
|
112
|
+
validateFR,
|
|
113
|
+
validatePT,
|
|
114
|
+
validateDE,
|
|
115
|
+
} from "validator-tax-id";
|
|
88
116
|
|
|
89
117
|
validateES("12345678Z"); // true (auto-detects DNI)
|
|
90
118
|
validateES("A58818501"); // true (auto-detects CIF)
|
|
91
119
|
validateFR("443061841"); // true (auto-detects SIREN)
|
|
92
120
|
validatePT("123456789"); // true
|
|
121
|
+
validateDE("86095742719"); // true (auto-detects SteuerIdNr)
|
|
122
|
+
validateDE("DE136695976"); // true (auto-detects VAT Number)
|
|
93
123
|
```
|
|
94
124
|
|
|
95
125
|
## API Reference
|
|
96
126
|
|
|
97
127
|
### `validateIdentification(country, value)`
|
|
98
128
|
|
|
99
|
-
- **country**: `CountryCode` ('es' | 'pt' | 'fr') - The ISO code of the country.
|
|
100
|
-
- **value**: `string`
|
|
129
|
+
- **country**: `CountryCode` ('es' | 'pt' | 'fr' | 'de') - The ISO code of the country.
|
|
130
|
+
- **value**: `string` - The document string to validate.
|
|
101
131
|
- **Returns**: `boolean` (`true` if valid, `false` otherwise).
|
|
102
132
|
|
|
103
133
|
_Note: The validator sanitizes the input automatically (removes spaces, hyphens, and is case-insensitive)._
|
|
104
134
|
|
|
105
|
-
##
|
|
106
|
-
|
|
107
|
-
| Country | Code | Documents Supported | Algorithm |
|
|
108
|
-
| -------- | ---- | ------------------- | ------------- |
|
|
109
|
-
| Spain | es | DNI, NIE , CIF | Module 23 |
|
|
110
|
-
| Portugal | pt | NIF (Personal) | Module 11 |
|
|
111
|
-
| France | fr | SIREN, SIRET, NIR | Luhn + Mod.97 |
|
|
112
|
-
|
|
113
|
-
# Changelog
|
|
114
|
-
|
|
115
|
-
All notable changes to this project will be documented in this file.
|
|
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
|
-
|
|
128
|
-
## [1.1.3] - 2026-01-18
|
|
129
|
-
|
|
130
|
-
### Added 🚀
|
|
131
|
-
|
|
132
|
-
- **France (FR)** added validation for NIR document and fix SIREN-SIRET algorithm
|
|
133
|
-
- **Spain (ES)** added validation for CIF document.
|
|
134
|
-
- **Portugal (PT)** added validation on prefix in NIF document
|
|
135
|
-
|
|
136
|
-
## [1.1.0] - 2026-01-17
|
|
137
|
-
|
|
138
|
-
### Added 🚀
|
|
139
|
-
|
|
140
|
-
- **France (FR)** support added.
|
|
141
|
-
- Validation for **SIREN** (9 digits) and **SIRET** (14 digits) using Luhn algorithm.
|
|
142
|
-
|
|
143
|
-
## [1.0.0] - 2026-01-17
|
|
135
|
+
## Support
|
|
144
136
|
|
|
145
|
-
|
|
137
|
+
If this library helped you, consider buying me a coffee ☕
|
|
146
138
|
|
|
147
|
-
-
|
|
148
|
-
- **Spain (ES)** support: DNI and NIE validation (Modulo 23).
|
|
149
|
-
- **Portugal (PT)** support: NIF validation (Modulo 11).
|
|
150
|
-
- Core logic and TypeScript types.
|
|
139
|
+
[](https://paypal.me/AngelBlanco747)
|
|
151
140
|
|
|
152
141
|
## License
|
|
153
142
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,84 +1,45 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var n in t)f(e,n,{get:t[n],enumerable:!0})},$=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of O(t))!X.call(e,r)&&r!==n&&f(e,r,{get:()=>t[r],enumerable:!(o=M(t,r))||o.enumerable});return e};var P=e=>$(f({},"__esModule",{value:!0}),e);var rt={};z(rt,{isValidCountryCode:()=>F,isValidString:()=>u,validateCIF:()=>b,validateDE:()=>_,validateDNI:()=>E,validateES:()=>C,validateFR:()=>S,validateIdentification:()=>ot,validateNIE:()=>x,validateNIF:()=>y,validateNIR:()=>R,validatePT:()=>h,validateSIREN:()=>D,validateSIRET:()=>N,validateSteuerIdNr:()=>T,validateVatNumber:()=>k,validateWidnr:()=>v});module.exports=P(rt);var u=e=>typeof e=="string"&&e.length>0,F=e=>e==="es"||e==="pt"||e==="fr"||e==="de";var c=e=>u(e)?e.toUpperCase().replace(/[\s-]/g,""):null,a=(e,t)=>{let n=c(e);return n===null?null:t.test(n)?n:null};var I=e=>{let t=0,n=!1;for(let o=e.length-1;o>=0;o--){let r=parseInt(e[o],10);n&&(r*=2,r>9&&(r-=9)),t+=r,n=!n}return t%10===0},g=(e,t)=>t[e%23],w=e=>{let o=11-e.reduce((r,i,s)=>{let l=9-s;return r+i*l},0)%11;return o>=10?0:o},V=e=>Number(97n-e%97n),A=e=>{let t="JABCDEFGHI",n=0,o=0;for(let s=0;s<e.length;s++){let l=parseInt(e[s],10);if(s%2===0){let p=l*2;o+=p>9?p-9:p}else n+=l}let i=(10-(n+o)%10)%10;return{digit:i,letter:t[i]}},m=e=>/^(\d)\1+$/.test(e),d=e=>{let t=10;for(let o=0;o<e.length;o++){let i=(parseInt(e[o],10)+t)%10;t=(i===0?10:i)*2%11}let n=11-t;return n===10?0:n},G=e=>{let t={};for(let i of e)t[i]=(t[i]||0)+1;let n=Object.values(t),o=n.filter(i=>i===2).length,r=n.filter(i=>i===3).length;return o===1&&r===0||r===1&&o===0};var L="TRWAGMYFPDXBNJZSQVHLCKE",B=/^[0-9]{8}[A-Z]$/,W=/^[XYZ][0-9]{7}[A-Z]$/,Y=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/,H="PQRSNW",J="ABEH",E=e=>{let t=a(e,B);if(!t)return!1;let n=parseInt(t.slice(0,-1),10),o=t.slice(-1);return g(n,L)===o},x=e=>{let t=a(e,W);if(!t)return!1;let n=t.slice(-1),o=t[0],i=parseInt((o==="X"?"0":o==="Y"?"1":"2")+t.slice(1,-1),10);return g(i,L)===n},b=e=>{let t=a(e,Y);if(!t)return!1;let n=t[0],o=t.slice(1,8),r=t[8],{digit:i,letter:s}=A(o);return H.includes(n)?r===s:J.includes(n)?r===String(i):r===String(i)||r===s},C=e=>E(e)||x(e)||b(e);var U=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/,Z=/^\d{9}$/,K=/^\d{14}$/,R=e=>{let t=a(e,U);if(!t)return!1;let n=parseInt(t.slice(-2),10),o=t.slice(0,-2),r=o.slice(5,7);return r==="2A"&&(o=o.slice(0,5)+"19"+o.slice(7)),r==="2B"&&(o=o.slice(0,5)+"18"+o.slice(7)),V(BigInt(o))===n},D=e=>{let t=c(e);return!t||!Z.test(t)||m(t)?!1:I(t)},N=e=>{let t=c(e);return!t||!K.test(t)||m(t)?!1:I(t)};var S=e=>{let t=c(e);return t?t.length===15?R(e):t.length===9?D(e):t.length===14?N(e):!1:!1};var Q=/^[0-9]{9}$/,j=["1","2","3","5","6","8","9"],y=e=>{let t=c(e);if(!t||!Q.test(t)||!j.includes(t[0]))return!1;let n=t.slice(0,8).split("").map(r=>parseInt(r,10));return w(n)===parseInt(t[8],10)},h=y;var q=/^[0-9]{11}$/,tt=/^DE[0-9]{9}$/,et=/^[0-9]{9}$/,T=e=>{let t=a(e,q);if(!t)return!1;let n=t.substring(0,10),o=parseInt(t.substring(10,11),10);return G(n)?d(n)===o:!1},k=e=>{let t=a(e,tt);if(!t)return!1;let n=t.substring(2),o=n.substring(0,8),r=parseInt(n.substring(8,9),10);return d(o)===r},v=e=>{let t=a(e,et);if(!t)return!1;let n=t.substring(0,8),o=parseInt(t.substring(8,9),10);return d(n)===o},_=e=>T(e)||k(e)||v(e);var nt={es:C,pt:h,fr:S,de:_},ot=(e,t)=>{let n=nt[e];return n?n(t):(console.warn(`[TaxIDValidator] Country '${e}' not supported yet.`),!1)};0&&(module.exports={isValidCountryCode,isValidString,validateCIF,validateDE,validateDNI,validateES,validateFR,validateIdentification,validateNIE,validateNIF,validateNIR,validatePT,validateSIREN,validateSIRET,validateSteuerIdNr,validateVatNumber,validateWidnr});
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param value - The DNI number to validate (8 digits + letter)
|
|
5
|
-
* @returns boolean indicating whether the DNI is valid
|
|
3
|
+
* Types for Tax ID Validator
|
|
6
4
|
* @author AngelBlanco97
|
|
7
5
|
* @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
6
|
*/
|
|
10
7
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @returns boolean indicating whether the NIE is valid
|
|
8
|
+
* Sanitization utilities for Tax ID validation
|
|
9
|
+
* Single Responsibility: Only handles string cleaning/normalization
|
|
14
10
|
* @author AngelBlanco97
|
|
15
11
|
* @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
12
|
*/
|
|
18
13
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @returns boolean indicating whether the CIF is valid
|
|
14
|
+
* Common validation algorithms
|
|
15
|
+
* Single Responsibility: Only contains mathematical validation algorithms
|
|
22
16
|
* @author AngelBlanco97
|
|
23
17
|
* @license MIT
|
|
24
18
|
*/
|
|
25
19
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param value - The identification number to validate
|
|
28
|
-
* @returns boolean indicating whether the identification is valid
|
|
20
|
+
* Spanish Tax ID Validators (DNI, NIE, CIF)
|
|
29
21
|
* @author AngelBlanco97
|
|
30
22
|
* @license MIT
|
|
31
23
|
*/
|
|
32
24
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param value - The NIR number to validate (15 digits)
|
|
35
|
-
* @returns boolean indicating whether the NIR is valid
|
|
25
|
+
* French Tax ID Validators (NIR, SIREN, SIRET)
|
|
36
26
|
* @author AngelBlanco97
|
|
37
27
|
* @license MIT
|
|
38
|
-
* @documentation https://www.service-public.gouv.fr/
|
|
39
28
|
*/
|
|
40
29
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param value - The SIREN number to validate (9 digits)
|
|
43
|
-
* @returns boolean indicating whether the SIREN is valid
|
|
30
|
+
* Portuguese Tax ID Validators (NIF)
|
|
44
31
|
* @author AngelBlanco97
|
|
45
32
|
* @license MIT
|
|
46
33
|
*/
|
|
47
34
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
35
|
+
* German Validators (SteuerIdNr, VAT Number, W-IdNr)
|
|
36
|
+
* @documentation https://euipo.europa.eu/tunnel-web/secure/webdav/guest/document_library/Documents/COSME/VAT%20numbers%20EU.pdf
|
|
37
|
+
* @documentation https://www.iamexpat.de/expat-info/money-taxation/tax-identification-number-germany
|
|
51
38
|
* @author AngelBlanco97
|
|
52
39
|
* @license MIT
|
|
53
40
|
*/
|
|
54
41
|
/**
|
|
55
|
-
*
|
|
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
|
|
65
|
-
* @author AngelBlanco97
|
|
66
|
-
* @license MIT
|
|
67
|
-
* @documentation https://www.service-public.gouv.fr/
|
|
68
|
-
*/
|
|
69
|
-
/**
|
|
70
|
-
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
71
|
-
* @param value - The NIF number to validate (9 digits)
|
|
72
|
-
* @returns boolean indicating whether the NIF is valid
|
|
73
|
-
* @author AngelBlanco97
|
|
74
|
-
* @license MIT
|
|
75
|
-
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
76
|
-
*/
|
|
77
|
-
/**
|
|
78
|
-
* Function to validate identification numbers based on country/type.
|
|
79
|
-
* @param Country - The country code representing the type of identification number (e.g., 'es' for Spain, 'pt' for Portugal)
|
|
80
|
-
* @param value - The identification number to validate
|
|
81
|
-
* @returns boolean indicating whether the identification number is valid (true) or not (false)
|
|
42
|
+
* Tax ID Validator - Main Entry Point
|
|
82
43
|
* @author AngelBlanco97
|
|
83
44
|
* @license MIT
|
|
84
45
|
*/
|
package/dist/index.d.cts
CHANGED
|
@@ -2,20 +2,85 @@ export { validateCIF, validateDNI, validateES, validateNIE } from './validators/
|
|
|
2
2
|
export { validateFR, validateNIR, validateSIREN, validateSIRET } from './validators/fr.cjs';
|
|
3
3
|
export { validateNIF, validatePT } from './validators/pt.cjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* German Validators (SteuerIdNr, VAT Number, W-IdNr)
|
|
7
|
+
* @documentation https://euipo.europa.eu/tunnel-web/secure/webdav/guest/document_library/Documents/COSME/VAT%20numbers%20EU.pdf
|
|
8
|
+
* @documentation https://www.iamexpat.de/expat-info/money-taxation/tax-identification-number-germany
|
|
9
|
+
* @author AngelBlanco97
|
|
10
|
+
* @license MIT
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Validate German Steueridentifikationsnummer (Tax Identification Number).
|
|
14
|
+
* Unique per person, lifetime validity.
|
|
15
|
+
* Format: 11 digits.
|
|
16
|
+
* Checksum: ISO 7064 Mod 11,10.
|
|
17
|
+
* * @param value - The value to validate
|
|
18
|
+
* @returns boolean indicating whether the SteuerIdNr is valid
|
|
19
|
+
*/
|
|
20
|
+
declare const validateSteuerIdNr: (value: unknown) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Validate German VAT Number (Umsatzsteuer-Id).
|
|
23
|
+
* Format: DE + 9 digits.
|
|
24
|
+
* Checksum: ISO 7064 Mod 11,10.
|
|
25
|
+
* * @param value - The value to validate
|
|
26
|
+
* @returns boolean indicating whether the VAT number is valid
|
|
27
|
+
*/
|
|
28
|
+
declare const validateVatNumber: (value: unknown) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Validate Business identification number (W-IdNr)
|
|
31
|
+
* Format: DE + 9 digits + suffix (usually).
|
|
32
|
+
* Based on your regex, we validate the 9 digit core.
|
|
33
|
+
* Checksum: ISO 7064 Mod 11,10 (Same as VAT).
|
|
34
|
+
* * @param value - The value to validate
|
|
35
|
+
* @returns boolean indicating whether the W-IdNr is valid
|
|
36
|
+
*/
|
|
37
|
+
declare const validateWidnr: (value: unknown) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Validate German Tax Identifiers (SteuerIdNr, Steuernummer, VAT Number, W-IdNr).
|
|
40
|
+
* @param value - The value to validate
|
|
41
|
+
* @returns boolean indicating whether any of the German tax identifiers is valid
|
|
42
|
+
*/
|
|
43
|
+
declare const validateDE: (value: unknown) => boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Types for Tax ID Validator
|
|
47
|
+
* @author AngelBlanco97
|
|
48
|
+
* @license MIT
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* Supported country codes (ISO 3166-1 alpha-2)
|
|
52
|
+
*/
|
|
53
|
+
type CountryCode = "es" | "pt" | "fr" | "de";
|
|
54
|
+
/**
|
|
55
|
+
* Valid input type for tax ID validation.
|
|
56
|
+
* Only strings are valid - this makes the API explicit.
|
|
57
|
+
*/
|
|
58
|
+
type TaxIdInput = string;
|
|
59
|
+
/**
|
|
60
|
+
* Validation function signature
|
|
61
|
+
*/
|
|
62
|
+
type ValidatorFunction = (value: unknown) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Type guard to check if value is a non-empty string
|
|
65
|
+
*/
|
|
66
|
+
declare const isValidString: (value: unknown) => value is string;
|
|
67
|
+
/**
|
|
68
|
+
* Type guard to check if country code is valid
|
|
69
|
+
*/
|
|
70
|
+
declare const isValidCountryCode: (code: unknown) => code is CountryCode;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Tax ID Validator - Main Entry Point
|
|
74
|
+
* @author AngelBlanco97
|
|
75
|
+
* @license MIT
|
|
76
|
+
*/
|
|
77
|
+
|
|
11
78
|
/**
|
|
12
79
|
* Function to validate identification numbers based on country/type.
|
|
13
|
-
* @param
|
|
80
|
+
* @param country - The country code representing the type of identification number (e.g., 'es' for Spain, 'pt' for Portugal)
|
|
14
81
|
* @param value - The identification number to validate
|
|
15
82
|
* @returns boolean indicating whether the identification number is valid (true) or not (false)
|
|
16
|
-
* @author AngelBlanco97
|
|
17
|
-
* @license MIT
|
|
18
83
|
*/
|
|
19
|
-
declare const validateIdentification: (country: CountryCode, value:
|
|
84
|
+
declare const validateIdentification: (country: CountryCode, value: unknown) => boolean;
|
|
20
85
|
|
|
21
|
-
export { type CountryCode, validateIdentification };
|
|
86
|
+
export { type CountryCode, type TaxIdInput, type ValidatorFunction, isValidCountryCode, isValidString, validateDE, validateIdentification, validateSteuerIdNr, validateVatNumber, validateWidnr };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,20 +2,85 @@ export { validateCIF, validateDNI, validateES, validateNIE } from './validators/
|
|
|
2
2
|
export { validateFR, validateNIR, validateSIREN, validateSIRET } from './validators/fr.js';
|
|
3
3
|
export { validateNIF, validatePT } from './validators/pt.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* German Validators (SteuerIdNr, VAT Number, W-IdNr)
|
|
7
|
+
* @documentation https://euipo.europa.eu/tunnel-web/secure/webdav/guest/document_library/Documents/COSME/VAT%20numbers%20EU.pdf
|
|
8
|
+
* @documentation https://www.iamexpat.de/expat-info/money-taxation/tax-identification-number-germany
|
|
9
|
+
* @author AngelBlanco97
|
|
10
|
+
* @license MIT
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Validate German Steueridentifikationsnummer (Tax Identification Number).
|
|
14
|
+
* Unique per person, lifetime validity.
|
|
15
|
+
* Format: 11 digits.
|
|
16
|
+
* Checksum: ISO 7064 Mod 11,10.
|
|
17
|
+
* * @param value - The value to validate
|
|
18
|
+
* @returns boolean indicating whether the SteuerIdNr is valid
|
|
19
|
+
*/
|
|
20
|
+
declare const validateSteuerIdNr: (value: unknown) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Validate German VAT Number (Umsatzsteuer-Id).
|
|
23
|
+
* Format: DE + 9 digits.
|
|
24
|
+
* Checksum: ISO 7064 Mod 11,10.
|
|
25
|
+
* * @param value - The value to validate
|
|
26
|
+
* @returns boolean indicating whether the VAT number is valid
|
|
27
|
+
*/
|
|
28
|
+
declare const validateVatNumber: (value: unknown) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Validate Business identification number (W-IdNr)
|
|
31
|
+
* Format: DE + 9 digits + suffix (usually).
|
|
32
|
+
* Based on your regex, we validate the 9 digit core.
|
|
33
|
+
* Checksum: ISO 7064 Mod 11,10 (Same as VAT).
|
|
34
|
+
* * @param value - The value to validate
|
|
35
|
+
* @returns boolean indicating whether the W-IdNr is valid
|
|
36
|
+
*/
|
|
37
|
+
declare const validateWidnr: (value: unknown) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Validate German Tax Identifiers (SteuerIdNr, Steuernummer, VAT Number, W-IdNr).
|
|
40
|
+
* @param value - The value to validate
|
|
41
|
+
* @returns boolean indicating whether any of the German tax identifiers is valid
|
|
42
|
+
*/
|
|
43
|
+
declare const validateDE: (value: unknown) => boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Types for Tax ID Validator
|
|
47
|
+
* @author AngelBlanco97
|
|
48
|
+
* @license MIT
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* Supported country codes (ISO 3166-1 alpha-2)
|
|
52
|
+
*/
|
|
53
|
+
type CountryCode = "es" | "pt" | "fr" | "de";
|
|
54
|
+
/**
|
|
55
|
+
* Valid input type for tax ID validation.
|
|
56
|
+
* Only strings are valid - this makes the API explicit.
|
|
57
|
+
*/
|
|
58
|
+
type TaxIdInput = string;
|
|
59
|
+
/**
|
|
60
|
+
* Validation function signature
|
|
61
|
+
*/
|
|
62
|
+
type ValidatorFunction = (value: unknown) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Type guard to check if value is a non-empty string
|
|
65
|
+
*/
|
|
66
|
+
declare const isValidString: (value: unknown) => value is string;
|
|
67
|
+
/**
|
|
68
|
+
* Type guard to check if country code is valid
|
|
69
|
+
*/
|
|
70
|
+
declare const isValidCountryCode: (code: unknown) => code is CountryCode;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Tax ID Validator - Main Entry Point
|
|
74
|
+
* @author AngelBlanco97
|
|
75
|
+
* @license MIT
|
|
76
|
+
*/
|
|
77
|
+
|
|
11
78
|
/**
|
|
12
79
|
* Function to validate identification numbers based on country/type.
|
|
13
|
-
* @param
|
|
80
|
+
* @param country - The country code representing the type of identification number (e.g., 'es' for Spain, 'pt' for Portugal)
|
|
14
81
|
* @param value - The identification number to validate
|
|
15
82
|
* @returns boolean indicating whether the identification number is valid (true) or not (false)
|
|
16
|
-
* @author AngelBlanco97
|
|
17
|
-
* @license MIT
|
|
18
83
|
*/
|
|
19
|
-
declare const validateIdentification: (country: CountryCode, value:
|
|
84
|
+
declare const validateIdentification: (country: CountryCode, value: unknown) => boolean;
|
|
20
85
|
|
|
21
|
-
export { type CountryCode, validateIdentification };
|
|
86
|
+
export { type CountryCode, type TaxIdInput, type ValidatorFunction, isValidCountryCode, isValidString, validateDE, validateIdentification, validateSteuerIdNr, validateVatNumber, validateWidnr };
|
package/dist/index.js
CHANGED
|
@@ -1,84 +1,45 @@
|
|
|
1
|
-
var
|
|
1
|
+
var p=e=>typeof e=="string"&&e.length>0,G=e=>e==="es"||e==="pt"||e==="fr"||e==="de";var c=e=>p(e)?e.toUpperCase().replace(/[\s-]/g,""):null,a=(e,t)=>{let n=c(e);return n===null?null:t.test(n)?n:null};var f=e=>{let t=0,n=!1;for(let o=e.length-1;o>=0;o--){let r=parseInt(e[o],10);n&&(r*=2,r>9&&(r-=9)),t+=r,n=!n}return t%10===0},I=(e,t)=>t[e%23],m=e=>{let o=11-e.reduce((r,i,s)=>{let l=9-s;return r+i*l},0)%11;return o>=10?0:o},E=e=>Number(97n-e%97n),x=e=>{let t="JABCDEFGHI",n=0,o=0;for(let s=0;s<e.length;s++){let l=parseInt(e[s],10);if(s%2===0){let d=l*2;o+=d>9?d-9:d}else n+=l}let i=(10-(n+o)%10)%10;return{digit:i,letter:t[i]}},g=e=>/^(\d)\1+$/.test(e),u=e=>{let t=10;for(let o=0;o<e.length;o++){let i=(parseInt(e[o],10)+t)%10;t=(i===0?10:i)*2%11}let n=11-t;return n===10?0:n},b=e=>{let t={};for(let i of e)t[i]=(t[i]||0)+1;let n=Object.values(t),o=n.filter(i=>i===2).length,r=n.filter(i=>i===3).length;return o===1&&r===0||r===1&&o===0};var C="TRWAGMYFPDXBNJZSQVHLCKE",L=/^[0-9]{8}[A-Z]$/,M=/^[XYZ][0-9]{7}[A-Z]$/,O=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/,X="PQRSNW",z="ABEH",R=e=>{let t=a(e,L);if(!t)return!1;let n=parseInt(t.slice(0,-1),10),o=t.slice(-1);return I(n,C)===o},D=e=>{let t=a(e,M);if(!t)return!1;let n=t.slice(-1),o=t[0],i=parseInt((o==="X"?"0":o==="Y"?"1":"2")+t.slice(1,-1),10);return I(i,C)===n},N=e=>{let t=a(e,O);if(!t)return!1;let n=t[0],o=t.slice(1,8),r=t[8],{digit:i,letter:s}=x(o);return X.includes(n)?r===s:z.includes(n)?r===String(i):r===String(i)||r===s},S=e=>R(e)||D(e)||N(e);var $=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/,P=/^\d{9}$/,B=/^\d{14}$/,y=e=>{let t=a(e,$);if(!t)return!1;let n=parseInt(t.slice(-2),10),o=t.slice(0,-2),r=o.slice(5,7);return r==="2A"&&(o=o.slice(0,5)+"19"+o.slice(7)),r==="2B"&&(o=o.slice(0,5)+"18"+o.slice(7)),E(BigInt(o))===n},h=e=>{let t=c(e);return!t||!P.test(t)||g(t)?!1:f(t)},T=e=>{let t=c(e);return!t||!B.test(t)||g(t)?!1:f(t)};var k=e=>{let t=c(e);return t?t.length===15?y(e):t.length===9?h(e):t.length===14?T(e):!1:!1};var W=/^[0-9]{9}$/,Y=["1","2","3","5","6","8","9"],v=e=>{let t=c(e);if(!t||!W.test(t)||!Y.includes(t[0]))return!1;let n=t.slice(0,8).split("").map(r=>parseInt(r,10));return m(n)===parseInt(t[8],10)},_=v;var H=/^[0-9]{11}$/,J=/^DE[0-9]{9}$/,U=/^[0-9]{9}$/,F=e=>{let t=a(e,H);if(!t)return!1;let n=t.substring(0,10),o=parseInt(t.substring(10,11),10);return b(n)?u(n)===o:!1},w=e=>{let t=a(e,J);if(!t)return!1;let n=t.substring(2),o=n.substring(0,8),r=parseInt(n.substring(8,9),10);return u(o)===r},V=e=>{let t=a(e,U);if(!t)return!1;let n=t.substring(0,8),o=parseInt(t.substring(8,9),10);return u(n)===o},A=e=>F(e)||w(e)||V(e);var Z={es:S,pt:_,fr:k,de:A},xt=(e,t)=>{let n=Z[e];return n?n(t):(console.warn(`[TaxIDValidator] Country '${e}' not supported yet.`),!1)};export{G as isValidCountryCode,p as isValidString,N as validateCIF,A as validateDE,R as validateDNI,S as validateES,k as validateFR,xt as validateIdentification,D as validateNIE,v as validateNIF,y as validateNIR,_ as validatePT,h as validateSIREN,T as validateSIRET,F as validateSteuerIdNr,w as validateVatNumber,V as validateWidnr};
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param value - The DNI number to validate (8 digits + letter)
|
|
5
|
-
* @returns boolean indicating whether the DNI is valid
|
|
3
|
+
* Types for Tax ID Validator
|
|
6
4
|
* @author AngelBlanco97
|
|
7
5
|
* @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
6
|
*/
|
|
10
7
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @returns boolean indicating whether the NIE is valid
|
|
8
|
+
* Sanitization utilities for Tax ID validation
|
|
9
|
+
* Single Responsibility: Only handles string cleaning/normalization
|
|
14
10
|
* @author AngelBlanco97
|
|
15
11
|
* @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
12
|
*/
|
|
18
13
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @returns boolean indicating whether the CIF is valid
|
|
14
|
+
* Common validation algorithms
|
|
15
|
+
* Single Responsibility: Only contains mathematical validation algorithms
|
|
22
16
|
* @author AngelBlanco97
|
|
23
17
|
* @license MIT
|
|
24
18
|
*/
|
|
25
19
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param value - The identification number to validate
|
|
28
|
-
* @returns boolean indicating whether the identification is valid
|
|
20
|
+
* Spanish Tax ID Validators (DNI, NIE, CIF)
|
|
29
21
|
* @author AngelBlanco97
|
|
30
22
|
* @license MIT
|
|
31
23
|
*/
|
|
32
24
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param value - The NIR number to validate (15 digits)
|
|
35
|
-
* @returns boolean indicating whether the NIR is valid
|
|
25
|
+
* French Tax ID Validators (NIR, SIREN, SIRET)
|
|
36
26
|
* @author AngelBlanco97
|
|
37
27
|
* @license MIT
|
|
38
|
-
* @documentation https://www.service-public.gouv.fr/
|
|
39
28
|
*/
|
|
40
29
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param value - The SIREN number to validate (9 digits)
|
|
43
|
-
* @returns boolean indicating whether the SIREN is valid
|
|
30
|
+
* Portuguese Tax ID Validators (NIF)
|
|
44
31
|
* @author AngelBlanco97
|
|
45
32
|
* @license MIT
|
|
46
33
|
*/
|
|
47
34
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
35
|
+
* German Validators (SteuerIdNr, VAT Number, W-IdNr)
|
|
36
|
+
* @documentation https://euipo.europa.eu/tunnel-web/secure/webdav/guest/document_library/Documents/COSME/VAT%20numbers%20EU.pdf
|
|
37
|
+
* @documentation https://www.iamexpat.de/expat-info/money-taxation/tax-identification-number-germany
|
|
51
38
|
* @author AngelBlanco97
|
|
52
39
|
* @license MIT
|
|
53
40
|
*/
|
|
54
41
|
/**
|
|
55
|
-
*
|
|
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
|
|
65
|
-
* @author AngelBlanco97
|
|
66
|
-
* @license MIT
|
|
67
|
-
* @documentation https://www.service-public.gouv.fr/
|
|
68
|
-
*/
|
|
69
|
-
/**
|
|
70
|
-
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
71
|
-
* @param value - The NIF number to validate (9 digits)
|
|
72
|
-
* @returns boolean indicating whether the NIF is valid
|
|
73
|
-
* @author AngelBlanco97
|
|
74
|
-
* @license MIT
|
|
75
|
-
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
76
|
-
*/
|
|
77
|
-
/**
|
|
78
|
-
* Function to validate identification numbers based on country/type.
|
|
79
|
-
* @param Country - The country code representing the type of identification number (e.g., 'es' for Spain, 'pt' for Portugal)
|
|
80
|
-
* @param value - The identification number to validate
|
|
81
|
-
* @returns boolean indicating whether the identification number is valid (true) or not (false)
|
|
42
|
+
* Tax ID Validator - Main Entry Point
|
|
82
43
|
* @author AngelBlanco97
|
|
83
44
|
* @license MIT
|
|
84
45
|
*/
|
package/dist/validators/es.cjs
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var n in e)l(t,n,{get:e[n],enumerable:!0})},T=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!y.call(t,o)&&o!==n&&l(t,o,{get:()=>e[o],enumerable:!(r=C(e,o))||r.enumerable});return t};var b=t=>T(l({},"__esModule",{value:!0}),t);var _={};D(_,{validateCIF:()=>I,validateDNI:()=>f,validateES:()=>O,validateNIE:()=>x});module.exports=b(_);var d=t=>typeof t=="string"&&t.length>0;var N=t=>d(t)?t.toUpperCase().replace(/[\s-]/g,""):null,c=(t,e)=>{let n=N(t);return n===null?null:e.test(n)?n:null};var a=(t,e)=>e[t%23];var g=t=>{let e="JABCDEFGHI",n=0,r=0;for(let u=0;u<t.length;u++){let p=parseInt(t[u],10);if(u%2===0){let i=p*2;r+=i>9?i-9:i}else n+=p}let s=(10-(n+r)%10)%10;return{digit:s,letter:e[s]}};var m="TRWAGMYFPDXBNJZSQVHLCKE",S=/^[0-9]{8}[A-Z]$/,h=/^[XYZ][0-9]{7}[A-Z]$/,R=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/,F="PQRSNW",L="ABEH",f=t=>{let e=c(t,S);if(!e)return!1;let n=parseInt(e.slice(0,-1),10),r=e.slice(-1);return a(n,m)===r},x=t=>{let e=c(t,h);if(!e)return!1;let n=e.slice(-1),r=e[0],s=parseInt((r==="X"?"0":r==="Y"?"1":"2")+e.slice(1,-1),10);return a(s,m)===n},I=t=>{let e=c(t,R);if(!e)return!1;let n=e[0],r=e.slice(1,8),o=e[8],{digit:s,letter:u}=g(r);return F.includes(n)?o===u:L.includes(n)?o===String(s):o===String(s)||o===u},O=t=>f(t)||x(t)||I(t);0&&(module.exports={validateCIF,validateDNI,validateES,validateNIE});
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param value - The DNI number to validate (8 digits + letter)
|
|
5
|
-
* @returns boolean indicating whether the DNI is valid
|
|
3
|
+
* Types for Tax ID Validator
|
|
6
4
|
* @author AngelBlanco97
|
|
7
5
|
* @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
6
|
*/
|
|
10
7
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @returns boolean indicating whether the NIE is valid
|
|
8
|
+
* Sanitization utilities for Tax ID validation
|
|
9
|
+
* Single Responsibility: Only handles string cleaning/normalization
|
|
14
10
|
* @author AngelBlanco97
|
|
15
11
|
* @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
12
|
*/
|
|
18
13
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @returns boolean indicating whether the CIF is valid
|
|
14
|
+
* Common validation algorithms
|
|
15
|
+
* Single Responsibility: Only contains mathematical validation algorithms
|
|
22
16
|
* @author AngelBlanco97
|
|
23
17
|
* @license MIT
|
|
24
18
|
*/
|
|
25
19
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param value - The identification number to validate
|
|
28
|
-
* @returns boolean indicating whether the identification is valid
|
|
20
|
+
* Spanish Tax ID Validators (DNI, NIE, CIF)
|
|
29
21
|
* @author AngelBlanco97
|
|
30
22
|
* @license MIT
|
|
31
23
|
*/
|
package/dist/validators/es.d.cts
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spanish Tax ID Validators (DNI, NIE, CIF)
|
|
3
|
+
* @author AngelBlanco97
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Validate Spanish DNI (Documento Nacional de Identidad).
|
|
3
8
|
* @param value - The DNI number to validate (8 digits + letter)
|
|
4
9
|
* @returns boolean indicating whether the DNI is valid
|
|
5
|
-
* @author AngelBlanco97
|
|
6
|
-
* @license MIT
|
|
7
10
|
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
8
11
|
*/
|
|
9
|
-
declare const validateDNI: (value:
|
|
12
|
+
declare const validateDNI: (value: unknown) => boolean;
|
|
10
13
|
/**
|
|
11
14
|
* Validate Spanish NIE (Número de Identidad de Extranjero).
|
|
12
15
|
* @param value - The NIE number to validate (X/Y/Z + 7 digits + letter)
|
|
13
16
|
* @returns boolean indicating whether the NIE is valid
|
|
14
|
-
* @author AngelBlanco97
|
|
15
|
-
* @license MIT
|
|
16
17
|
* @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
|
*/
|
|
18
|
-
declare const validateNIE: (value:
|
|
19
|
+
declare const validateNIE: (value: unknown) => boolean;
|
|
19
20
|
/**
|
|
20
21
|
* Validate Spanish CIF (Código de Identificación Fiscal).
|
|
21
22
|
* @param value - The CIF number to validate (letter + 7 digits + control)
|
|
22
23
|
* @returns boolean indicating whether the CIF is valid
|
|
23
|
-
* @author AngelBlanco97
|
|
24
|
-
* @license MIT
|
|
25
24
|
*/
|
|
26
|
-
declare const validateCIF: (value:
|
|
25
|
+
declare const validateCIF: (value: unknown) => boolean;
|
|
27
26
|
/**
|
|
28
27
|
* Validate Spanish DNI/NIE/CIF numbers (auto-detect type).
|
|
29
28
|
* @param value - The identification number to validate
|
|
30
29
|
* @returns boolean indicating whether the identification is valid
|
|
31
|
-
* @author AngelBlanco97
|
|
32
|
-
* @license MIT
|
|
33
30
|
*/
|
|
34
|
-
declare const validateES: (value:
|
|
31
|
+
declare const validateES: (value: unknown) => boolean;
|
|
35
32
|
|
|
36
33
|
export { validateCIF, validateDNI, validateES, validateNIE };
|
package/dist/validators/es.d.ts
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spanish Tax ID Validators (DNI, NIE, CIF)
|
|
3
|
+
* @author AngelBlanco97
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Validate Spanish DNI (Documento Nacional de Identidad).
|
|
3
8
|
* @param value - The DNI number to validate (8 digits + letter)
|
|
4
9
|
* @returns boolean indicating whether the DNI is valid
|
|
5
|
-
* @author AngelBlanco97
|
|
6
|
-
* @license MIT
|
|
7
10
|
* @documentation https://www.interior.gob.es/opencms/es/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
|
|
8
11
|
*/
|
|
9
|
-
declare const validateDNI: (value:
|
|
12
|
+
declare const validateDNI: (value: unknown) => boolean;
|
|
10
13
|
/**
|
|
11
14
|
* Validate Spanish NIE (Número de Identidad de Extranjero).
|
|
12
15
|
* @param value - The NIE number to validate (X/Y/Z + 7 digits + letter)
|
|
13
16
|
* @returns boolean indicating whether the NIE is valid
|
|
14
|
-
* @author AngelBlanco97
|
|
15
|
-
* @license MIT
|
|
16
17
|
* @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
|
*/
|
|
18
|
-
declare const validateNIE: (value:
|
|
19
|
+
declare const validateNIE: (value: unknown) => boolean;
|
|
19
20
|
/**
|
|
20
21
|
* Validate Spanish CIF (Código de Identificación Fiscal).
|
|
21
22
|
* @param value - The CIF number to validate (letter + 7 digits + control)
|
|
22
23
|
* @returns boolean indicating whether the CIF is valid
|
|
23
|
-
* @author AngelBlanco97
|
|
24
|
-
* @license MIT
|
|
25
24
|
*/
|
|
26
|
-
declare const validateCIF: (value:
|
|
25
|
+
declare const validateCIF: (value: unknown) => boolean;
|
|
27
26
|
/**
|
|
28
27
|
* Validate Spanish DNI/NIE/CIF numbers (auto-detect type).
|
|
29
28
|
* @param value - The identification number to validate
|
|
30
29
|
* @returns boolean indicating whether the identification is valid
|
|
31
|
-
* @author AngelBlanco97
|
|
32
|
-
* @license MIT
|
|
33
30
|
*/
|
|
34
|
-
declare const validateES: (value:
|
|
31
|
+
declare const validateES: (value: unknown) => boolean;
|
|
35
32
|
|
|
36
33
|
export { validateCIF, validateDNI, validateES, validateNIE };
|
package/dist/validators/es.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
var
|
|
1
|
+
var p=t=>typeof t=="string"&&t.length>0;var m=t=>p(t)?t.toUpperCase().replace(/[\s-]/g,""):null,c=(t,e)=>{let n=m(t);return n===null?null:e.test(n)?n:null};var l=(t,e)=>e[t%23];var d=t=>{let e="JABCDEFGHI",n=0,r=0;for(let s=0;s<t.length;s++){let a=parseInt(t[s],10);if(s%2===0){let i=a*2;r+=i>9?i-9:i}else n+=a}let o=(10-(n+r)%10)%10;return{digit:o,letter:e[o]}};var g="TRWAGMYFPDXBNJZSQVHLCKE",f=/^[0-9]{8}[A-Z]$/,x=/^[XYZ][0-9]{7}[A-Z]$/,I=/^[ABCDEFGHJNPQRSUVW][0-9]{7}[0-9A-J]$/,C="PQRSNW",E="ABEH",y=t=>{let e=c(t,f);if(!e)return!1;let n=parseInt(e.slice(0,-1),10),r=e.slice(-1);return l(n,g)===r},D=t=>{let e=c(t,x);if(!e)return!1;let n=e.slice(-1),r=e[0],o=parseInt((r==="X"?"0":r==="Y"?"1":"2")+e.slice(1,-1),10);return l(o,g)===n},T=t=>{let e=c(t,I);if(!e)return!1;let n=e[0],r=e.slice(1,8),u=e[8],{digit:o,letter:s}=d(r);return C.includes(n)?u===s:E.includes(n)?u===String(o):u===String(o)||u===s},L=t=>y(t)||D(t)||T(t);export{T as validateCIF,y as validateDNI,L as validateES,D as validateNIE};
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param value - The DNI number to validate (8 digits + letter)
|
|
5
|
-
* @returns boolean indicating whether the DNI is valid
|
|
3
|
+
* Types for Tax ID Validator
|
|
6
4
|
* @author AngelBlanco97
|
|
7
5
|
* @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
6
|
*/
|
|
10
7
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @returns boolean indicating whether the NIE is valid
|
|
8
|
+
* Sanitization utilities for Tax ID validation
|
|
9
|
+
* Single Responsibility: Only handles string cleaning/normalization
|
|
14
10
|
* @author AngelBlanco97
|
|
15
11
|
* @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
12
|
*/
|
|
18
13
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @returns boolean indicating whether the CIF is valid
|
|
14
|
+
* Common validation algorithms
|
|
15
|
+
* Single Responsibility: Only contains mathematical validation algorithms
|
|
22
16
|
* @author AngelBlanco97
|
|
23
17
|
* @license MIT
|
|
24
18
|
*/
|
|
25
19
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param value - The identification number to validate
|
|
28
|
-
* @returns boolean indicating whether the identification is valid
|
|
20
|
+
* Spanish Tax ID Validators (DNI, NIE, CIF)
|
|
29
21
|
* @author AngelBlanco97
|
|
30
22
|
* @license MIT
|
|
31
23
|
*/
|
package/dist/validators/fr.cjs
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var h=(e,t)=>{for(var r in t)i(e,r,{get:t[r],enumerable:!0})},R=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of I(t))!y.call(e,o)&&o!==r&&i(e,o,{get:()=>t[o],enumerable:!(n=x(t,o))||n.enumerable});return e};var E=e=>R(i({},"__esModule",{value:!0}),e);var k={};h(k,{validateFR:()=>D,validateFR_NIR:()=>N,validateFR_SIREN_SIRET:()=>C,validateNIR:()=>c,validateSIREN:()=>a,validateSIREN_SIRET:()=>m,validateSIRET:()=>p});module.exports=E(k);var d=e=>typeof e=="string"&&e.length>0;var s=e=>d(e)?e.toUpperCase().replace(/[\s-]/g,""):null,f=(e,t)=>{let r=s(e);return r===null?null:t.test(r)?r:null};var u=e=>{let t=0,r=!1;for(let n=e.length-1;n>=0;n--){let o=parseInt(e[n],10);r&&(o*=2,o>9&&(o-=9)),t+=o,r=!r}return t%10===0};var g=e=>Number(97n-e%97n);var l=e=>/^(\d)\1+$/.test(e);var S=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/,b=/^\d{9}$/,T=/^\d{14}$/,c=e=>{let t=f(e,S);if(!t)return!1;let r=parseInt(t.slice(-2),10),n=t.slice(0,-2),o=n.slice(5,7);return o==="2A"&&(n=n.slice(0,5)+"19"+n.slice(7)),o==="2B"&&(n=n.slice(0,5)+"18"+n.slice(7)),g(BigInt(n))===r},a=e=>{let t=s(e);return!t||!b.test(t)||l(t)?!1:u(t)},p=e=>{let t=s(e);return!t||!T.test(t)||l(t)?!1:u(t)},m=e=>{let t=s(e);return t?t.length===9?a(t):t.length===14?p(t):!1:!1},D=e=>{let t=s(e);return t?t.length===15?c(e):t.length===9?a(e):t.length===14?p(e):!1:!1},C=m,N=c;0&&(module.exports={validateFR,validateFR_NIR,validateFR_SIREN_SIRET,validateNIR,validateSIREN,validateSIREN_SIRET,validateSIRET});
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param value - The NIR number to validate (15 digits)
|
|
5
|
-
* @returns boolean indicating whether the NIR is valid
|
|
3
|
+
* Types for Tax ID Validator
|
|
6
4
|
* @author AngelBlanco97
|
|
7
5
|
* @license MIT
|
|
8
|
-
* @documentation https://www.service-public.gouv.fr/
|
|
9
6
|
*/
|
|
10
7
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @returns boolean indicating whether the SIREN is valid
|
|
8
|
+
* Sanitization utilities for Tax ID validation
|
|
9
|
+
* Single Responsibility: Only handles string cleaning/normalization
|
|
14
10
|
* @author AngelBlanco97
|
|
15
11
|
* @license MIT
|
|
16
12
|
*/
|
|
17
13
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @returns boolean indicating whether the SIRET is valid
|
|
14
|
+
* Common validation algorithms
|
|
15
|
+
* Single Responsibility: Only contains mathematical validation algorithms
|
|
21
16
|
* @author AngelBlanco97
|
|
22
17
|
* @license MIT
|
|
23
18
|
*/
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
27
|
-
* @returns boolean indicating whether the number is valid
|
|
20
|
+
* French Tax ID Validators (NIR, SIREN, SIRET)
|
|
28
21
|
* @author AngelBlanco97
|
|
29
22
|
* @license MIT
|
|
30
23
|
*/
|
|
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
|
-
*/
|
package/dist/validators/fr.d.cts
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* French Tax ID Validators (NIR, SIREN, SIRET)
|
|
3
|
+
* @author AngelBlanco97
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Validate French NIR (Numéro d'Inscription au Répertoire) - Social Security Number.
|
|
3
8
|
* @param value - The NIR number to validate (15 digits)
|
|
4
9
|
* @returns boolean indicating whether the NIR is valid
|
|
5
|
-
* @author AngelBlanco97
|
|
6
|
-
* @license MIT
|
|
7
10
|
* @documentation https://www.service-public.gouv.fr/
|
|
8
11
|
*/
|
|
9
|
-
declare const validateNIR: (value:
|
|
12
|
+
declare const validateNIR: (value: unknown) => boolean;
|
|
10
13
|
/**
|
|
11
14
|
* Validate French SIREN (Système d'Identification du Répertoire des Entreprises).
|
|
12
15
|
* @param value - The SIREN number to validate (9 digits)
|
|
13
16
|
* @returns boolean indicating whether the SIREN is valid
|
|
14
|
-
* @author AngelBlanco97
|
|
15
|
-
* @license MIT
|
|
16
17
|
*/
|
|
17
|
-
declare const validateSIREN: (value:
|
|
18
|
+
declare const validateSIREN: (value: unknown) => boolean;
|
|
18
19
|
/**
|
|
19
20
|
* Validate French SIRET (Système d'Identification du Répertoire des Établissements).
|
|
20
21
|
* @param value - The SIRET number to validate (14 digits = SIREN + NIC)
|
|
21
22
|
* @returns boolean indicating whether the SIRET is valid
|
|
22
|
-
* @author AngelBlanco97
|
|
23
|
-
* @license MIT
|
|
24
23
|
*/
|
|
25
|
-
declare const validateSIRET: (value:
|
|
24
|
+
declare const validateSIRET: (value: unknown) => boolean;
|
|
26
25
|
/**
|
|
27
26
|
* Validate French SIREN or SIRET numbers (auto-detect by length).
|
|
28
27
|
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
29
28
|
* @returns boolean indicating whether the number is valid
|
|
30
|
-
* @author AngelBlanco97
|
|
31
|
-
* @license MIT
|
|
32
29
|
*/
|
|
33
|
-
declare const validateSIREN_SIRET: (value:
|
|
30
|
+
declare const validateSIREN_SIRET: (value: unknown) => boolean;
|
|
34
31
|
/**
|
|
35
32
|
* Validates French identification numbers: NIR, SIREN, and SIRET (auto-detect).
|
|
36
33
|
* @param value - The identification number to validate
|
|
37
34
|
* @returns boolean indicating whether the identification number is valid
|
|
38
|
-
* @author AngelBlanco97
|
|
39
|
-
* @license MIT
|
|
40
35
|
* @documentation https://www.service-public.gouv.fr/
|
|
41
36
|
*/
|
|
42
|
-
declare const validateFR: (value:
|
|
43
|
-
declare const validateFR_SIREN_SIRET: (value:
|
|
44
|
-
declare const validateFR_NIR: (value:
|
|
37
|
+
declare const validateFR: (value: unknown) => boolean;
|
|
38
|
+
declare const validateFR_SIREN_SIRET: (value: unknown) => boolean;
|
|
39
|
+
declare const validateFR_NIR: (value: unknown) => boolean;
|
|
45
40
|
|
|
46
41
|
export { validateFR, validateFR_NIR, validateFR_SIREN_SIRET, validateNIR, validateSIREN, validateSIREN_SIRET, validateSIRET };
|
package/dist/validators/fr.d.ts
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* French Tax ID Validators (NIR, SIREN, SIRET)
|
|
3
|
+
* @author AngelBlanco97
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Validate French NIR (Numéro d'Inscription au Répertoire) - Social Security Number.
|
|
3
8
|
* @param value - The NIR number to validate (15 digits)
|
|
4
9
|
* @returns boolean indicating whether the NIR is valid
|
|
5
|
-
* @author AngelBlanco97
|
|
6
|
-
* @license MIT
|
|
7
10
|
* @documentation https://www.service-public.gouv.fr/
|
|
8
11
|
*/
|
|
9
|
-
declare const validateNIR: (value:
|
|
12
|
+
declare const validateNIR: (value: unknown) => boolean;
|
|
10
13
|
/**
|
|
11
14
|
* Validate French SIREN (Système d'Identification du Répertoire des Entreprises).
|
|
12
15
|
* @param value - The SIREN number to validate (9 digits)
|
|
13
16
|
* @returns boolean indicating whether the SIREN is valid
|
|
14
|
-
* @author AngelBlanco97
|
|
15
|
-
* @license MIT
|
|
16
17
|
*/
|
|
17
|
-
declare const validateSIREN: (value:
|
|
18
|
+
declare const validateSIREN: (value: unknown) => boolean;
|
|
18
19
|
/**
|
|
19
20
|
* Validate French SIRET (Système d'Identification du Répertoire des Établissements).
|
|
20
21
|
* @param value - The SIRET number to validate (14 digits = SIREN + NIC)
|
|
21
22
|
* @returns boolean indicating whether the SIRET is valid
|
|
22
|
-
* @author AngelBlanco97
|
|
23
|
-
* @license MIT
|
|
24
23
|
*/
|
|
25
|
-
declare const validateSIRET: (value:
|
|
24
|
+
declare const validateSIRET: (value: unknown) => boolean;
|
|
26
25
|
/**
|
|
27
26
|
* Validate French SIREN or SIRET numbers (auto-detect by length).
|
|
28
27
|
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
29
28
|
* @returns boolean indicating whether the number is valid
|
|
30
|
-
* @author AngelBlanco97
|
|
31
|
-
* @license MIT
|
|
32
29
|
*/
|
|
33
|
-
declare const validateSIREN_SIRET: (value:
|
|
30
|
+
declare const validateSIREN_SIRET: (value: unknown) => boolean;
|
|
34
31
|
/**
|
|
35
32
|
* Validates French identification numbers: NIR, SIREN, and SIRET (auto-detect).
|
|
36
33
|
* @param value - The identification number to validate
|
|
37
34
|
* @returns boolean indicating whether the identification number is valid
|
|
38
|
-
* @author AngelBlanco97
|
|
39
|
-
* @license MIT
|
|
40
35
|
* @documentation https://www.service-public.gouv.fr/
|
|
41
36
|
*/
|
|
42
|
-
declare const validateFR: (value:
|
|
43
|
-
declare const validateFR_SIREN_SIRET: (value:
|
|
44
|
-
declare const validateFR_NIR: (value:
|
|
37
|
+
declare const validateFR: (value: unknown) => boolean;
|
|
38
|
+
declare const validateFR_SIREN_SIRET: (value: unknown) => boolean;
|
|
39
|
+
declare const validateFR_NIR: (value: unknown) => boolean;
|
|
45
40
|
|
|
46
41
|
export { validateFR, validateFR_NIR, validateFR_SIREN_SIRET, validateNIR, validateSIREN, validateSIREN_SIRET, validateSIRET };
|
package/dist/validators/fr.js
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=e=>typeof e=="string"&&e.length>0;var s=e=>l(e)?e.toUpperCase().replace(/[\s-]/g,""):null,c=(e,t)=>{let r=s(e);return r===null?null:t.test(r)?r:null};var i=e=>{let t=0,r=!1;for(let n=e.length-1;n>=0;n--){let o=parseInt(e[n],10);r&&(o*=2,o>9&&(o-=9)),t+=o,r=!r}return t%10===0};var a=e=>Number(97n-e%97n);var u=e=>/^(\d)\1+$/.test(e);var g=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/,m=/^\d{9}$/,x=/^\d{14}$/,p=e=>{let t=c(e,g);if(!t)return!1;let r=parseInt(t.slice(-2),10),n=t.slice(0,-2),o=n.slice(5,7);return o==="2A"&&(n=n.slice(0,5)+"19"+n.slice(7)),o==="2B"&&(n=n.slice(0,5)+"18"+n.slice(7)),a(BigInt(n))===r},d=e=>{let t=s(e);return!t||!m.test(t)||u(t)?!1:i(t)},f=e=>{let t=s(e);return!t||!x.test(t)||u(t)?!1:i(t)},I=e=>{let t=s(e);return t?t.length===9?d(t):t.length===14?f(t):!1:!1},T=e=>{let t=s(e);return t?t.length===15?p(e):t.length===9?d(e):t.length===14?f(e):!1:!1},D=I,C=p;export{T as validateFR,C as validateFR_NIR,D as validateFR_SIREN_SIRET,p as validateNIR,d as validateSIREN,I as validateSIREN_SIRET,f as validateSIRET};
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param value - The NIR number to validate (15 digits)
|
|
5
|
-
* @returns boolean indicating whether the NIR is valid
|
|
3
|
+
* Types for Tax ID Validator
|
|
6
4
|
* @author AngelBlanco97
|
|
7
5
|
* @license MIT
|
|
8
|
-
* @documentation https://www.service-public.gouv.fr/
|
|
9
6
|
*/
|
|
10
7
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @returns boolean indicating whether the SIREN is valid
|
|
8
|
+
* Sanitization utilities for Tax ID validation
|
|
9
|
+
* Single Responsibility: Only handles string cleaning/normalization
|
|
14
10
|
* @author AngelBlanco97
|
|
15
11
|
* @license MIT
|
|
16
12
|
*/
|
|
17
13
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @returns boolean indicating whether the SIRET is valid
|
|
14
|
+
* Common validation algorithms
|
|
15
|
+
* Single Responsibility: Only contains mathematical validation algorithms
|
|
21
16
|
* @author AngelBlanco97
|
|
22
17
|
* @license MIT
|
|
23
18
|
*/
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @param value - The SIREN (9 digits) or SIRET (14 digits) number to validate
|
|
27
|
-
* @returns boolean indicating whether the number is valid
|
|
20
|
+
* French Tax ID Validators (NIR, SIREN, SIRET)
|
|
28
21
|
* @author AngelBlanco97
|
|
29
22
|
* @license MIT
|
|
30
23
|
*/
|
|
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
|
-
*/
|
package/dist/validators/pt.cjs
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var o in e)s(t,o,{get:e[o],enumerable:!0})},I=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of m(e))!f.call(t,n)&&n!==o&&s(t,n,{get:()=>e[n],enumerable:!(r=g(e,n))||r.enumerable});return t};var y=t=>I(s({},"__esModule",{value:!0}),t);var T={};x(T,{validateNIF:()=>l,validatePT:()=>C});module.exports=y(T);var i=t=>typeof t=="string"&&t.length>0;var u=t=>i(t)?t.toUpperCase().replace(/[\s-]/g,""):null;var c=t=>{let r=11-t.reduce((n,p,a)=>{let d=9-a;return n+p*d},0)%11;return r>=10?0:r};var D=/^[0-9]{9}$/,h=["1","2","3","5","6","8","9"],l=t=>{let e=u(t);if(!e||!D.test(e)||!h.includes(e[0]))return!1;let o=e.slice(0,8).split("").map(n=>parseInt(n,10));return c(o)===parseInt(e[8],10)},C=l;0&&(module.exports={validateNIF,validatePT});
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
* Types for Tax ID Validator
|
|
4
|
+
* @author AngelBlanco97
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Sanitization utilities for Tax ID validation
|
|
9
|
+
* Single Responsibility: Only handles string cleaning/normalization
|
|
10
|
+
* @author AngelBlanco97
|
|
11
|
+
* @license MIT
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Common validation algorithms
|
|
15
|
+
* Single Responsibility: Only contains mathematical validation algorithms
|
|
16
|
+
* @author AngelBlanco97
|
|
17
|
+
* @license MIT
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Portuguese Tax ID Validators (NIF)
|
|
6
21
|
* @author AngelBlanco97
|
|
7
22
|
* @license MIT
|
|
8
|
-
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
9
23
|
*/
|
package/dist/validators/pt.d.cts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portuguese Tax ID Validators (NIF)
|
|
3
|
+
* @author AngelBlanco97
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
3
8
|
* @param value - The NIF number to validate (9 digits)
|
|
4
9
|
* @returns boolean indicating whether the NIF is valid
|
|
5
|
-
* @author AngelBlanco97
|
|
6
|
-
* @license MIT
|
|
7
10
|
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
8
11
|
*/
|
|
9
|
-
declare const validateNIF: (value:
|
|
12
|
+
declare const validateNIF: (value: unknown) => boolean;
|
|
10
13
|
/**
|
|
11
14
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
12
15
|
* Alias for validateNIF for consistency with other country validators.
|
|
13
16
|
* @param value - The NIF number to validate
|
|
14
17
|
* @returns boolean indicating whether the NIF is valid
|
|
15
18
|
*/
|
|
16
|
-
declare const validatePT: (value:
|
|
19
|
+
declare const validatePT: (value: unknown) => boolean;
|
|
17
20
|
|
|
18
21
|
export { validateNIF, validatePT };
|
package/dist/validators/pt.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portuguese Tax ID Validators (NIF)
|
|
3
|
+
* @author AngelBlanco97
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
3
8
|
* @param value - The NIF number to validate (9 digits)
|
|
4
9
|
* @returns boolean indicating whether the NIF is valid
|
|
5
|
-
* @author AngelBlanco97
|
|
6
|
-
* @license MIT
|
|
7
10
|
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
8
11
|
*/
|
|
9
|
-
declare const validateNIF: (value:
|
|
12
|
+
declare const validateNIF: (value: unknown) => boolean;
|
|
10
13
|
/**
|
|
11
14
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
12
15
|
* Alias for validateNIF for consistency with other country validators.
|
|
13
16
|
* @param value - The NIF number to validate
|
|
14
17
|
* @returns boolean indicating whether the NIF is valid
|
|
15
18
|
*/
|
|
16
|
-
declare const validatePT: (value:
|
|
19
|
+
declare const validatePT: (value: unknown) => boolean;
|
|
17
20
|
|
|
18
21
|
export { validateNIF, validatePT };
|
package/dist/validators/pt.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
var i=["1","2","3","5","6","8","9"]
|
|
1
|
+
var s=t=>typeof t=="string"&&t.length>0;var i=t=>s(t)?t.toUpperCase().replace(/[\s-]/g,""):null;var u=t=>{let n=11-t.reduce((o,c,l)=>{let p=9-l;return o+c*p},0)%11;return n>=10?0:n};var a=/^[0-9]{9}$/,d=["1","2","3","5","6","8","9"],g=t=>{let e=i(t);if(!e||!a.test(e)||!d.includes(e[0]))return!1;let r=e.slice(0,8).split("").map(o=>parseInt(o,10));return u(r)===parseInt(e[8],10)},h=g;export{g as validateNIF,h as validatePT};
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
* Types for Tax ID Validator
|
|
4
|
+
* @author AngelBlanco97
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Sanitization utilities for Tax ID validation
|
|
9
|
+
* Single Responsibility: Only handles string cleaning/normalization
|
|
10
|
+
* @author AngelBlanco97
|
|
11
|
+
* @license MIT
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Common validation algorithms
|
|
15
|
+
* Single Responsibility: Only contains mathematical validation algorithms
|
|
16
|
+
* @author AngelBlanco97
|
|
17
|
+
* @license MIT
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Portuguese Tax ID Validators (NIF)
|
|
6
21
|
* @author AngelBlanco97
|
|
7
22
|
* @license MIT
|
|
8
|
-
* @documentation https://en.wikipedia.org/wiki/Tax_identification_number#Portugal
|
|
9
23
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "validator-tax-id",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"funding": {
|
|
6
|
+
"type": "paypal",
|
|
7
|
+
"url": "https://paypal.me/AngelBlanco747"
|
|
8
|
+
},
|
|
5
9
|
"main": "./dist/index.cjs",
|
|
6
10
|
"module": "./dist/index.js",
|
|
7
11
|
"types": "./dist/index.d.ts",
|