codicechiaro 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodiceChiaro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # codicechiaro
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Italian **codice fiscale** in JavaScript and TypeScript: calculate, decode, check and handle omocodia,
4
+ with the **official** lists of Italian comuni (also ceased and renamed ones, with their validity dates)
5
+ and foreign states. Zero dependencies, runs in the browser and in Node. Nothing is ever sent anywhere.
6
+
7
+ > *Calcolo, inverso e verifica del codice fiscale con i dati ufficiali ANPR e ISTAT. È il motore del
8
+ > calcolatore CodiceChiaro.*
9
+
10
+ ```sh
11
+ npm install codicechiaro
12
+ ```
13
+
14
+ ## Quick start
15
+
16
+ ```ts
17
+ import { calcola, verifica, inverso, parseData, messaggioInglese } from 'codicechiaro';
18
+ import { indiceUfficiale } from 'codicechiaro/data'; // official places (~140 KB gzip): load it lazily in browsers
19
+
20
+ const luoghi = indiceUfficiale();
21
+ const [roma] = luoghi.cerca('Roma'); // also "Germania" or "Germany", "Roma (RM)", ceased comuni…
22
+
23
+ const r = calcola(
24
+ { cognome: 'Rossi', nome: 'Mario', sesso: 'M', dataNascita: parseData('01/01/1980')!, codiceLuogo: roma.codice },
25
+ { luoghi },
26
+ );
27
+ if (r.ok) {
28
+ r.codice; // 'RSSMRA80A01H501U'
29
+ r.parti; // { cognome: 'RSS', nome: 'MRA', anno: '80', mese: 'A', giorno: '01', luogo: 'H501', controllo: 'U' }
30
+ r.omocodici; // the 7 official omocodia variants
31
+ }
32
+
33
+ const v = verifica('RSSMRA80A01H501X', { luoghi });
34
+ v.valido; // false
35
+ v.errori[0].messaggio; // "Il carattere di controllo (l'ultimo) dovrebbe essere U, non X. …"
36
+ messaggioInglese(v.errori[0]); // "The check character (the last one) should be U, not X. …"
37
+
38
+ const d = inverso('RSSMRA80A01H501U', { luoghi });
39
+ // d.ok && d.sesso === 'M', d.dataNascita, d.eta, d.luogo (Roma), d.dateCandidate (other century)
40
+ ```
41
+
42
+ ## API
43
+
44
+ | Function | What it does |
45
+ | --- | --- |
46
+ | `calcola(dati, { luoghi?, oggi? })` | Code, colour-group parts, 7 omocodia variants; validation errors and warnings |
47
+ | `validaDati(dati, opz)` | Only the validation (field by field), for live forms |
48
+ | `verifica(codice, { luoghi?, oggi? })` | Format, check character, month/day, real date, place exists and was valid on the birth date, omocodia; explains what is wrong |
49
+ | `inverso(codice, { luoghi?, oggi? })` | Sex, birth date (with the other possible century), age, comune or foreign state |
50
+ | `confrontaConDati(codice, dati)` | Which parts of a code do not match the given person |
51
+ | `omocodici`, `codiceBase` | Omocodia variants (right to left, `LMNPQRSTUV`) and back |
52
+ | `creaIndice`, `cerca`, `perCodice` | Place index and autocomplete search (accents and case insensitive) |
53
+ | `etichettaLuogo`, `etichettaLuogoInglese` | "Bussana (IM) – soppresso nel 1928" / "… – comune merged or abolished in 1928" |
54
+ | `messaggioInglese(problema)` | Any engine error or warning in English |
55
+ | `parseData` | "gg/mm/aaaa" (also `-` `.`) or ISO "aaaa-mm-gg", only real calendar dates |
56
+
57
+ Errors are returned, never thrown. Each one has a stable `codice` (e.g. `controllo.errato`), the field,
58
+ an Italian message in the "tu" form and the `valori` used in it.
59
+
60
+ ## Data
61
+
62
+ `codicechiaro/data` contains, as compact JSON, the files below. Each dataset records its
63
+ source URL and download date (`datasetComuni.fonti`, `metaDati`). Codes are never written by hand.
64
+
65
+ - **ANPR – Archivio storico dei comuni** (Ministero dell'Interno): every comune since 1861 with its
66
+ codice catastale and validity dates, including soppressi.
67
+ - **ISTAT – Elenco dei comuni italiani**: official names, cross-check of the current codes.
68
+ - **ANPR – Tabella 2, Stati esteri**: Z codes of foreign states, with the official English names.
69
+
70
+ Known limitation: Tabella 2 lists current states only, so ceased states (USSR, Yugoslavia,
71
+ Czechoslovakia, …) are not included yet.
72
+
73
+ Building from source: `npm run data` rebuilds `data/generated/*.json` from `data/sources/`;
74
+ `npm run data:download` fetches fresh copies first and updates `data/sources/manifest.json`
75
+ (URL, date, Last-Modified, SHA-256).
76
+
77
+ ## Quality
78
+
79
+ - 90+ Vitest tests, including real codes and the official omocodia rules (DM 12/03/1974, DM 23/12/1976).
80
+ - The engine without data is under 15 KB gzip (the build fails above that).
81
+ - `npm run check`: tests, build, then `npm pack` + install + import + `nodenext` type check.
82
+
83
+ ## License
84
+
85
+ Code: MIT (see `LICENSE`). The bundled data comes from ANPR (Ministero dell'Interno) and ISTAT and
86
+ keeps the terms of those sources.
87
+
88
+ This library is not an official tool. The only valid codice fiscale is the one issued by the Agenzia
89
+ delle Entrate.
@@ -0,0 +1 @@
1
+ function L(n,r){return n.find(i=>(!i.dal||i.dal<=r)&&(!i.al||r<=i.al))}function p(n){return n.normalize("NFD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/\([^)]*\)/g," ").replace(/[^a-z0-9]+/g," ").trim()}function h(...n){let r=[],i=new Map,m=0;for(let a of n)for(let[t,s,l,g,f,u,o]of a.righe){let e={codice:t,nome:s,provincia:l,tipo:a.tipo,dal:g,al:f};if(o&&(e.nomeEn=o),m++,r.push({l:e,k:p(s)}),u)for(let d of u.split("|"))r.push({l:e,k:p(d)});o&&r.push({l:e,k:p(o)});let c=i.get(t);c?c.push(e):i.set(t,[e])}for(let a of i.values())for(let t of a){if(!t.al)continue;let s=a.some(l=>l!==t&&l.nome!==t.nome&&(!l.al||l.al>t.al));t.fine=s?"rinominato":"soppresso"}return{totale:m,perCodice(a){return i.get(a.trim().toUpperCase())??[]},cerca(a,t={}){let s=p(a);if(!s)return[];let l=t.limite??10,g=[];for(let{l:o,k:e}of r){let c;if(e===s)c=0;else if(e.startsWith(s))c=1;else if(e.includes(" "+s))c=2;else continue;if(t.data){if(o.dal&&o.dal>t.data||o.al&&t.data>o.al){if(t.soloValidi)continue;c+=6}}else o.al&&(c+=3);g.push({l:o,punti:c})}g.sort((o,e)=>o.punti-e.punti||o.l.nome.length-e.l.nome.length||o.l.nome.localeCompare(e.l.nome,"it")||(e.l.al||"9999").localeCompare(o.l.al||"9999"));let f=new Set,u=[];for(let{l:o}of g){let e=o.codice+"|"+o.nome;if(!f.has(e)&&(f.add(e),u.push(o),u.length>=l))break}return u}}}function x(n){let r=n.provincia?`${n.nome} (${n.provincia})`:n.nome;if(!n.al)return r;let i=n.al.slice(0,4);return n.fine==="rinominato"?`${r} \u2013 denominazione fino al ${i}`:n.tipo==="comune"?`${r} \u2013 soppresso nel ${i}`:`${r} \u2013 cessato nel ${i}`}export{L as a,p as b,h as c,x as d};