validator-tax-id 1.1.2 → 1.1.3
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 +13 -5
- package/dist/index.cjs +10 -2
- package/dist/index.global.js +10 -2
- package/dist/index.js +10 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,16 +63,24 @@ _Note: The validator sanitizes the input automatically (removes spaces, hyphens,
|
|
|
63
63
|
|
|
64
64
|
## SUPPORTED COUNTRIES
|
|
65
65
|
|
|
66
|
-
| Country | Code | Documents Supported | Algorithm
|
|
67
|
-
| -------- | ---- | ------------------- |
|
|
68
|
-
| Spain | es | DNI, NIE
|
|
69
|
-
| Portugal | pt | NIF (Personal) |
|
|
70
|
-
| France | fr | SIREN, SIRET
|
|
66
|
+
| Country | Code | Documents Supported | Algorithm |
|
|
67
|
+
| -------- | ---- | ------------------- | ------------- |
|
|
68
|
+
| Spain | es | DNI, NIE , CIF | Module 23 |
|
|
69
|
+
| Portugal | pt | NIF (Personal) | Module 11 |
|
|
70
|
+
| France | fr | SIREN, SIRET, NIR | Luhn + Mod.97 |
|
|
71
71
|
|
|
72
72
|
# Changelog
|
|
73
73
|
|
|
74
74
|
All notable changes to this project will be documented in this file.
|
|
75
75
|
|
|
76
|
+
## [1.1.3] - 2026-01-18
|
|
77
|
+
|
|
78
|
+
### Added 🚀
|
|
79
|
+
|
|
80
|
+
- **France (FR)** added validation for NIR document and fix SIREN-SIRET algorithm
|
|
81
|
+
- **Spain (ES)** added validation for CIF document.
|
|
82
|
+
- **Portugal (PT)** added validation on prefix in NIF document
|
|
83
|
+
|
|
76
84
|
## [1.1.0] - 2026-01-17
|
|
77
85
|
|
|
78
86
|
### Added 🚀
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";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:()=>$});module.exports=S(h);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)};0&&(module.exports={validateIdentification});
|
|
2
2
|
/**
|
|
3
|
-
* Validate Spanish DNI/NIE numbers.
|
|
3
|
+
* Validate Spanish DNI/NIE/CIF numbers.
|
|
4
4
|
* @param value - The DNI or NIE number to validate
|
|
5
5
|
* @returns boolean indicating whether the DNI/NIE is valid (true) or not (false)
|
|
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
|
+
/**
|
|
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
|
+
*/
|
|
10
18
|
/**
|
|
11
19
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
12
20
|
* @param value - The NIF number to validate
|
package/dist/index.global.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
"use strict";var TaxIdValidator=(()=>{var
|
|
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
2
|
/**
|
|
3
|
-
* Validate Spanish DNI/NIE numbers.
|
|
3
|
+
* Validate Spanish DNI/NIE/CIF numbers.
|
|
4
4
|
* @param value - The DNI or NIE number to validate
|
|
5
5
|
* @returns boolean indicating whether the DNI/NIE is valid (true) or not (false)
|
|
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
|
+
/**
|
|
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
|
+
*/
|
|
10
18
|
/**
|
|
11
19
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
12
20
|
* @param value - The NIF number to validate
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
var
|
|
1
|
+
var E="TRWAGMYFPDXBNJZSQVHLCKE",R="JABCDEFGHI",m=/^([0-9]{8}|[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(m.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 E[a%23]===f}if(!b.test(t))return!1;let o=t[0],n=t.slice(1,8),r=t[8],l=0,c=0;for(let s=0;s<n.length;s++){let f=parseInt(n[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,d=R[i];return"PQRSNW".includes(o)?r===d:"ABEH".includes(o)?r===String(i):r===String(i)||r===d};var y=/^[1-8]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B|97\d)\d{6}\d{2}$/;var I=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");return t.length===15?T(t):t.length===9||t.length===14?S(t):!1},C=e=>{let t=0,o=!1;for(let n=e.length-1;n>=0;n--){let r=parseInt(e[n],10);o&&(r*=2,r>9&&(r-=9)),t+=r,o=!o}return t%10===0},S=e=>{let t=e.replace(/\s|-/g,"");return!/^\d{9}$/.test(t)&&!/^\d{14}$/.test(t)||/^(\d)\1+$/.test(t)?!1:C(t)},T=e=>{let t=e.toUpperCase().replace(/\s|-/g,"");if(!y.test(t))return!1;let o=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 l=BigInt(n);return Number(97n-l%97n)===o};var v=["1","2","3","5","6","8","9"];var g=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s|-/g,"");if(!/^[0-9]{9}$/.test(t)||!v.includes(t[0]))return!1;let r=11-t.slice(0,8).split("").reduce((l,c,u)=>{let i=9-u;return l+parseInt(c,10)*i},0)%11;return r>=10&&(r=0),r===parseInt(t[8],10)};var N={es:p,pt:g,fr:I};var L=(e,t)=>{let o=N[e];return o?o(t):(console.warn(`[TaxIDValidator] Country '${e}' not supported yet.`),!1)};export{L as validateIdentification};
|
|
2
2
|
/**
|
|
3
|
-
* Validate Spanish DNI/NIE numbers.
|
|
3
|
+
* Validate Spanish DNI/NIE/CIF numbers.
|
|
4
4
|
* @param value - The DNI or NIE number to validate
|
|
5
5
|
* @returns boolean indicating whether the DNI/NIE is valid (true) or not (false)
|
|
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
|
+
/**
|
|
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
|
+
*/
|
|
10
18
|
/**
|
|
11
19
|
* Validates a Portuguese NIF (Número de Identificação Fiscal).
|
|
12
20
|
* @param value - The NIF number to validate
|