From e9c7d5dd7236ae3ec50d54e8bdf0f043ce32e612 Mon Sep 17 00:00:00 2001 From: vitomanuguerra Date: Thu, 4 Sep 2025 09:53:12 +0200 Subject: [PATCH] feat: export COMUNI and PROVINCE data as public constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exposes the internal municipality (comuni) and province data as public exports to allow external usage for validation, mapping, and UI components. Changes: - Add COMUNI_LIST export with user-friendly structure (belfioreCode, province, name, active) - Export PROVINCE mapping as static property on CodiceFiscale class - Add TypeScript definitions for IComuneData and IProvinceData interfaces - Support both CommonJS and ES6 module imports This allows developers to: - Import data directly: import { COMUNI, PROVINCE } from 'codice-fiscale-js' - Access via class: CodiceFiscale.COMUNI and CodiceFiscale.PROVINCE - Reuse official municipality data without duplication - Build forms, selectors, and validation services with type safety Fixes: Resolves feature request for exporting comuni and province data 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/codice-fiscale.js | 4 ++++ src/lista-comuni.js | 8 ++++++++ types/codice-fiscale.d.ts | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/codice-fiscale.js b/src/codice-fiscale.js index 3839e84..11271bc 100755 --- a/src/codice-fiscale.js +++ b/src/codice-fiscale.js @@ -1,6 +1,8 @@ import { Comune } from './comune' import { CHECK_CODE_CHARS, CHECK_CODE_EVEN, CHECK_CODE_ODD, MONTH_CODES, NUMERIC_POS, OMOCODIA_TABLE, OMOCODIA_TABLE_INVERSE } from './constants' import { extractConsonants, extractVowels, getValidDate, birthplaceFields, getAllSubsets } from './utils' +import { COMUNI_LIST } from './lista-comuni' +import { PROVINCE } from './lista-province' class CodiceFiscale { get day () { @@ -250,4 +252,6 @@ class CodiceFiscale { CodiceFiscale.utils = { birthplaceFields: birthplaceFields } +CodiceFiscale.COMUNI = COMUNI_LIST +CodiceFiscale.PROVINCE = PROVINCE module.exports = CodiceFiscale; \ No newline at end of file diff --git a/src/lista-comuni.js b/src/lista-comuni.js index 5391f57..7246748 100644 --- a/src/lista-comuni.js +++ b/src/lista-comuni.js @@ -13655,3 +13655,11 @@ export const COMUNI = [ ["A001","PD","ABANO BAGNI",0], ["M205","MI","ZUNICO",0], ["M206","CA","ZURI",0], ] + +// Export a more user-friendly structure for external consumption +export const COMUNI_LIST = COMUNI.map(([cc, prov, nome, active]) => ({ + belfioreCode: cc, + province: prov, + name: nome, + active: active === 1 +})) diff --git a/types/codice-fiscale.d.ts b/types/codice-fiscale.d.ts index a4cf424..76f40eb 100644 --- a/types/codice-fiscale.d.ts +++ b/types/codice-fiscale.d.ts @@ -3,6 +3,17 @@ import { birthplaceFields } from "./utils"; export type Gender = "F" | "M"; +export interface IComuneData { + belfioreCode: string; + province: string; + name: string; + active: boolean; +} + +export interface IProvinceData { + [key: string]: string; +} + export interface ICodiceFiscaleObject { name: string; surname: string; @@ -26,6 +37,8 @@ declare class CodiceFiscale { static utils: { birthplaceFields: typeof birthplaceFields; }; + static COMUNI: IComuneData[]; + static PROVINCE: IProvinceData; birthday: Date; birthplace: Comune; name: string; @@ -55,3 +68,6 @@ declare class CodiceFiscale { } export default CodiceFiscale; +export { CodiceFiscale }; +export const COMUNI: IComuneData[]; +export const PROVINCE: IProvinceData;