codicechiaro 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +100 -2
- package/dist/chunks/chunk-SUXBTA67.js +1 -0
- package/dist/data.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/calcola.d.ts +42 -0
- package/dist/types/core.d.ts +41 -0
- package/dist/types/data.d.ts +55 -0
- package/dist/types/en.d.ts +5 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/luoghi.d.ts +44 -0
- package/dist/types/parse.d.ts +6 -0
- package/dist/types/types.d.ts +46 -0
- package/dist/types/verifica.d.ts +56 -0
- package/package.json +66 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as D,b as j,c as q,d as Y}from"./chunks/chunk-SUXBTA67.js";var f="ABCDEHLMPRST",O="LMNPQRSTUV",x=[14,13,12,10,9,7,6],H="AEIOU";function N(e){return e.normalize("NFD").replace(/[̀-ͯ]/g,"").replace(/ß/g,"SS").replace(/[Ææ]/g,"AE").replace(/[Œœ]/g,"OE").replace(/[Øø]/g,"O").replace(/[Łł]/g,"L").replace(/[Đđ]/g,"D").toUpperCase().replace(/[^A-Z]/g,"")}function k(e){let o="",t="";for(let i of e)H.includes(i)?t+=i:o+=i;return{cons:o,voc:t}}function C(e){let{cons:o,voc:t}=k(N(e));return(o+t+"XXX").slice(0,3)}function S(e){let{cons:o,voc:t}=k(N(e));return o.length>=4?o[0]+o[2]+o[3]:(o+t+"XXX").slice(0,3)}function w(e){return e%4===0&&e%100!==0||e%400===0}function A(e,o){return o===2?w(e)?29:28:[4,6,9,11].includes(o)?30:31}function p(e){return Number.isInteger(e.anno)&&Number.isInteger(e.mese)&&Number.isInteger(e.giorno)&&e.anno>=1800&&e.anno<=9999&&e.mese>=1&&e.mese<=12&&e.giorno>=1&&e.giorno<=A(e.anno,e.mese)}function m(e){let o=(t,i)=>String(t).padStart(i,"0");return`${o(e.anno,4)}-${o(e.mese,2)}-${o(e.giorno,2)}`}function M(e,o){let t=String(e.anno%100).padStart(2,"0"),i=String(e.giorno+(o==="F"?40:0)).padStart(2,"0");return t+f[e.mese-1]+i}var W={0:1,1:0,2:5,3:7,4:9,5:13,6:15,7:17,8:19,9:21,A:1,B:0,C:5,D:7,E:9,F:13,G:15,H:17,I:19,J:21,K:2,L:4,M:18,N:20,O:11,P:3,Q:6,R:8,S:12,T:14,U:16,V:10,W:22,X:25,Y:24,Z:23};function G(e){let o=e.charCodeAt(0);return o>=48&&o<=57?o-48:o-65}function h(e){let o=e.toUpperCase();if(!/^[A-Z0-9]{15}$/.test(o))throw new Error("Servono 15 caratteri alfanumerici.");let t=0;for(let i=0;i<15;i++)t+=i%2===0?W[o[i]]:G(o[i]);return String.fromCharCode(65+t%26)}function z(e){let o=L(e),t=[],i=o.slice(0,15).split("");for(let n of x){i[n]=O[Number(i[n])];let a=i.join("");t.push(a+h(a))}return t}function L(e){let o=e.toUpperCase().slice(0,15).split("");for(let i of x){let n=O.indexOf(o[i]);n>=0&&(o[i]=String(n))}let t=o.join("");return t+h(t)}function E(e){let o=e.toUpperCase();return x.filter(t=>O.includes(o[t]))}var J=/^[\p{L}\s'’`\-.]+$/u;function V(e){let o=e??new Date;return m({anno:o.getFullYear(),mese:o.getMonth()+1,giorno:o.getDate()})}function F(e,o={}){let t=[],i=[],n=(r,c)=>{let u=(e[r]??"").trim();u?J.test(u)?N(u)||t.push({codice:`${r}.caratteri`,campo:r,messaggio:`Il ${c} deve contenere almeno una lettera.`,valori:{motivo:"nessuna-lettera"}}):t.push({codice:`${r}.caratteri`,campo:r,messaggio:`Il ${c} pu\xF2 contenere solo lettere, spazi, apostrofi e trattini.`}):t.push({codice:`${r}.vuoto`,campo:r,messaggio:`Inserisci il ${c}.`})};n("cognome","cognome"),n("nome","nome"),e.sesso!=="M"&&e.sesso!=="F"&&t.push({codice:"sesso.vuoto",campo:"sesso",messaggio:"Scegli il sesso."});let a=e.dataNascita;!a||!p(a)?t.push({codice:"data.non-valida",campo:"dataNascita",messaggio:"La data di nascita non esiste. Controlla giorno, mese e anno."}):m(a)>V(o.oggi)&&t.push({codice:"data.futura",campo:"dataNascita",messaggio:"La data di nascita non pu\xF2 essere nel futuro."});let s=(e.codiceLuogo??"").trim().toUpperCase();if(!/^[A-Z]\d{3}$/.test(s))t.push({codice:"luogo.vuoto",campo:"codiceLuogo",messaggio:"Scegli il comune o lo Stato estero di nascita."});else if(o.luoghi&&a&&p(a)){let r=o.luoghi.perCodice(s);r.length===0?t.push({codice:"luogo.sconosciuto",campo:"codiceLuogo",messaggio:"Non troviamo questo comune o Stato nei dati ufficiali."}):D(r,m(a))||i.push({codice:"luogo.fuori-periodo",campo:"codiceLuogo",messaggio:"Secondo i dati ufficiali questo luogo non esisteva con questo codice alla data di nascita. Controlla il comune scelto."})}return{errori:t,avvisi:i}}function K(e,o={}){let{errori:t,avvisi:i}=F(e,o);if(t.length)return{ok:!1,errori:t};let n=M(e.dataNascita,e.sesso),a={cognome:C(e.cognome),nome:S(e.nome),anno:n.slice(0,2),mese:n[2],giorno:n.slice(3,5),luogo:e.codiceLuogo.trim().toUpperCase(),controllo:""},s=a.cognome+a.nome+n+a.luogo;a.controllo=h(s);let r=s+a.controllo;return{ok:!0,codice:r,parti:a,omocodici:z(r),avvisi:i}}var ee=/^[A-Z]{6}[0-9LMNPQRSTUV]{2}[A-Z][0-9LMNPQRSTUV]{2}[A-Z][0-9LMNPQRSTUV]{3}[A-Z]$/;function U(e){return(e??"").toUpperCase().replace(/[\s\-.]/g,"")}function oe(e,o){let t=o.getFullYear()-e.anno,i=o.getMonth()+1;return(i<e.mese||i===e.mese&&o.getDate()<e.giorno)&&t--,t}function B(e,o={}){let t=U(e),i=[],n=[],a=l=>({valido:i.length===0,codice:t,errori:i,avvisi:n,dati:l});if(!t)return i.push({codice:"codice.vuoto",messaggio:"Inserisci un codice fiscale."}),a();if(t.length!==16)return i.push({codice:"codice.lunghezza",messaggio:`Il codice fiscale ha 16 caratteri: qui ne hai inseriti ${t.length}.`,valori:{n:t.length}}),a();if(!/^[A-Z0-9]+$/.test(t))return i.push({codice:"codice.caratteri",messaggio:"Il codice fiscale contiene solo lettere e numeri."}),a();if(!ee.test(t))return i.push({codice:"codice.struttura",...te(t)}),a();let s=h(t.slice(0,15));t[15]!==s&&i.push({codice:"controllo.errato",messaggio:`Il carattere di controllo (l'ultimo) dovrebbe essere ${s}, non ${t[15]}. Probabilmente c'\xE8 un errore di battitura.`,valori:{atteso:s,trovato:t[15]}});let r=E(t);r.length&&(x.slice(0,r.length).every(d=>r.includes(d))||n.push({codice:"omocodia.ordine",messaggio:"Le lettere al posto dei numeri non seguono l\u2019ordine ufficiale (da destra verso sinistra). Un codice cos\xEC \xE8 insolito: verificalo con l\u2019Agenzia delle Entrate."}));let c=L(t),u=f.indexOf(c[8])+1;if(u===0)return i.push({codice:"mese.errato",messaggio:`La lettera del mese (9\xB0 carattere) \xE8 ${c[8]}, ma le lettere valide sono ${f.split("").join(", ")}.`,valori:{lettera:c[8]}}),a();let v=Number(c.slice(9,11)),Q=v>40?"F":"M",$=v>40?v-40:v;if($<1||$>31||v>31&&v<41)return i.push({codice:"giorno.errato",messaggio:`Il giorno (10\xB0 e 11\xB0 carattere) \xE8 ${c.slice(9,11)}: deve essere tra 01 e 31 per gli uomini e tra 41 e 71 per le donne.`,valori:{giorno:c.slice(9,11)}}),a();let P=o.oggi??new Date,X=V(P),Z=Number(c.slice(6,8)),b=c.slice(11,15),g=o.luoghi?o.luoghi.perCodice(b):[],_=Math.floor(P.getFullYear()/100)*100,I=[];for(let l=_;l>=1800;l-=100){let d={anno:l+Z,mese:u,giorno:$};if(p(d)&&m(d)<=X&&I.push(d),I.length===2)break}if(I.length===0){let l=A(2e3+Z,u);return i.push({codice:"data.non-valida",messaggio:$>l?`La data non esiste: il mese ${String(u).padStart(2,"0")} ha al massimo ${l} giorni.`:"La data di nascita non \xE8 valida.",...$>l?{valori:{mese:u,max:l}}:{}}),a()}let y=I;if(g.length){let l=I.filter(d=>D(g,m(d)));y=[...l,...I.filter(d=>!l.includes(d))]}let T=y[0],R;return o.luoghi&&(g.length===0?i.push({codice:"luogo.sconosciuto",messaggio:`Il codice del luogo di nascita (${b}) non esiste nei dati ufficiali dei comuni e degli Stati esteri.`,valori:{codice:b}}):(R=D(g,m(T)),R||n.push({codice:"luogo.fuori-periodo",messaggio:`Il codice ${b} (${g[g.length-1].nome}) non risulta valido alla data di nascita secondo i dati ufficiali.`,valori:{codice:b,nome:g[g.length-1].nome}}))),a({sesso:Q,dataNascita:T,dateCandidate:y,eta:oe(T,P),codiceLuogo:b,luogo:R,luoghiPossibili:g,codiceBase:c,livelloOmocodia:r.length})}function te(e){let o=[[0,6,/^[A-Z]{6}$/,"I primi 6 caratteri (cognome e nome) devono essere lettere"],[6,8,/^[0-9LMNPQRSTUV]{2}$/,"Il 7\xB0 e l'8\xB0 carattere (anno) devono essere numeri"],[8,9,/^[A-Z]$/,"Il 9\xB0 carattere (mese) deve essere una lettera"],[9,11,/^[0-9LMNPQRSTUV]{2}$/,"Il 10\xB0 e l'11\xB0 carattere (giorno) devono essere numeri"],[11,12,/^[A-Z]$/,"Il 12\xB0 carattere (luogo di nascita) deve essere una lettera"],[12,15,/^[0-9LMNPQRSTUV]{3}$/,"Dal 13\xB0 al 15\xB0 carattere (luogo di nascita) devono essere numeri"],[15,16,/^[A-Z]$/,"L'ultimo carattere (controllo) deve essere una lettera"]];for(let[t,[i,n,a,s]]of o.entries()){let r=e.slice(i,n);if(!a.test(r))return{messaggio:`${s}: hai scritto "${r}".`,valori:{gruppo:t,scritto:r}}}return{messaggio:"La struttura del codice non \xE8 valida."}}function ie(e,o={}){let t=B(e,o);return!t.dati||t.errori.some(i=>i.codice!=="luogo.sconosciuto")?{ok:!1,errori:t.errori}:{ok:!0,...t.dati,avvisi:[...t.errori,...t.avvisi]}}function ae(e,o){let t=L(U(e)),i=o.dataNascita,n=String(i.giorno+(o.sesso==="F"?40:0)).padStart(2,"0");return[["cognome",C(o.cognome),t.slice(0,3)],["nome",S(o.nome),t.slice(3,6)],["anno",String(i.anno%100).padStart(2,"0"),t.slice(6,8)],["mese",f[i.mese-1]??"",t[8]],["giorno",n,t.slice(9,11)],["luogo",o.codiceLuogo.toUpperCase(),t.slice(11,15)]].filter(([,s,r])=>s!==r).map(([s,r,c])=>({campo:s,atteso:r,trovato:c}))}function re(e){let o=(e??"").trim(),t=/^(\d{1,2})[/.\-](\d{1,2})[/.\-](\d{4})$/.exec(o),i;return t?i={giorno:+t[1],mese:+t[2],anno:+t[3]}:(t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(o))&&(i={anno:+t[1],mese:+t[2],giorno:+t[3]}),i&&p(i)?i:void 0}var ne=["The first 6 characters (surname and name) must be letters","The 7th and 8th characters (year) must be digits","The 9th character (month) must be a letter","The 10th and 11th characters (day) must be digits","The 12th character (place of birth) must be a letter","Characters 13 to 15 (place of birth) must be digits","The last character (check character) must be a letter"];function se(e){let o=e.valori??{},t=e.codice.split(".")[0]==="cognome"?"surname":"first name";switch(e.codice){case"cognome.vuoto":case"nome.vuoto":return`Enter the ${t}.`;case"cognome.caratteri":case"nome.caratteri":return o.motivo==="nessuna-lettera"?`The ${t} must contain at least one letter.`:`The ${t} can only contain letters, spaces, apostrophes and hyphens.`;case"sesso.vuoto":return"Choose the sex.";case"data.non-valida":return o.max!==void 0?`This date does not exist: month ${String(o.mese).padStart(2,"0")} has at most ${o.max} days.`:"The date of birth does not exist. Check the day, month and year.";case"data.futura":return"The date of birth cannot be in the future.";case"luogo.vuoto":return"Choose the Italian comune or the foreign country of birth.";case"luogo.sconosciuto":return o.codice?`The place of birth code (${o.codice}) does not exist in the official lists of comuni and foreign countries.`:"We cannot find this comune or country in the official data.";case"luogo.fuori-periodo":return o.codice?`According to the official data, code ${o.codice} (${o.nome}) was not valid on the date of birth.`:"According to the official data, this place did not exist with this code on the date of birth. Check the comune you chose.";case"codice.vuoto":return"Enter a codice fiscale.";case"codice.lunghezza":return`A codice fiscale has 16 characters: you entered ${o.n}.`;case"codice.caratteri":return"A codice fiscale contains only letters and digits.";case"codice.struttura":{let i=ne[Number(o.gruppo)];return i?`${i}: you wrote "${o.scritto}".`:"The structure of the code is not valid."}case"controllo.errato":return`The check character (the last one) should be ${o.atteso}, not ${o.trovato}. There is probably a typo.`;case"omocodia.ordine":return"The letters replacing digits do not follow the official order (right to left). A code like this is unusual: check it with the Agenzia delle Entrate.";case"mese.errato":return`The month letter (9th character) is ${o.lettera}, but the valid letters are ${f.split("").join(", ")}.`;case"giorno.errato":return`The day (10th and 11th characters) is ${o.giorno}: it must be between 01 and 31 for men and between 41 and 71 for women.`;default:return e.messaggio}}function ce(e){let o=e.nomeEn||e.nome,t=e.provincia?`${o} (${e.provincia})`:o;if(!e.al)return t;let i=e.al.slice(0,4);return e.fine==="rinominato"?`${t} \u2013 name used until ${i}`:e.tipo==="comune"?`${t} \u2013 comune merged or abolished in ${i}`:`${t} \u2013 ceased in ${i}`}export{f as MESI,O as OMOCODIA_LETTERE,x as OMOCODIA_POSIZIONI,K as calcola,h as carattereControllo,j as chiaveRicerca,L as codiceBase,C as codificaCognome,M as codificaData,S as codificaNome,ae as confrontaConDati,q as creaIndice,m as dataIso,Y as etichettaLuogo,ce as etichettaLuogoInglese,A as giorniNelMese,ie as inverso,w as isBisestile,p as isDataValida,D as luogoAllaData,se as messaggioInglese,U as normalizzaCodice,N as normalizzaNome,z as omocodici,re as parseData,E as posizioniOmocodiche,F as validaDati,B as verifica};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DataNascita, PlaceIndex, Problema, Sesso } from './types.js';
|
|
2
|
+
export interface DatiAnagrafici {
|
|
3
|
+
cognome: string;
|
|
4
|
+
nome: string;
|
|
5
|
+
sesso: Sesso;
|
|
6
|
+
dataNascita: DataNascita;
|
|
7
|
+
/** Codice catastale of the comune or Z code of the foreign state. */
|
|
8
|
+
codiceLuogo: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OpzioniCalcolo {
|
|
11
|
+
/** If given, the place code is checked against the official data. */
|
|
12
|
+
luoghi?: PlaceIndex;
|
|
13
|
+
/** "Today", used to reject future dates. Defaults to the current date. */
|
|
14
|
+
oggi?: Date;
|
|
15
|
+
}
|
|
16
|
+
export interface Parti {
|
|
17
|
+
cognome: string;
|
|
18
|
+
nome: string;
|
|
19
|
+
anno: string;
|
|
20
|
+
mese: string;
|
|
21
|
+
giorno: string;
|
|
22
|
+
luogo: string;
|
|
23
|
+
controllo: string;
|
|
24
|
+
}
|
|
25
|
+
export type RisultatoCalcolo = {
|
|
26
|
+
ok: true;
|
|
27
|
+
codice: string;
|
|
28
|
+
parti: Parti;
|
|
29
|
+
omocodici: string[];
|
|
30
|
+
avvisi: Problema[];
|
|
31
|
+
} | {
|
|
32
|
+
ok: false;
|
|
33
|
+
errori: Problema[];
|
|
34
|
+
};
|
|
35
|
+
export declare function oggiIso(oggi?: Date): string;
|
|
36
|
+
/** Validates the personal data and returns Italian error messages. */
|
|
37
|
+
export declare function validaDati(dati: DatiAnagrafici, opz?: OpzioniCalcolo): {
|
|
38
|
+
errori: Problema[];
|
|
39
|
+
avvisi: Problema[];
|
|
40
|
+
};
|
|
41
|
+
/** Computes the codice fiscale. Never throws on bad input: returns errors. */
|
|
42
|
+
export declare function calcola(dati: DatiAnagrafici, opz?: OpzioniCalcolo): RisultatoCalcolo;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core codice fiscale rules (DM 12/03/1974, DM 23/12/1976 for omocodia).
|
|
3
|
+
* Pure functions, no data dependencies.
|
|
4
|
+
*/
|
|
5
|
+
import type { DataNascita, Sesso } from './types.js';
|
|
6
|
+
export declare const MESI = "ABCDEHLMPRST";
|
|
7
|
+
export declare const OMOCODIA_LETTERE = "LMNPQRSTUV";
|
|
8
|
+
/** 0-based positions of the digits replaced for omocodia, right to left. */
|
|
9
|
+
export declare const OMOCODIA_POSIZIONI: readonly [14, 13, 12, 10, 9, 7, 6];
|
|
10
|
+
/**
|
|
11
|
+
* Normalizes a surname or name: removes diacritics (Nicolò -> NICOLO),
|
|
12
|
+
* apostrophes, spaces, hyphens and anything that is not A-Z.
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizzaNome(s: string): string;
|
|
15
|
+
/** Three letters for the surname: consonants, then vowels, then X. */
|
|
16
|
+
export declare function codificaCognome(cognome: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Three letters for the first name. With 4+ consonants the 1st, 3rd and 4th
|
|
19
|
+
* are used; otherwise as for the surname.
|
|
20
|
+
*/
|
|
21
|
+
export declare function codificaNome(nome: string): string;
|
|
22
|
+
export declare function isBisestile(anno: number): boolean;
|
|
23
|
+
export declare function giorniNelMese(anno: number, mese: number): number;
|
|
24
|
+
export declare function isDataValida(d: DataNascita): boolean;
|
|
25
|
+
export declare function dataIso(d: DataNascita): string;
|
|
26
|
+
/** Five characters for date and sex: YY + month letter + DD (+40 if female). */
|
|
27
|
+
export declare function codificaData(d: DataNascita, sesso: Sesso): string;
|
|
28
|
+
/** Control character for the first 15 characters. */
|
|
29
|
+
export declare function carattereControllo(primi15: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the 7 omocodia variants of a base code (levels 1..7), replacing
|
|
32
|
+
* digits right to left with LMNPQRSTUV and recomputing the control char.
|
|
33
|
+
*/
|
|
34
|
+
export declare function omocodici(codice: string): string[];
|
|
35
|
+
/**
|
|
36
|
+
* Converts any omocode back to the base code (all digits), with the
|
|
37
|
+
* control char recomputed. Input must have the 16-char shape.
|
|
38
|
+
*/
|
|
39
|
+
export declare function codiceBase(codice: string): string;
|
|
40
|
+
/** Positions (0-based) that carry an omocodia letter. */
|
|
41
|
+
export declare function posizioniOmocodiche(codice: string): number[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type DatasetLuoghi, type IndiceLuoghi } from './luoghi.js';
|
|
2
|
+
export declare const datasetComuni: DatasetLuoghi;
|
|
3
|
+
export declare const datasetStati: DatasetLuoghi;
|
|
4
|
+
export declare const metaDati: {
|
|
5
|
+
generato: string;
|
|
6
|
+
fonti: {
|
|
7
|
+
"anpr-comuni": {
|
|
8
|
+
nome: string;
|
|
9
|
+
url: string;
|
|
10
|
+
pagina: string;
|
|
11
|
+
file: string;
|
|
12
|
+
scaricato: string;
|
|
13
|
+
lastModified: string;
|
|
14
|
+
sha256: string;
|
|
15
|
+
bytes: number;
|
|
16
|
+
};
|
|
17
|
+
"istat-comuni": {
|
|
18
|
+
nome: string;
|
|
19
|
+
url: string;
|
|
20
|
+
pagina: string;
|
|
21
|
+
file: string;
|
|
22
|
+
scaricato: string;
|
|
23
|
+
lastModified: string;
|
|
24
|
+
sha256: string;
|
|
25
|
+
bytes: number;
|
|
26
|
+
};
|
|
27
|
+
"anpr-stati": {
|
|
28
|
+
nome: string;
|
|
29
|
+
url: string;
|
|
30
|
+
pagina: string;
|
|
31
|
+
file: string;
|
|
32
|
+
scaricato: string;
|
|
33
|
+
lastModified: string;
|
|
34
|
+
sha256: string;
|
|
35
|
+
bytes: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
comuni: {
|
|
39
|
+
righe: number;
|
|
40
|
+
codici: number;
|
|
41
|
+
attivi: number;
|
|
42
|
+
scartatiSenzaCodice: number;
|
|
43
|
+
confrontoIstat: {
|
|
44
|
+
soloIstat: string[];
|
|
45
|
+
soloAnprAttivi: string[];
|
|
46
|
+
nomeDiverso: string[];
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
stati: {
|
|
50
|
+
righe: number;
|
|
51
|
+
};
|
|
52
|
+
limiti: string[];
|
|
53
|
+
};
|
|
54
|
+
/** Shared index over all comuni and Stati esteri (built on first use). */
|
|
55
|
+
export declare function indiceUfficiale(): IndiceLuoghi;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Luogo, Problema } from './types.js';
|
|
2
|
+
/** English message for an engine problem. Unknown codes fall back to the Italian text. */
|
|
3
|
+
export declare function messaggioInglese(p: Problema): string;
|
|
4
|
+
/** English label: "Roma (RM)", "Germany", "… – ceased in 1928". */
|
|
5
|
+
export declare function etichettaLuogoInglese(l: Luogo): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { DataNascita, Luogo, PlaceIndex, Problema, Sesso } from './types.js';
|
|
2
|
+
export { MESI, OMOCODIA_LETTERE, OMOCODIA_POSIZIONI, carattereControllo, codiceBase, codificaCognome, codificaData, codificaNome, dataIso, giorniNelMese, isBisestile, isDataValida, normalizzaNome, omocodici, posizioniOmocodiche, } from './core.js';
|
|
3
|
+
export { calcola, validaDati } from './calcola.js';
|
|
4
|
+
export type { DatiAnagrafici, OpzioniCalcolo, Parti, RisultatoCalcolo } from './calcola.js';
|
|
5
|
+
export { verifica, inverso, confrontaConDati, normalizzaCodice } from './verifica.js';
|
|
6
|
+
export type { Confronto, DatiInversi, OpzioniVerifica, RisultatoInverso, RisultatoVerifica, } from './verifica.js';
|
|
7
|
+
export { creaIndice, chiaveRicerca, etichettaLuogo, luogoAllaData } from './luoghi.js';
|
|
8
|
+
export type { DatasetLuoghi, IndiceLuoghi, OpzioniRicerca, RigaLuogo } from './luoghi.js';
|
|
9
|
+
export { parseData } from './parse.js';
|
|
10
|
+
export { messaggioInglese, etichettaLuogoInglese } from './en.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Luogo, PlaceIndex } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compact row as stored in comuni.json / stati.json:
|
|
4
|
+
* [codice, nome, provincia, dal, al, altriNomi?]. Dates are "YYYY-MM-DD";
|
|
5
|
+
* `dal` is "" if unknown and `al` is "" while the place is still valid.
|
|
6
|
+
* `altriNomi` holds extra search names separated by "|". Foreign states may
|
|
7
|
+
* add a 7th item: the official English name (also searchable).
|
|
8
|
+
*/
|
|
9
|
+
export type RigaLuogo = [string, string, string, string, string, string?, string?];
|
|
10
|
+
export interface DatasetLuoghi {
|
|
11
|
+
/** Dataset format version. */
|
|
12
|
+
v: number;
|
|
13
|
+
tipo: 'comune' | 'stato';
|
|
14
|
+
/** Where the data comes from and when it was downloaded. */
|
|
15
|
+
fonti: {
|
|
16
|
+
nome: string;
|
|
17
|
+
url: string;
|
|
18
|
+
scaricato: string;
|
|
19
|
+
aggiornato?: string;
|
|
20
|
+
}[];
|
|
21
|
+
righe: RigaLuogo[];
|
|
22
|
+
}
|
|
23
|
+
/** Picks the period valid on an ISO date, if any. */
|
|
24
|
+
export declare function luogoAllaData(periodi: Luogo[], iso: string): Luogo | undefined;
|
|
25
|
+
/** Lowercase, no accents, no punctuation: used for search. */
|
|
26
|
+
export declare function chiaveRicerca(s: string): string;
|
|
27
|
+
export interface OpzioniRicerca {
|
|
28
|
+
/** ISO birth date: places valid on that day are listed first. */
|
|
29
|
+
data?: string;
|
|
30
|
+
/** With `data`, drop places not valid on that day. */
|
|
31
|
+
soloValidi?: boolean;
|
|
32
|
+
/** Max results (default 10). */
|
|
33
|
+
limite?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface IndiceLuoghi extends PlaceIndex {
|
|
36
|
+
/** Autocomplete search by name (accent and case insensitive). */
|
|
37
|
+
cerca(testo: string, opz?: OpzioniRicerca): Luogo[];
|
|
38
|
+
/** Number of periods in the index. */
|
|
39
|
+
readonly totale: number;
|
|
40
|
+
}
|
|
41
|
+
/** Builds a place index from one or more datasets (comuni, stati). */
|
|
42
|
+
export declare function creaIndice(...dataset: DatasetLuoghi[]): IndiceLuoghi;
|
|
43
|
+
/** "Roma (RM)" for comuni, "Francia" for states; adds "soppresso" info. */
|
|
44
|
+
export declare function etichettaLuogo(l: Luogo): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DataNascita } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses "gg/mm/aaaa" (also with "-" or "." separators) or ISO "aaaa-mm-gg".
|
|
4
|
+
* Returns undefined if the text is not a real calendar date.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseData(testo: string): DataNascita | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Sex as encoded in the codice fiscale. */
|
|
2
|
+
export type Sesso = 'M' | 'F';
|
|
3
|
+
/** A calendar date without time zone. Months are 1-12. */
|
|
4
|
+
export interface DataNascita {
|
|
5
|
+
anno: number;
|
|
6
|
+
mese: number;
|
|
7
|
+
giorno: number;
|
|
8
|
+
}
|
|
9
|
+
/** A place of birth: an Italian comune or a foreign state (Z code). */
|
|
10
|
+
export interface Luogo {
|
|
11
|
+
/** Codice catastale / Belfiore, e.g. "H501" (Roma) or "Z404" (USA). */
|
|
12
|
+
codice: string;
|
|
13
|
+
/** Display name, e.g. "Roma". */
|
|
14
|
+
nome: string;
|
|
15
|
+
/** Province code for comuni, e.g. "RM". Empty for foreign states. */
|
|
16
|
+
provincia: string;
|
|
17
|
+
/** "comune" or "stato". */
|
|
18
|
+
tipo: 'comune' | 'stato';
|
|
19
|
+
/** First valid day, ISO "YYYY-MM-DD". Empty if unknown. */
|
|
20
|
+
dal: string;
|
|
21
|
+
/** Last valid day, ISO "YYYY-MM-DD". Empty while still valid. */
|
|
22
|
+
al: string;
|
|
23
|
+
/**
|
|
24
|
+
* Set when `al` is not empty: "soppresso" if the code is no longer in use,
|
|
25
|
+
* "rinominato" if the same code continues under another name.
|
|
26
|
+
*/
|
|
27
|
+
fine?: 'soppresso' | 'rinominato';
|
|
28
|
+
/** Official English name (foreign states only, from ANPR Tabella 2), when it differs. */
|
|
29
|
+
nomeEn?: string;
|
|
30
|
+
}
|
|
31
|
+
/** An issue found while validating input or a code. Messages are in Italian. */
|
|
32
|
+
export interface Problema {
|
|
33
|
+
/** Stable machine id, e.g. "cognome.vuoto". */
|
|
34
|
+
codice: string;
|
|
35
|
+
/** Field the problem refers to, if any. */
|
|
36
|
+
campo?: string;
|
|
37
|
+
/** Human-readable Italian message ("tu" form). */
|
|
38
|
+
messaggio: string;
|
|
39
|
+
/** Values used in the message, so it can be rewritten in another language (see `messaggioInglese`). */
|
|
40
|
+
valori?: Record<string, string | number>;
|
|
41
|
+
}
|
|
42
|
+
/** Minimal place lookup used by the engine. The data module provides one. */
|
|
43
|
+
export interface PlaceIndex {
|
|
44
|
+
/** All periods recorded for a code (empty if unknown). */
|
|
45
|
+
perCodice(codice: string): Luogo[];
|
|
46
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type DatiAnagrafici } from './calcola.js';
|
|
2
|
+
import type { DataNascita, Luogo, PlaceIndex, Problema, Sesso } from './types.js';
|
|
3
|
+
export interface OpzioniVerifica {
|
|
4
|
+
luoghi?: PlaceIndex;
|
|
5
|
+
/** "Today" for age and century choice. Defaults to now. */
|
|
6
|
+
oggi?: Date;
|
|
7
|
+
}
|
|
8
|
+
export declare function normalizzaCodice(input: string): string;
|
|
9
|
+
export interface DatiInversi {
|
|
10
|
+
sesso: Sesso;
|
|
11
|
+
/** Most likely birth date (see `dateCandidate`). */
|
|
12
|
+
dataNascita: DataNascita;
|
|
13
|
+
/** All valid interpretations of the 2-digit year, most likely first. */
|
|
14
|
+
dateCandidate: DataNascita[];
|
|
15
|
+
/** Age in full years on `oggi` for `dataNascita`. */
|
|
16
|
+
eta: number;
|
|
17
|
+
codiceLuogo: string;
|
|
18
|
+
/** Place valid at the birth date, if data was provided and it matches. */
|
|
19
|
+
luogo?: Luogo;
|
|
20
|
+
/** Every period recorded for the place code (empty without data). */
|
|
21
|
+
luoghiPossibili: Luogo[];
|
|
22
|
+
/** Base code if this is an omocode, else the code itself. */
|
|
23
|
+
codiceBase: string;
|
|
24
|
+
/** 0 = not omocode, 1..7 = number of substituted digits. */
|
|
25
|
+
livelloOmocodia: number;
|
|
26
|
+
}
|
|
27
|
+
export type RisultatoInverso = ({
|
|
28
|
+
ok: true;
|
|
29
|
+
} & DatiInversi & {
|
|
30
|
+
avvisi: Problema[];
|
|
31
|
+
}) | {
|
|
32
|
+
ok: false;
|
|
33
|
+
errori: Problema[];
|
|
34
|
+
};
|
|
35
|
+
export interface RisultatoVerifica {
|
|
36
|
+
valido: boolean;
|
|
37
|
+
codice: string;
|
|
38
|
+
errori: Problema[];
|
|
39
|
+
avvisi: Problema[];
|
|
40
|
+
/** Decoded data, when the structure allows decoding. */
|
|
41
|
+
dati?: DatiInversi;
|
|
42
|
+
}
|
|
43
|
+
/** Full structural + data check. Explains in Italian what is wrong. */
|
|
44
|
+
export declare function verifica(input: string, opz?: OpzioniVerifica): RisultatoVerifica;
|
|
45
|
+
/** Decodes a code into sex, birth date, age and place. */
|
|
46
|
+
export declare function inverso(input: string, opz?: OpzioniVerifica): RisultatoInverso;
|
|
47
|
+
export interface Confronto {
|
|
48
|
+
campo: 'cognome' | 'nome' | 'anno' | 'mese' | 'giorno' | 'luogo';
|
|
49
|
+
atteso: string;
|
|
50
|
+
trovato: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Compares a code with personal data and lists the parts that differ,
|
|
54
|
+
* ignoring omocodia substitutions.
|
|
55
|
+
*/
|
|
56
|
+
export declare function confrontaConDati(input: string, dati: DatiAnagrafici): Confronto[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codicechiaro",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Italian codice fiscale engine: calcola, inverso, verifica, omocodia (DM 12/03/1974), with official comuni and Stati esteri data.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "CodiceChiaro",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/zaingifthub/codicechiaro-js.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/zaingifthub/codicechiaro-js#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/zaingifthub/codicechiaro-js/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"codice fiscale",
|
|
18
|
+
"codice-fiscale",
|
|
19
|
+
"italian tax code",
|
|
20
|
+
"codici catastali",
|
|
21
|
+
"omocodia",
|
|
22
|
+
"validation",
|
|
23
|
+
"italy",
|
|
24
|
+
"anpr",
|
|
25
|
+
"istat"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/types/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./data": {
|
|
38
|
+
"types": "./dist/types/data.d.ts",
|
|
39
|
+
"import": "./dist/data.js"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"scripts": {
|
|
45
|
+
"data": "node scripts/build-data.mjs",
|
|
46
|
+
"data:download": "node scripts/build-data.mjs --download",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"build": "node scripts/bundle.mjs",
|
|
49
|
+
"test": "tsc --noEmit && vitest run",
|
|
50
|
+
"check": "npm test && npm run build && node scripts/pack-check.mjs",
|
|
51
|
+
"prepublishOnly": "npm run check"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^26.6.11",
|
|
55
|
+
"esbuild": "^0.28.2",
|
|
56
|
+
"exceljs": "^4.4.0",
|
|
57
|
+
"typescript": "^7.0.2",
|
|
58
|
+
"vitest": "^5.1.2"
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"dist",
|
|
62
|
+
"README.md",
|
|
63
|
+
"LICENSE"
|
|
64
|
+
],
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
}
|
|
68
|
+
}
|