├── .babelrc ├── .editorconfig ├── .github └── workflows │ └── codeql-analysis.yml ├── .gitignore ├── .vscode └── launch.json ├── LICENSE-CC-BY-SA.txt ├── dist ├── codice-fiscale-var.js ├── codice.fiscale.amd.js ├── codice.fiscale.commonjs2.js ├── codice.fiscale.umd.js └── codice.fiscale.var.js ├── docs ├── js-oop.md ├── js-static.md └── typescript.md ├── example ├── bootstrap.bundle.min.js ├── bootstrap.min.css ├── codice.fiscale.var.js ├── index.html └── jquery-3.3.1.min.js ├── package-lock.json ├── package.json ├── readme.md ├── src ├── codice-fiscale.js ├── comune.js ├── constants.js ├── lista-comuni.js ├── lista-province.js └── utils.js ├── tests ├── bug.spec.js ├── compute.spec.js ├── computeInverse.spec.js ├── comune.spec.js ├── index.spec.js ├── inverse.spec.js └── omocodie.spec.js ├── tsconfig.json ├── types ├── codice-fiscale.d.ts ├── comune.d.ts ├── constants.d.ts ├── geo-data.d.ts └── utils.d.ts ├── update_comuni.py ├── utils.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["@babel/preset-env", { 4 | "debug": true, 5 | "modules": "cjs" 6 | }] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | 2 | [*] 3 | indent_style = space 4 | 5 | [*.{.json,js}] 6 | indent_size = 2 7 | 8 | [*.ts] 9 | indent_size = 4 -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '20 9 * * 3' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript', 'python' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v2 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v1 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v1 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v1 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # intellij files 33 | .idea 34 | 35 | # Optional REPL history 36 | .node_repl_history 37 | .DS_Store 38 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | 5 | { 6 | "name": "Debug Jest Tests", 7 | "type": "node", 8 | "request": "launch", 9 | "runtimeArgs": [ 10 | "--inspect-brk", 11 | "${workspaceRoot}/node_modules/jest/bin/jest.js", 12 | "--runInBand" 13 | ], 14 | "console": "integratedTerminal", 15 | "internalConsoleOptions": "neverOpen", 16 | "port": 9229 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /LICENSE-CC-BY-SA.txt: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public 411 | licenses. Notwithstanding, Creative Commons may elect to apply one of 412 | its public licenses to material it publishes and in those instances 413 | will be considered the “Licensor.” The text of the Creative Commons 414 | public licenses is dedicated to the public domain under the CC0 Public 415 | Domain Dedication. Except for the limited purpose of indicating that 416 | material is shared under a Creative Commons public license or as 417 | otherwise permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the 425 | public licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. 428 | -------------------------------------------------------------------------------- /docs/js-oop.md: -------------------------------------------------------------------------------- 1 | # Javascript 2 | Create and compute 3 | ------- 4 | 5 | Compute a codice fiscale given: 6 | 7 | - Name (String) 8 | - Surname (String) 9 | - Gender (String) ["M","F"] 10 | - Birthday day (Number) 11 | - Birthday month (Number) 12 | - Birthday year (Number) 13 | - Place of birth (String) 14 | - Province of birth (String) 15 | 16 | ```js 17 | var cf = new CodiceFiscale({ 18 | name: "Enzo", 19 | surname: "Righi", 20 | gender: "M", 21 | day: 24, 22 | month: 7, 23 | year: 1957, 24 | birthplace: "Napoli", 25 | birthplaceProvincia: "NA" // Optional 26 | }); 27 | console.log(cf); 28 | ``` 29 | Support foreign countries 30 | === 31 | Use the italian name of the foreign country (e.g. Francia, for France) as birthplace 32 | and "EE" as birthplace_provincia 33 | ```js 34 | var cf = new CodiceFiscale({ 35 | name: "Enzo", 36 | surname: "Righi", 37 | gender: "M", 38 | day: 24, 39 | month: 7, 40 | year: 1957, 41 | birthplace: "Francia", 42 | birthplaceProvincia: "EE" 43 | }); 44 | console.log(cf); 45 | ``` 46 | ---------- 47 | Inverse Computation 48 | ------- 49 | Get a person data for a given Codice Fiscale. Throws an exeption if the code provided as argument is invalid. 50 | ```js 51 | var cf = new CodiceFiscale("RGHNZE10L24F839E"); 52 | console.log(cf.toJSON()); 53 | /** 54 | OUTPUT 55 | { 56 | name: "NZE", 57 | surname: "RGH", 58 | gender: "M", 59 | day: 24, 60 | month: 7, 61 | year: 2010, 62 | birthplace: "NAPOLI", 63 | birthplaceProvincia: "NA" 64 | } 65 | */ 66 | ``` 67 | Or you can access reversed attribute via instance properties: 68 | ```js 69 | var cf = new CodiceFiscale("RGHNZE10L24F839E"); 70 | console.log(cf.toJSON()); 71 | cf.name === "NZE"; // true 72 | cf.surname === "RGH"; // true 73 | cf.gender === "M"; // true 74 | cf.day === 24; // true 75 | cf.month === 7; // true 76 | cf.year === 2010; // true 77 | cf.birthday === new Date(2010, 6, 24,0,0,0,0); // true 78 | cf.birthplace === "NAPOLI"; // true 79 | cf.birthplaceProvincia === "NA"; // true 80 | ``` 81 | Omocodie 82 | ------- 83 | Get all the omocodie for a given Codice Fiscale. It returns an array of strings 84 | 85 | ```js 86 | var cf = new CodiceFiscale("VNDLDL10A01G410Z"); 87 | var omocodie = cf.omocodie(); 88 | ``` -------------------------------------------------------------------------------- /docs/js-static.md: -------------------------------------------------------------------------------- 1 | # Javascript v1.2.0 Deprecated 2 | 3 | 4 | Compute 5 | ------- 6 | 7 | Compute a codice fiscale given: 8 | 9 | - Name (String) 10 | - Surname (String) 11 | - Gender (String) ["M","F"] 12 | - Birthday day (Number) 13 | - Birthday month (Number) 14 | - Birthday year (Number) 15 | - Place of birth (String) 16 | - Province of birth (String) 17 | 18 | ```js 19 | var cf = CodiceFiscale.compute({ 20 | name: "Enzo", 21 | surname: "Righi", 22 | gender: "M", 23 | day: 24, 24 | month: 7, 25 | year: 1957, 26 | birthplace: "Napoli", 27 | birthplaceProvincia: "NA"}); 28 | ``` 29 | Support foreign countries 30 | === 31 | Use the italian name of the foreign country (e.g. Francia, for France) as birthplace 32 | and "EE" as birthplace_provincia 33 | ```js 34 | var cf = CodiceFiscale.compute({ 35 | name: "Enzo", 36 | surname: "Righi", 37 | gender: "M", 38 | day: 24, 39 | month: 7, 40 | year: 1957, 41 | birthplace: "Francia", 42 | birthplaceProvincia: "EE"}); 43 | ``` 44 | ---------- 45 | Inverse Computation 46 | ------- 47 | Get a person data for a given Codice Fiscale. It returns an **object**: 48 | 49 | - Name (String) 50 | - Surname (String) 51 | - Gender (String) 52 | - Birthday day (Number) 53 | - Birthday month (Number) 54 | - Birthday year [Number] 55 | - Place of birth (String) 56 | - Province of birth (String) 57 | 58 | ```js 59 | var personData = CodiceFiscale.computeInverse("RGHNZE10L24F839E"); 60 | 61 | // personData 62 | { 63 | name: "NZE", 64 | surname: "RGH", 65 | gender: "M", 66 | day: 24, 67 | month: 7 68 | year: [1910, 2010], 69 | birthplace: "NAPOLI", 70 | birthplaceProvincia: "NA" 71 | } 72 | ``` 73 | ---------- 74 | 75 | Check 76 | ------- 77 | Check if a codice fiscale is valid. It returns a **boolean** value. 78 | 79 | ```js 80 | var isValid = CodiceFiscale.check("VNDLDL10A01G410Z"); 81 | ``` 82 | ---------- 83 | Omocodie 84 | ------- 85 | Get all the omocodie for a given Codice Fiscale. It returns an array of strings 86 | 87 | ```js 88 | var omocodie = CodiceFiscale.getOmocodie("VNDLDL10A01G410Z"); 89 | ``` -------------------------------------------------------------------------------- /docs/typescript.md: -------------------------------------------------------------------------------- 1 | # TypeScript 2 | Create and compute 3 | ------- 4 | 5 | Compute a codice fiscale given: 6 | 7 | - Name (String) 8 | - Surname (String) 9 | - Gender (String) ["M","F"] 10 | - Birthday day (Number) 11 | - Birthday month (Number) 12 | - Birthday year (Number) 13 | - Place of birth (String) 14 | - Province of birth (String) 15 | 16 | ```js 17 | import CodiceFiscale from 'codice-fiscale-js'; 18 | const cf = new CodiceFiscale({ 19 | name: "Enzo", 20 | surname: "Righi", 21 | gender: "M", 22 | day: 24, 23 | month: 7, 24 | year: 1957, 25 | birthplace: "Napoli", 26 | birthplaceProvincia: "NA" // Optional 27 | }); 28 | console.log(cf); 29 | ``` 30 | Support foreign countries 31 | === 32 | Use the italian name of the foreign country (e.g. Francia, for France) as birthplace 33 | and "EE" as birthplace_provincia 34 | ```js 35 | const cf = new CodiceFiscale({ 36 | name: "Enzo", 37 | surname: "Righi", 38 | gender: "M", 39 | day: 24, 40 | month: 7, 41 | year: 1957, 42 | birthplace: "Francia", 43 | birthplaceProvincia: "EE" 44 | }); 45 | console.log(cf); 46 | ``` 47 | ---------- 48 | Inverse Computation 49 | ------- 50 | Get a person data for a given Codice Fiscale. Throws an exeption if the code provided as argument is invalid. 51 | ```js 52 | const cf = new CodiceFiscale("RGHNZE10L24F839E"); 53 | console.log(cf.toJSON()); 54 | /** 55 | OUTPUT 56 | { 57 | name: "NZE", 58 | surname: "RGH", 59 | gender: "M", 60 | day: 24, 61 | month: 7, 62 | year: 2010, 63 | birthplace: "NAPOLI", 64 | birthplaceProvincia: "NA" 65 | } 66 | */ 67 | ``` 68 | Or you can access reversed attribute via instance properties: 69 | ```js 70 | const cf = new CodiceFiscale("RGHNZE10L24F839E"); 71 | console.log(cf.toJSON()); 72 | cf.name === "NZE"; // true 73 | cf.surname === "RGH"; // true 74 | cf.gender === "M"; // true 75 | cf.day === 24; // true 76 | cf.month === 7; // true 77 | cf.year === 2010; // true 78 | cf.birthday === new Date(2010, 6, 24,0,0,0,0); // true 79 | cf.birthplace === "NAPOLI"; // true 80 | cf.birthplaceProvincia === "NA"; // true 81 | ``` 82 | Omocodie 83 | ------- 84 | Get all the omocodie for a given Codice Fiscale. It returns an array of strings 85 | 86 | ```js 87 | const cf = new CodiceFiscale("VNDLDL10A01G410Z"); 88 | const omocodie = cf.omocodie(); 89 | ``` -------------------------------------------------------------------------------- /example/bootstrap.bundle.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v4.1.3 (https://getbootstrap.com/) 3 | * Copyright 2011-2018 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */ 6 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("jquery")):"function"==typeof define&&define.amd?define(["exports","jquery"],t):t(e.bootstrap={},e.jQuery)}(this,function(e,t){"use strict";function i(e,t){for(var n=0;nthis._items.length-1||e<0))if(this._isSliding)k(this._element).one(q.SLID,function(){return t.to(e)});else{if(n===e)return this.pause(),void this.cycle();var i=n=i.clientWidth&&n>=i.clientHeight}),u=0l[e]&&!i.escapeWithReference&&(n=Math.min(u[t],l[e]-("right"===e?u.width:u.height))),Ve({},t,n)}};return c.forEach(function(e){var t=-1!==["left","top"].indexOf(e)?"primary":"secondary";u=ze({},u,f[t](e))}),e.offsets.popper=u,e},priority:["left","right","top","bottom"],padding:5,boundariesElement:"scrollParent"},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,n=t.popper,i=t.reference,r=e.placement.split("-")[0],o=Math.floor,s=-1!==["top","bottom"].indexOf(r),a=s?"right":"bottom",l=s?"left":"top",c=s?"width":"height";return n[a]o(i[a])&&(e.offsets.popper[l]=o(i[a])),e}},arrow:{order:500,enabled:!0,fn:function(e,t){var n;if(!pt(e.instance.modifiers,"arrow","keepTogether"))return e;var i=t.element;if("string"==typeof i){if(!(i=e.instance.popper.querySelector(i)))return e}else if(!e.instance.popper.contains(i))return console.warn("WARNING: `arrow.element` must be child of its popper element!"),e;var r=e.placement.split("-")[0],o=e.offsets,s=o.popper,a=o.reference,l=-1!==["left","right"].indexOf(r),c=l?"height":"width",u=l?"Top":"Left",f=u.toLowerCase(),h=l?"left":"top",d=l?"bottom":"right",p=nt(i)[c];a[d]-ps[d]&&(e.offsets.popper[f]+=a[f]+p-s[d]),e.offsets.popper=Ge(e.offsets.popper);var m=a[f]+a[c]/2-p/2,g=Pe(e.instance.popper),_=parseFloat(g["margin"+u],10),v=parseFloat(g["border"+u+"Width"],10),y=m-e.offsets.popper[f]-_-v;return y=Math.max(Math.min(s[c]-p,y),0),e.arrowElement=i,e.offsets.arrow=(Ve(n={},f,Math.round(y)),Ve(n,h,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(p,m){if(at(p.instance.modifiers,"inner"))return p;if(p.flipped&&p.placement===p.originalPlacement)return p;var g=$e(p.instance.popper,p.instance.reference,m.padding,m.boundariesElement,p.positionFixed),_=p.placement.split("-")[0],v=it(_),y=p.placement.split("-")[1]||"",E=[];switch(m.behavior){case vt:E=[_,v];break;case yt:E=_t(_);break;case Et:E=_t(_,!0);break;default:E=m.behavior}return E.forEach(function(e,t){if(_!==e||E.length===t+1)return p;_=p.placement.split("-")[0],v=it(_);var n,i=p.offsets.popper,r=p.offsets.reference,o=Math.floor,s="left"===_&&o(i.right)>o(r.left)||"right"===_&&o(i.left)o(r.top)||"bottom"===_&&o(i.top)o(g.right),c=o(i.top)o(g.bottom),f="left"===_&&a||"right"===_&&l||"top"===_&&c||"bottom"===_&&u,h=-1!==["top","bottom"].indexOf(_),d=!!m.flipVariations&&(h&&"start"===y&&a||h&&"end"===y&&l||!h&&"start"===y&&c||!h&&"end"===y&&u);(s||f||d)&&(p.flipped=!0,(s||f)&&(_=E[t+1]),d&&(y="end"===(n=y)?"start":"start"===n?"end":n),p.placement=_+(y?"-"+y:""),p.offsets.popper=ze({},p.offsets.popper,rt(p.instance.popper,p.offsets.reference,p.placement)),p=st(p.instance.modifiers,p,"flip"))}),p},behavior:"flip",padding:5,boundariesElement:"viewport"},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,n=t.split("-")[0],i=e.offsets,r=i.popper,o=i.reference,s=-1!==["left","right"].indexOf(n),a=-1===["top","left"].indexOf(n);return r[s?"left":"top"]=o[n]-(a?r[s?"width":"height"]:0),e.placement=it(t),e.offsets.popper=Ge(r),e}},hide:{order:800,enabled:!0,fn:function(e){if(!pt(e.instance.modifiers,"hide","preventOverflow"))return e;var t=e.offsets.reference,n=ot(e.instance.modifiers,function(e){return"preventOverflow"===e.name}).boundaries;if(t.bottomn.right||t.top>n.bottom||t.rightdocument.documentElement.clientHeight;!this._isBodyOverflowing&&e&&(this._element.style.paddingLeft=this._scrollbarWidth+"px"),this._isBodyOverflowing&&!e&&(this._element.style.paddingRight=this._scrollbarWidth+"px")},e._resetAdjustments=function(){this._element.style.paddingLeft="",this._element.style.paddingRight=""},e._checkScrollbar=function(){var e=document.body.getBoundingClientRect();this._isBodyOverflowing=e.left+e.right
',trigger:"hover focus",title:"",delay:0,html:!(An={AUTO:"auto",TOP:"top",RIGHT:"right",BOTTOM:"bottom",LEFT:"left"}),selector:!(Dn={animation:"boolean",template:"string",title:"(string|element|function)",trigger:"string",delay:"(number|object)",html:"boolean",selector:"(string|boolean)",placement:"(string|function)",offset:"(number|string)",container:"(string|element|boolean)",fallbackPlacement:"(string|array)",boundary:"(string|element)"}),placement:"top",offset:0,container:!1,fallbackPlacement:"flip",boundary:"scrollParent"},Nn="out",kn={HIDE:"hide"+wn,HIDDEN:"hidden"+wn,SHOW:(On="show")+wn,SHOWN:"shown"+wn,INSERTED:"inserted"+wn,CLICK:"click"+wn,FOCUSIN:"focusin"+wn,FOCUSOUT:"focusout"+wn,MOUSEENTER:"mouseenter"+wn,MOUSELEAVE:"mouseleave"+wn},xn="fade",Pn="show",Ln=".tooltip-inner",jn=".arrow",Hn="hover",Mn="focus",Fn="click",Wn="manual",Rn=function(){function i(e,t){if("undefined"==typeof Ct)throw new TypeError("Bootstrap tooltips require Popper.js (https://popper.js.org)");this._isEnabled=!0,this._timeout=0,this._hoverState="",this._activeTrigger={},this._popper=null,this.element=e,this.config=this._getConfig(t),this.tip=null,this._setListeners()}var e=i.prototype;return e.enable=function(){this._isEnabled=!0},e.disable=function(){this._isEnabled=!1},e.toggleEnabled=function(){this._isEnabled=!this._isEnabled},e.toggle=function(e){if(this._isEnabled)if(e){var t=this.constructor.DATA_KEY,n=yn(e.currentTarget).data(t);n||(n=new this.constructor(e.currentTarget,this._getDelegateConfig()),yn(e.currentTarget).data(t,n)),n._activeTrigger.click=!n._activeTrigger.click,n._isWithActiveTrigger()?n._enter(null,n):n._leave(null,n)}else{if(yn(this.getTipElement()).hasClass(Pn))return void this._leave(null,this);this._enter(null,this)}},e.dispose=function(){clearTimeout(this._timeout),yn.removeData(this.element,this.constructor.DATA_KEY),yn(this.element).off(this.constructor.EVENT_KEY),yn(this.element).closest(".modal").off("hide.bs.modal"),this.tip&&yn(this.tip).remove(),this._isEnabled=null,this._timeout=null,this._hoverState=null,(this._activeTrigger=null)!==this._popper&&this._popper.destroy(),this._popper=null,this.element=null,this.config=null,this.tip=null},e.show=function(){var t=this;if("none"===yn(this.element).css("display"))throw new Error("Please use show on visible elements");var e=yn.Event(this.constructor.Event.SHOW);if(this.isWithContent()&&this._isEnabled){yn(this.element).trigger(e);var n=yn.contains(this.element.ownerDocument.documentElement,this.element);if(e.isDefaultPrevented()||!n)return;var i=this.getTipElement(),r=we.getUID(this.constructor.NAME);i.setAttribute("id",r),this.element.setAttribute("aria-describedby",r),this.setContent(),this.config.animation&&yn(i).addClass(xn);var o="function"==typeof this.config.placement?this.config.placement.call(this,i,this.element):this.config.placement,s=this._getAttachment(o);this.addAttachmentClass(s);var a=!1===this.config.container?document.body:yn(document).find(this.config.container);yn(i).data(this.constructor.DATA_KEY,this),yn.contains(this.element.ownerDocument.documentElement,this.tip)||yn(i).appendTo(a),yn(this.element).trigger(this.constructor.Event.INSERTED),this._popper=new Ct(this.element,i,{placement:s,modifiers:{offset:{offset:this.config.offset},flip:{behavior:this.config.fallbackPlacement},arrow:{element:jn},preventOverflow:{boundariesElement:this.config.boundary}},onCreate:function(e){e.originalPlacement!==e.placement&&t._handlePopperPlacementChange(e)},onUpdate:function(e){t._handlePopperPlacementChange(e)}}),yn(i).addClass(Pn),"ontouchstart"in document.documentElement&&yn(document.body).children().on("mouseover",null,yn.noop);var l=function(){t.config.animation&&t._fixTransition();var e=t._hoverState;t._hoverState=null,yn(t.element).trigger(t.constructor.Event.SHOWN),e===Nn&&t._leave(null,t)};if(yn(this.tip).hasClass(xn)){var c=we.getTransitionDurationFromElement(this.tip);yn(this.tip).one(we.TRANSITION_END,l).emulateTransitionEnd(c)}else l()}},e.hide=function(e){var t=this,n=this.getTipElement(),i=yn.Event(this.constructor.Event.HIDE),r=function(){t._hoverState!==On&&n.parentNode&&n.parentNode.removeChild(n),t._cleanTipClass(),t.element.removeAttribute("aria-describedby"),yn(t.element).trigger(t.constructor.Event.HIDDEN),null!==t._popper&&t._popper.destroy(),e&&e()};if(yn(this.element).trigger(i),!i.isDefaultPrevented()){if(yn(n).removeClass(Pn),"ontouchstart"in document.documentElement&&yn(document.body).children().off("mouseover",null,yn.noop),this._activeTrigger[Fn]=!1,this._activeTrigger[Mn]=!1,this._activeTrigger[Hn]=!1,yn(this.tip).hasClass(xn)){var o=we.getTransitionDurationFromElement(n);yn(n).one(we.TRANSITION_END,r).emulateTransitionEnd(o)}else r();this._hoverState=""}},e.update=function(){null!==this._popper&&this._popper.scheduleUpdate()},e.isWithContent=function(){return Boolean(this.getTitle())},e.addAttachmentClass=function(e){yn(this.getTipElement()).addClass(Tn+"-"+e)},e.getTipElement=function(){return this.tip=this.tip||yn(this.config.template)[0],this.tip},e.setContent=function(){var e=this.getTipElement();this.setElementContent(yn(e.querySelectorAll(Ln)),this.getTitle()),yn(e).removeClass(xn+" "+Pn)},e.setElementContent=function(e,t){var n=this.config.html;"object"==typeof t&&(t.nodeType||t.jquery)?n?yn(t).parent().is(e)||e.empty().append(t):e.text(yn(t).text()):e[n?"html":"text"](t)},e.getTitle=function(){var e=this.element.getAttribute("data-original-title");return e||(e="function"==typeof this.config.title?this.config.title.call(this.element):this.config.title),e},e._getAttachment=function(e){return An[e.toUpperCase()]},e._setListeners=function(){var i=this;this.config.trigger.split(" ").forEach(function(e){if("click"===e)yn(i.element).on(i.constructor.Event.CLICK,i.config.selector,function(e){return i.toggle(e)});else if(e!==Wn){var t=e===Hn?i.constructor.Event.MOUSEENTER:i.constructor.Event.FOCUSIN,n=e===Hn?i.constructor.Event.MOUSELEAVE:i.constructor.Event.FOCUSOUT;yn(i.element).on(t,i.config.selector,function(e){return i._enter(e)}).on(n,i.config.selector,function(e){return i._leave(e)})}yn(i.element).closest(".modal").on("hide.bs.modal",function(){return i.hide()})}),this.config.selector?this.config=l({},this.config,{trigger:"manual",selector:""}):this._fixTitle()},e._fixTitle=function(){var e=typeof this.element.getAttribute("data-original-title");(this.element.getAttribute("title")||"string"!==e)&&(this.element.setAttribute("data-original-title",this.element.getAttribute("title")||""),this.element.setAttribute("title",""))},e._enter=function(e,t){var n=this.constructor.DATA_KEY;(t=t||yn(e.currentTarget).data(n))||(t=new this.constructor(e.currentTarget,this._getDelegateConfig()),yn(e.currentTarget).data(n,t)),e&&(t._activeTrigger["focusin"===e.type?Mn:Hn]=!0),yn(t.getTipElement()).hasClass(Pn)||t._hoverState===On?t._hoverState=On:(clearTimeout(t._timeout),t._hoverState=On,t.config.delay&&t.config.delay.show?t._timeout=setTimeout(function(){t._hoverState===On&&t.show()},t.config.delay.show):t.show())},e._leave=function(e,t){var n=this.constructor.DATA_KEY;(t=t||yn(e.currentTarget).data(n))||(t=new this.constructor(e.currentTarget,this._getDelegateConfig()),yn(e.currentTarget).data(n,t)),e&&(t._activeTrigger["focusout"===e.type?Mn:Hn]=!1),t._isWithActiveTrigger()||(clearTimeout(t._timeout),t._hoverState=Nn,t.config.delay&&t.config.delay.hide?t._timeout=setTimeout(function(){t._hoverState===Nn&&t.hide()},t.config.delay.hide):t.hide())},e._isWithActiveTrigger=function(){for(var e in this._activeTrigger)if(this._activeTrigger[e])return!0;return!1},e._getConfig=function(e){return"number"==typeof(e=l({},this.constructor.Default,yn(this.element).data(),"object"==typeof e&&e?e:{})).delay&&(e.delay={show:e.delay,hide:e.delay}),"number"==typeof e.title&&(e.title=e.title.toString()),"number"==typeof e.content&&(e.content=e.content.toString()),we.typeCheckConfig(En,e,this.constructor.DefaultType),e},e._getDelegateConfig=function(){var e={};if(this.config)for(var t in this.config)this.constructor.Default[t]!==this.config[t]&&(e[t]=this.config[t]);return e},e._cleanTipClass=function(){var e=yn(this.getTipElement()),t=e.attr("class").match(Sn);null!==t&&t.length&&e.removeClass(t.join(""))},e._handlePopperPlacementChange=function(e){var t=e.instance;this.tip=t.popper,this._cleanTipClass(),this.addAttachmentClass(this._getAttachment(e.placement))},e._fixTransition=function(){var e=this.getTipElement(),t=this.config.animation;null===e.getAttribute("x-placement")&&(yn(e).removeClass(xn),this.config.animation=!1,this.hide(),this.show(),this.config.animation=t)},i._jQueryInterface=function(n){return this.each(function(){var e=yn(this).data(bn),t="object"==typeof n&&n;if((e||!/dispose|hide/.test(n))&&(e||(e=new i(this,t),yn(this).data(bn,e)),"string"==typeof n)){if("undefined"==typeof e[n])throw new TypeError('No method named "'+n+'"');e[n]()}})},s(i,null,[{key:"VERSION",get:function(){return"4.1.3"}},{key:"Default",get:function(){return In}},{key:"NAME",get:function(){return En}},{key:"DATA_KEY",get:function(){return bn}},{key:"Event",get:function(){return kn}},{key:"EVENT_KEY",get:function(){return wn}},{key:"DefaultType",get:function(){return Dn}}]),i}(),yn.fn[En]=Rn._jQueryInterface,yn.fn[En].Constructor=Rn,yn.fn[En].noConflict=function(){return yn.fn[En]=Cn,Rn._jQueryInterface},Rn),Qi=(Bn="popover",Kn="."+(qn="bs.popover"),Qn=(Un=t).fn[Bn],Yn="bs-popover",Vn=new RegExp("(^|\\s)"+Yn+"\\S+","g"),zn=l({},Ki.Default,{placement:"right",trigger:"click",content:"",template:''}),Gn=l({},Ki.DefaultType,{content:"(string|element|function)"}),Jn="fade",Xn=".popover-header",$n=".popover-body",ei={HIDE:"hide"+Kn,HIDDEN:"hidden"+Kn,SHOW:(Zn="show")+Kn,SHOWN:"shown"+Kn,INSERTED:"inserted"+Kn,CLICK:"click"+Kn,FOCUSIN:"focusin"+Kn,FOCUSOUT:"focusout"+Kn,MOUSEENTER:"mouseenter"+Kn,MOUSELEAVE:"mouseleave"+Kn},ti=function(e){var t,n;function i(){return e.apply(this,arguments)||this}n=e,(t=i).prototype=Object.create(n.prototype),(t.prototype.constructor=t).__proto__=n;var r=i.prototype;return r.isWithContent=function(){return this.getTitle()||this._getContent()},r.addAttachmentClass=function(e){Un(this.getTipElement()).addClass(Yn+"-"+e)},r.getTipElement=function(){return this.tip=this.tip||Un(this.config.template)[0],this.tip},r.setContent=function(){var e=Un(this.getTipElement());this.setElementContent(e.find(Xn),this.getTitle());var t=this._getContent();"function"==typeof t&&(t=t.call(this.element)),this.setElementContent(e.find($n),t),e.removeClass(Jn+" "+Zn)},r._getContent=function(){return this.element.getAttribute("data-content")||this.config.content},r._cleanTipClass=function(){var e=Un(this.getTipElement()),t=e.attr("class").match(Vn);null!==t&&0=this._offsets[r]&&("undefined"==typeof this._offsets[r+1]||e 2 | 3 | 4 | 5 | 6 | 7 | 8 | CodiceFiscaleJS 9 | 10 | 11 | 12 | 13 | 14 | 19 | 20 | 21 |
22 |
23 |

Codice Fiscale JS

24 |

The Italian Tax Code Library for Javascript and Typescript

25 |
26 | 27 | Star 28 | 29 | Issue 30 | 31 | Download 32 |
33 |
34 |
35 |
36 |

Codice Fiscale

37 |
38 |
39 |
40 | 41 | 42 |
43 |
44 | 45 | 46 |
47 |
48 |
49 |
50 | 51 | 55 |
56 |
57 | 58 | 59 |
60 |
61 |
62 |
63 | 64 | 66 |
67 |
68 | 69 | 71 |
72 |
73 | 74 | 75 |
76 |
77 |
78 |
79 | 80 |
81 | 82 |
83 | 84 |
85 |
86 |
87 |
88 |
89 | Codice fiscale copied to your clipboard!!! 90 | 93 |
94 |
95 |
96 |
97 | 98 |
99 |
100 |

Reverse Codice Fiscale

101 |
102 |
103 |
104 | 105 |
106 | 107 |
108 | 109 |
110 |
111 | Invalid Codice Fiscale 112 |
113 |
114 | 115 |
116 |
117 |
118 |
119 |
120 | 121 | 122 |
123 |
124 | 125 | 126 |
127 |
128 |
129 |
130 | 131 | 132 |
133 |
134 | 135 | 136 |
137 |
138 |
139 |
140 | 141 | 142 |
143 |
144 | 145 | 146 |
147 |
148 |
149 |
150 |
151 | 152 |
153 |
154 |

Validate Codice Fiscale

155 |
156 |
157 |
158 | 159 |
160 | 161 |
162 | 163 |
164 |
165 | Invalid Codice Fiscale 166 |
167 |
168 | Valid Codice Fiscale 169 |
170 |
171 | 172 |
173 |
174 |
175 |
176 |
177 |
178 | 179 | 267 | 268 | 269 | 270 | 271 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codice-fiscale-js", 3 | "version": "2.3.23", 4 | "description": "The Italian Tax Code Library for Javascript and Typescript", 5 | "main": "dist/codice.fiscale.commonjs2.js", 6 | "types": "types/codice-fiscale.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "git://github.com/lucavandro/CodiceFiscaleJS.git" 10 | }, 11 | "directories": { 12 | "test": "tests" 13 | }, 14 | "devDependencies": { 15 | "@babel/cli": "^7.10.5", 16 | "@babel/core": "^7.10.5", 17 | "@babel/preset-env": "^7.10.4", 18 | "babel-jest": "^24.9.0", 19 | "babel-loader": "^8.1.0", 20 | "jest": "^29.7.0", 21 | "parallel-webpack": "^2.6.0", 22 | "standard": "^12.0.1", 23 | "webpack": "^4.43.0", 24 | "webpack-cli": "^3.3.12" 25 | }, 26 | "scripts": { 27 | "build": "webpack && rename", 28 | "clean": "rm ./example/codice.fiscale.var.js", 29 | "test": "jest", 30 | "fix": "standard --fix", 31 | "standard": "standard", 32 | "rename": "node utils.js", 33 | "webpack": "webpack" 34 | }, 35 | "author": "Luca Vandro ", 36 | "contributors": [ 37 | "Walter Barbagallo ", 38 | "Marco Pesani ", 39 | "Arsenio Siani " 40 | ], 41 | "license": "CC BY SA", 42 | "standard": { 43 | "ignore": [ 44 | "dist/" 45 | ] 46 | }, 47 | "jest": { 48 | "moduleDirectories": [ 49 | "node_modules", 50 | "./src" 51 | ] 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # CodiceFiscale.js 2 | CodiceFiscale.js is a javascript and typescript utility library to compute and validate Italian Italian Tax code (codice fiscale). 3 | 4 | ### Check it out 5 | [CodiceFiscaleJS](https://lucavandro.github.io/CodiceFiscaleJS/) 6 | 7 | ### Donate 8 | [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W2M92TNMXR3CC&source=url) 9 | 10 | ## Change log 11 | 12 | **Version 2.3.10** 13 | - Security fixes 14 | - Bug fixes 15 | - Added isOmocodia function 16 | - Test code refactoring 17 | 18 | **Version 2.3.4** 19 | - Improved search 20 | - Bug fixes 21 | 22 | **Version 2.3.0** 23 | - Complete italian comuni list (comuni soppressi, che hanno cambiato provincia) [last update 29/05/2020] 24 | - Python script to update data directly from the ISTAT website 25 | 26 | 27 | **Version 2.2.5** 28 | - Added more comuni 29 | - Updated gh-pages sites 30 | - Security fix 31 | 32 | **Version 2.2.4** 33 | - Fixed lowercase validation issue 34 | - Updated country list 35 | - Security fix 36 | 37 | 38 | **Version 2.2.1** 39 | - Fixed UTC Date issue 40 | - Minor bug fixed 41 | 42 | **Version 2.0.0** 43 | - Added TypeScript support 44 | - Added Object-oriented API 45 | - Improved performance 46 | - Improved error detection 47 | - Backcompatible 48 | 49 | ## Installation 50 | **Node** 51 | ```sh 52 | npm install codice-fiscale-js --save 53 | ``` 54 | ```js 55 | var CodiceFiscale = require('codice-fiscale-js'); 56 | 57 | ``` 58 | **Web** 59 | ```html 60 | 61 | ``` 62 | AMD, UMD e CommonJS version are available. Check `dist` folder 63 | 64 | ## Docs 65 | - [Javascript](https://github.com/lucavandro/CodiceFiscaleJS/tree/master/docs/js-oop.md) 66 | - [TypeScript](https://github.com/lucavandro/CodiceFiscaleJS/tree/master/docs/typescript.md) 67 | - [Javascript v1.2.0 deprecated](https://github.com/lucavandro/CodiceFiscaleJS/tree/master/docs/js-static.md) 68 | ## Available npm scripts: 69 | - `npm run build`: build the bundle into `dist` directory. 70 | - `npm run test`: launch the tests. -------------------------------------------------------------------------------- /src/codice-fiscale.js: -------------------------------------------------------------------------------- 1 | import { Comune } from './comune' 2 | import { CHECK_CODE_CHARS, CHECK_CODE_EVEN, CHECK_CODE_ODD, MONTH_CODES, NUMERIC_POS, OMOCODIA_TABLE, OMOCODIA_TABLE_INVERSE } from './constants' 3 | import { extractConsonants, extractVowels, getValidDate, birthplaceFields, getAllSubsets } from './utils' 4 | 5 | class CodiceFiscale { 6 | get day () { 7 | return this.birthday.getUTCDate() 8 | } 9 | set day (d) { 10 | this.birthday.setDate(d) 11 | } 12 | get month () { 13 | return this.birthday.getUTCMonth() + 1 14 | } 15 | set month (m) { 16 | this.birthday.setMonth(m - 1) 17 | } 18 | get year () { 19 | return this.birthday.getUTCFullYear() 20 | } 21 | set year (y) { 22 | this.birthday.setFullYear(y) 23 | } 24 | get cf () { 25 | return this.code 26 | } 27 | get nameCode () { 28 | return this.code.substr(3, 3) 29 | } 30 | get surnameCode () { 31 | return this.code.substr(0, 3) 32 | } 33 | get checkCode () { 34 | return this.code.substr(15, 1) 35 | } 36 | constructor (data) { 37 | if (typeof data === 'string') { 38 | data = data.toUpperCase() 39 | if (CodiceFiscale.check(data)) { 40 | this.code = data 41 | this.reverse() 42 | } else { 43 | throw new Error('Provided input is not a valid Codice Fiscale') 44 | } 45 | } else if (typeof data === 'object') { 46 | const cfData = data 47 | this.name = cfData.name 48 | this.surname = cfData.surname 49 | this.gender = this.checkGender(cfData.gender) 50 | this.birthday = cfData.birthday ? getValidDate(cfData.birthday) : getValidDate(cfData.day, cfData.month, cfData.year) 51 | this.birthplace = new Comune(cfData.birthplace, cfData.birthplaceProvincia) 52 | this.compute() 53 | } else { 54 | throw new Error('CodiceFiscale constructor accept either a valid string or a plain object. Check the documentation') 55 | } 56 | } 57 | static getCheckCode (codiceFiscale) { 58 | codiceFiscale = codiceFiscale.toUpperCase(); 59 | let val = 0 60 | for (let i = 0; i < 15; i = i + 1) { 61 | const c = codiceFiscale[i] 62 | val += i % 2 !== 0 ? CHECK_CODE_EVEN[c] : CHECK_CODE_ODD[c] 63 | } 64 | val = val % 26 65 | return CHECK_CODE_CHARS.charAt(val) 66 | } 67 | static findLocationCode (name, prov) { 68 | return new Comune(name, prov).cc 69 | } 70 | static computeInverse (codiceFiscale) { 71 | return new CodiceFiscale(codiceFiscale).toJSON() 72 | } 73 | static reverse(codiceFiscale) { 74 | return new CodiceFiscale(codiceFiscale).toJSON() 75 | } 76 | static compute (obj) { 77 | return new CodiceFiscale(obj).toString() 78 | } 79 | static check (codiceFiscale) { 80 | if (typeof codiceFiscale !== 'string') { 81 | return false 82 | } 83 | let cf = codiceFiscale.toUpperCase() 84 | if (cf.length !== 16) { 85 | return false 86 | } 87 | if(! /^[A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST]{1}[0-9LMNPQRSTUV]{2}[A-Z]{1}[0-9LMNPQRSTUV]{3}[A-Z]{1}$/.test(cf)){ 88 | return false; 89 | } 90 | const expectedCheckCode = codiceFiscale.charAt(15) 91 | cf = codiceFiscale.slice(0, 15) 92 | return CodiceFiscale.getCheckCode(cf).toUpperCase() === expectedCheckCode.toUpperCase(); 93 | } 94 | static isOmocodia(cf){ 95 | for(const pos of NUMERIC_POS){ 96 | if(!/^[0-9]$/.test(cf[pos])) return true; 97 | } 98 | return false; 99 | } 100 | static getOmocodie (cf) { 101 | return new CodiceFiscale(cf).omocodie() 102 | } 103 | static surnameCode(surname){ 104 | const codeSurname = `${extractConsonants(surname)}${extractVowels(surname)}XXX` 105 | return codeSurname.substr(0, 3).toUpperCase() 106 | } 107 | static nameCode(name){ 108 | let codNome = extractConsonants(name) 109 | if (codNome.length >= 4) { 110 | codNome = codNome.charAt(0) + codNome.charAt(2) + codNome.charAt(3) 111 | } else { 112 | codNome += `${extractVowels(name)}XXX` 113 | codNome = codNome.substr(0, 3) 114 | } 115 | return codNome.toUpperCase() 116 | } 117 | static dateCode(day, month, year, gender){ 118 | year = `0${year}` 119 | year = year.substr(year.length - 2, 2) 120 | month = MONTH_CODES[month-1]; 121 | if (gender.toUpperCase() === 'F') { 122 | day += 40 123 | } 124 | day = `0${day}` 125 | day = day.substr(day.length - 2, 2) 126 | return `${year}${month}${day}` 127 | } 128 | static toNumberIfOmocodia(input){ 129 | if (isNaN(input)) { 130 | let res = "" 131 | let tokens = input.split("") 132 | for(let i=0; i 0 ) 192 | results.push(omocode + CodiceFiscale.getCheckCode(omocode)) 193 | } 194 | 195 | return results 196 | } 197 | compute () { 198 | let code = this.getSurnameCode() 199 | code += this.getNameCode() 200 | code += this.dateCode() 201 | code += this.birthplace.cc 202 | code += CodiceFiscale.getCheckCode(code) 203 | this.code = code 204 | } 205 | reverse () { 206 | const code = CodiceFiscale.isOmocodia(this.code) ? CodiceFiscale.fromOmocodiaToOriginal(this.code) : this.code 207 | this.name = code.substr(3, 3) 208 | this.surname = code.substr(0, 3) 209 | 210 | let yearCode = code.substr(6, 2) 211 | const year19XX = parseInt(`19${yearCode}`, 10) 212 | const year20XX = parseInt(`20${yearCode}`, 10) 213 | const currentYear20XX = new Date().getFullYear() 214 | const year = year20XX > currentYear20XX ? year19XX : year20XX 215 | const monthChar = code.substr(8, 1) 216 | const month = MONTH_CODES.indexOf(monthChar) 217 | this.gender = 'M' 218 | let dayString = code.substr(9, 2); 219 | let day = parseInt(dayString, 10) 220 | if (day > 31) { 221 | this.gender = 'F' 222 | day = day - 40 223 | } 224 | this.birthday = new Date(Date.UTC(year, month, day, 0, 0, 0, 0)) 225 | let cc = code.substr(11, 4) 226 | this.birthplace = Comune.GetByCC(cc) 227 | return this.toJSON() 228 | } 229 | checkGender (gender) { 230 | this.gender = gender !== undefined ? gender.toUpperCase() : this.gender.toUpperCase() 231 | if (typeof this.gender !== 'string') { 232 | throw new Error('Gender must be a string') 233 | } 234 | if (this.gender !== 'M' && this.gender !== 'F') { 235 | throw new Error('Gender must be either \'M\' or \'F\'') 236 | } 237 | return gender 238 | } 239 | getSurnameCode () { 240 | return CodiceFiscale.surnameCode(this.surname); 241 | } 242 | getNameCode () { 243 | return CodiceFiscale.nameCode(this.name); 244 | } 245 | dateCode () { 246 | return CodiceFiscale.dateCode(this.birthday.getDate(), this.birthday.getMonth() + 1, this.birthday.getFullYear(), this.gender); 247 | } 248 | }; 249 | 250 | CodiceFiscale.utils = { 251 | birthplaceFields: birthplaceFields 252 | } 253 | module.exports = CodiceFiscale; -------------------------------------------------------------------------------- /src/comune.js: -------------------------------------------------------------------------------- 1 | import { COMUNI } from './lista-comuni' 2 | import { normalizeString } from './utils' 3 | export class Comune { 4 | get nomeNorm () { 5 | return normalizeString(this.nome) 6 | } 7 | constructor (nome, prov, cc, check = true) { 8 | if (check || cc === undefined || prov === undefined) { 9 | let comune = this.searchByNameAndProvince(nome, prov) 10 | 11 | if (comune === undefined && nome.length === 4 && /^[A-Za-z]\d{3}$/.test(nome)) { 12 | comune = this.searchByCC(nome) 13 | } 14 | 15 | if (comune === undefined) { 16 | throw new Error(`Comune with name ${nome} doesn't exist`) 17 | } else if (cc !== undefined && comune.cc !== cc) { 18 | throw new Error(`Comune with cc ${cc} doesn't exist`) 19 | } else { 20 | this.nome = comune.nome 21 | this.prov = comune.prov 22 | this.cc = comune.cc 23 | } 24 | } else { 25 | this.nome = nome 26 | this.prov = prov 27 | this.cc = cc 28 | } 29 | } 30 | static GetByName (name, prov) { 31 | return new Comune(name, prov) 32 | } 33 | static GetByCC (cc) { 34 | let result 35 | let count = 0 36 | for (const item of COMUNI) { 37 | if ( item[0] === cc && item[3]===1) { 38 | result = item 39 | break 40 | } else if(item[0] === cc){ 41 | result = item; 42 | } 43 | } 44 | if (result !== undefined) { 45 | return new Comune(result[2], result[1], result[0], false) 46 | } 47 | throw new Error(`Comune with cc ${cc} doesn't exist`) 48 | } 49 | 50 | searchByCC (cc) { 51 | let result 52 | try { 53 | result = Comune.GetByCC(cc) 54 | } catch (e) { } 55 | if (result !== undefined) { 56 | return result.toJSON() 57 | } 58 | } 59 | searchByName (nome ) { 60 | this.searchByNameAndProvince(nome) 61 | } 62 | searchByNameAndProvince (nome, prov) { 63 | const qNome = normalizeString(nome) 64 | const qProv= prov && normalizeString(prov) 65 | let results = COMUNI.filter((c)=>qProv? c[1]===qProv && c[2]===qNome: c[2]===qNome).map((c)=>{ 66 | return { cc: c[0], prov: c[1], nome: c[2], active:c[3]===1 } 67 | }) 68 | 69 | // One results: no problem! 70 | if (results.length === 1) { 71 | return results[0] 72 | } 73 | 74 | // if many results look for the active one 75 | results = results.filter(c=> c.active) 76 | 77 | if(results.length === 1) 78 | return results[0] 79 | else if(prov) 80 | throw new Error(`Comune with name of ${nome} and prov ${prov} doesn't exists`) 81 | else if(nome.length===4 && nome.toUpperCase() === nome) 82 | return Comune.GetByCC(nome) 83 | else 84 | throw new Error(`Comune with name of ${nome} is found in more than one province. Please specify the province code`) 85 | 86 | } 87 | 88 | toJSON () { 89 | return { 90 | cc: this.cc, 91 | nome: this.nome, 92 | prov: this.prov 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/constants.js: -------------------------------------------------------------------------------- 1 | export const MONTH_CODES = [ 2 | 'A', 3 | 'B', 4 | 'C', 5 | 'D', 6 | 'E', 7 | 'H', 8 | 'L', 9 | 'M', 10 | 'P', 11 | 'R', 12 | 'S', 13 | 'T' 14 | ] 15 | 16 | export const CHECK_CODE_ODD = { 17 | 0: 1, 18 | 1: 0, 19 | 2: 5, 20 | 3: 7, 21 | 4: 9, 22 | 5: 13, 23 | 6: 15, 24 | 7: 17, 25 | 8: 19, 26 | 9: 21, 27 | A: 1, 28 | B: 0, 29 | C: 5, 30 | D: 7, 31 | E: 9, 32 | F: 13, 33 | G: 15, 34 | H: 17, 35 | I: 19, 36 | J: 21, 37 | K: 2, 38 | L: 4, 39 | M: 18, 40 | N: 20, 41 | O: 11, 42 | P: 3, 43 | Q: 6, 44 | R: 8, 45 | S: 12, 46 | T: 14, 47 | U: 16, 48 | V: 10, 49 | W: 22, 50 | X: 25, 51 | Y: 24, 52 | Z: 23 53 | } 54 | 55 | export const CHECK_CODE_EVEN = { 56 | 0: 0, 57 | 1: 1, 58 | 2: 2, 59 | 3: 3, 60 | 4: 4, 61 | 5: 5, 62 | 6: 6, 63 | 7: 7, 64 | 8: 8, 65 | 9: 9, 66 | A: 0, 67 | B: 1, 68 | C: 2, 69 | D: 3, 70 | E: 4, 71 | F: 5, 72 | G: 6, 73 | H: 7, 74 | I: 8, 75 | J: 9, 76 | K: 10, 77 | L: 11, 78 | M: 12, 79 | N: 13, 80 | O: 14, 81 | P: 15, 82 | Q: 16, 83 | R: 17, 84 | S: 18, 85 | T: 19, 86 | U: 20, 87 | V: 21, 88 | W: 22, 89 | X: 23, 90 | Y: 24, 91 | Z: 25 92 | } 93 | 94 | export const OMOCODIA_TABLE = { 95 | 0: 'L', 96 | 1: 'M', 97 | 2: 'N', 98 | 3: 'P', 99 | 4: 'Q', 100 | 5: 'R', 101 | 6: 'S', 102 | 7: 'T', 103 | 8: 'U', 104 | 9: 'V' 105 | } 106 | 107 | export const OMOCODIA_TABLE_INVERSE = { 108 | 'L': '0', 109 | 'M': '1', 110 | 'N': '2', 111 | 'P': '3', 112 | 'Q': '4', 113 | 'R': '5', 114 | 'S': '6', 115 | 'T': '7', 116 | 'U': '8', 117 | 'V': '9' 118 | } 119 | 120 | export const CHECK_CODE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 121 | 122 | export const NUMERIC_POS = [6,7,9,10,12,13,14] -------------------------------------------------------------------------------- /src/lista-province.js: -------------------------------------------------------------------------------- 1 | export const PROVINCE = { 2 | AG: "Agrigento", 3 | AL: "Alessandria", 4 | AN: "Ancona", 5 | AO: "Aosta", 6 | AP: "Ascoli Piceno", 7 | AQ: "L'Aquila", 8 | AR: "Arezzo", 9 | AT: "Asti", 10 | AV: "Avellino", 11 | BA: "Bari", 12 | BG: "Bergamo", 13 | BI: "Biella", 14 | BL: "Belluno", 15 | BN: "Benevento", 16 | BO: "Bologna", 17 | BR: "Brindisi", 18 | BS: "Brescia", 19 | BT: "Barletta-Andria-Trani", 20 | BZ: "Bolzano", 21 | CA: "Cagliari", 22 | CB: "Campobasso", 23 | CE: "Caserta", 24 | CH: "Chieti", 25 | CL: "Caltanissetta", 26 | CN: "Cuneo", 27 | CO: "Como", 28 | CR: "Cremona", 29 | CS: "Cosenza", 30 | CT: "Catania", 31 | CZ: "Catanzaro", 32 | EN: "Enna", 33 | FC: "Forlì-Cesena", 34 | FE: "Ferrara", 35 | FG: "Foggia", 36 | FI: "Firenze", 37 | FM: "Fermo", 38 | FR: "Frosinone", 39 | GE: "Genova", 40 | GO: "Gorizia", 41 | GR: "Grosseto", 42 | IM: "Imperia", 43 | IS: "Isernia", 44 | KR: "Crotone", 45 | LC: "Lecco", 46 | LE: "Lecce", 47 | LI: "Livorno", 48 | LO: "Lodi", 49 | LT: "Latina", 50 | LU: "Lucca", 51 | MB: "Monza e della Brianza", 52 | MC: "Macerata", 53 | ME: "Messina", 54 | MI: "Milano", 55 | MN: "Mantova", 56 | MO: "Modena", 57 | MS: "Massa-Carrara", 58 | MT: "Matera", 59 | NA: "Napoli", 60 | NO: "Novara", 61 | NU: "Nuoro", 62 | OR: "Oristano", 63 | PA: "Palermo", 64 | PC: "Piacenza", 65 | PD: "Padova", 66 | PE: "Pescara", 67 | PG: "Perugia", 68 | PI: "Pisa", 69 | PN: "Pordenone", 70 | PO: "Prato", 71 | PR: "Parma", 72 | PT: "Pistoia", 73 | PU: "Pesaro e Urbino", 74 | PV: "Pavia", 75 | PZ: "Potenza", 76 | RA: "Ravenna", 77 | RC: "Reggio Calabria", 78 | RE: "Reggio Emilia", 79 | RG: "Ragusa", 80 | RI: "Rieti", 81 | RM: "Roma", 82 | RN: "Rimini", 83 | RO: "Rovigo", 84 | SA: "Salerno", 85 | SI: "Siena", 86 | SO: "Sondrio", 87 | SP: "La Spezia", 88 | SR: "Siracusa", 89 | SS: "Sassari", 90 | SU: "Sud Sardegna", 91 | SV: "Savona", 92 | TA: "Taranto", 93 | TE: "Teramo", 94 | TN: "Trento", 95 | TO: "Torino", 96 | TP: "Trapani", 97 | TR: "Terni", 98 | TS: "Trieste", 99 | TV: "Treviso", 100 | UD: "Udine", 101 | VA: "Varese", 102 | VB: "Verbano-Cusio-Ossola", 103 | VC: "Vercelli", 104 | VE: "Venezia", 105 | VI: "Vicenza", 106 | VR: "Verona", 107 | VS: "Medio Campidano", 108 | VT: "Viterbo", 109 | VV: "Vibo Valentia", 110 | EE: "Estero" 111 | } 112 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | import { COMUNI } from './lista-comuni' 2 | import { PROVINCE } from './lista-province' 3 | 4 | export function normalizeString (str) { 5 | return str.trim() 6 | .replace(new RegExp(/[àá]/g), 'a\'') 7 | .replace(new RegExp(/[èé]/g), 'e\'') 8 | .replace(new RegExp(/[ìí]/g), 'i\'') 9 | .replace(new RegExp(/[òó]/g), 'o\'') 10 | .replace(new RegExp(/[ùú]/g), 'u\'') 11 | .toUpperCase() 12 | } 13 | export function daysInMonth (m, y) { 14 | switch (m) { 15 | case 1: 16 | return (y % 4 === 0 && y % 100 !== 0) || (y % 400 === 0) ? 29 : 28 17 | case 8: 18 | case 3: 19 | case 5: 20 | case 10: 21 | return 30 22 | default: 23 | return 31 24 | } 25 | } 26 | export function isValidDate (d, m, y) { 27 | const month = m - 1 28 | return month >= 0 && month < 12 && d > 0 && d <= daysInMonth(month, y) 29 | } 30 | export function getValidDate(d, m, y) { 31 | if (typeof d === 'string' && m === undefined && y === undefined) { 32 | if (d.includes('-')) { 33 | const [year, month, day] = d.split('-').map(Number); 34 | const date = new Date(); 35 | date.setFullYear(year, month - 1, day); 36 | date.setHours(12, 0, 0, 0); // mezzogiorno per evitare errori di fuso 37 | return date; 38 | } 39 | return new Date(d); 40 | } 41 | 42 | if (typeof d === 'number' && typeof m === 'number' && typeof y === 'number') { 43 | const date = new Date(); 44 | date.setFullYear(y, m - 1, d); 45 | date.setHours(12, 0, 0, 0); 46 | return date; 47 | } 48 | 49 | throw new Error(`The date ${y}/${m}/${d} is not a valid date`); 50 | } 51 | 52 | export function extractVowels (str) { 53 | return str.replace(/[^AEIOU]/gi, '') 54 | } 55 | export function extractConsonants (str) { 56 | return str.replace(/[^BCDFGHJKLMNPQRSTVWXYZ]/gi, '') 57 | } 58 | 59 | export function birthplaceFields (provinceSelector, birthplaceSelector) { 60 | const provinceSelect = document.querySelector(provinceSelector) 61 | const birthplaceSelect = document.querySelector(birthplaceSelector) 62 | const optGroupProv = document.createElement('optgroup') 63 | const optGroupEE = document.createElement('optgroup') 64 | optGroupEE.label = '-----------' 65 | provinceSelect.appendChild(optGroupProv) 66 | provinceSelect.appendChild(optGroupEE) 67 | Object.keys(PROVINCE).sort(function(a,b){return PROVINCE[a]>PROVINCE[b] ? 1 : -1}).forEach((code, i) => { 68 | const name = PROVINCE[code] 69 | const option = document.createElement('option') 70 | option.value = code 71 | option.textContent = name 72 | if (code === 'EE') { 73 | optGroupEE.appendChild(option) 74 | } else { 75 | optGroupProv.appendChild(option) 76 | } 77 | }) 78 | 79 | provinceSelect.onchange = (e) => { 80 | let province = provinceSelect.value 81 | while (birthplaceSelect.firstChild) { 82 | birthplaceSelect.removeChild(birthplaceSelect.firstChild) 83 | } 84 | COMUNI.forEach((comune) => { 85 | let cc = comune[0] 86 | let nome = comune[2] 87 | let prov = comune[1] 88 | if (prov === province) { 89 | let option = document.createElement('option') 90 | option.value = cc 91 | option.textContent = nome.toLowerCase().replace(/\b\w/g, l => l.toUpperCase()) 92 | birthplaceSelect.appendChild(option) 93 | } 94 | }) 95 | } 96 | provinceSelect.selectedIndex = '0' 97 | provinceSelect.onchange() 98 | } 99 | 100 | 101 | export function getAllSubsets(array){ 102 | return array.reduce( 103 | (subsets, value) => subsets.concat( 104 | subsets.map(set => [value,...set]) 105 | ), 106 | [[]] 107 | ); 108 | } 109 | -------------------------------------------------------------------------------- /tests/bug.spec.js: -------------------------------------------------------------------------------- 1 | import CodiceFiscale from '../src/codice-fiscale.js'; 2 | 3 | describe('Error in getting day of birth in reverse CF check #85', () => { 4 | let cf = new CodiceFiscale("RSSMRA80B01F205W") 5 | test('genera la data di nascita corretta', () => { 6 | expect(cf.day).toEqual(1) 7 | expect(cf.month).toEqual(2) 8 | expect(cf.year).toEqual(1980) 9 | }) 10 | }) 11 | 12 | describe('Generazione codice fiscale per persone nate nell\'Unione Sovietica', () => { 13 | test('genera CF corretto per persona nata a Mosca', () => { 14 | const cf = new CodiceFiscale({ 15 | name: 'Vladimir', 16 | surname: 'Petrov', 17 | gender: 'M', 18 | day: 15, 19 | month: 6, 20 | year: 1985, 21 | birthplace: 'URSS', // Codice per Mosca 22 | birthplaceProvincia: 'EE' // EE per stati esteri 23 | }) 24 | expect(cf.cf.length).toBe(16) 25 | expect(cf.cf.substr(11, 1)).toBe('Z') // Verifica il codice catastale estero 26 | }) 27 | 28 | test('genera CF corretto per persona nata a Kiev', () => { 29 | const cf = new CodiceFiscale({ 30 | name: 'Natalia', 31 | surname: 'Kovacs', 32 | gender: 'F', 33 | day: 23, 34 | month: 3, 35 | year: 1979, 36 | birthplace: 'UNIONE SOVIETICA', // Codice per Kiev 37 | birthplaceProvincia: 'EE' 38 | }) 39 | expect(cf.cf.length).toBe(16) 40 | expect(cf.cf.substr(11, 1)).toBe('Z') 41 | }) 42 | 43 | test('genera CF corretto per persona nata a Leningrado', () => { 44 | const cf = new CodiceFiscale({ 45 | name: 'Mikhail', 46 | surname: 'Ivanov', 47 | gender: 'M', 48 | day: 7, 49 | month: 11, 50 | year: 1982, 51 | birthplace: 'UNIONE REPUBBLICHE SOCIALISTE SOVIETICHE', // Codice per Leningrado (San Pietroburgo) 52 | birthplaceProvincia: 'EE' 53 | }) 54 | expect(cf.cf.length).toBe(16) 55 | expect(cf.cf.substr(11, 1)).toBe('Z') 56 | }) 57 | }) 58 | 59 | 60 | -------------------------------------------------------------------------------- /tests/compute.spec.js: -------------------------------------------------------------------------------- 1 | import CodiceFiscale from '../src/codice-fiscale.js'; 2 | 3 | describe('CodiceFiscale.compute', () => { 4 | test('è definito', () => { 5 | expect(CodiceFiscale.compute).toBeDefined() 6 | }) 7 | 8 | test('calcola il codice fiscale', () => { 9 | expect(CodiceFiscale.compute({ 10 | name: 'Luca', 11 | surname: 'Moreno', 12 | gender: 'M', 13 | day: 1, 14 | month: 1, 15 | year: 2000, 16 | birthplace: 'Roma', 17 | birthplaceProvincia: 'RM' 18 | })) 19 | .toBe('MRNLCU00A01H501J') 20 | }) 21 | 22 | test('calcola il codice fiscale anche per i nati nel comune di Bolzano 😁', () => { 23 | expect(CodiceFiscale.compute({ 24 | name: 'Mario', 25 | surname: 'Rossi', 26 | gender: 'M', 27 | day: 1, 28 | month: 1, 29 | year: 1980, 30 | birthplace: 'Bolzano', 31 | birthplaceProvincia: 'BZ' 32 | })) 33 | .toBe('RSSMRA80A01A952F') 34 | }) 35 | 36 | 37 | test('calcola il codice fiscale anche per i nati nel comune di Bolzano 😁', () => { 38 | expect(CodiceFiscale.compute({ 39 | name: 'Mario', 40 | surname: 'Rossi', 41 | gender: 'M', 42 | day: 1, 43 | month: 1, 44 | year: 1980, 45 | birthplace: 'Chiaravalle', 46 | birthplaceProvincia: 'AN' 47 | })) 48 | .toBeDefined() 49 | }) 50 | 51 | let invalidCfis = "BLIPTR93MO4A674Q"; 52 | test('controlla il codice fiscale con una regex', () => { 53 | expect(CodiceFiscale.check(invalidCfis)).toEqual(false); 54 | }); 55 | 56 | 57 | test("calcola il codice fiscale di persone nate all'estero", () => { 58 | expect(CodiceFiscale.compute({ 59 | name: 'Luca', 60 | surname: 'Moreno', 61 | gender: 'M', 62 | day: 1, 63 | month: 1, 64 | year: 2000, 65 | birthplace: 'Albania', 66 | birthplaceProvincia: 'EE' 67 | })) 68 | .toBe('MRNLCU00A01Z100P') 69 | }) 70 | 71 | 72 | test("calcola il codice fiscale di persone nate in Turkmenistan", () => { 73 | expect(CodiceFiscale.compute({ 74 | name: 'Maria', 75 | surname: 'Rossi', 76 | gender: 'F', 77 | day: 10, 78 | month: 9, 79 | year: 1990, 80 | birthplace: 'Turkmenistan', 81 | birthplaceProvincia: 'EE' 82 | })) 83 | .toBe('RSSMRA90P50Z258M') 84 | }) 85 | 86 | test("calcola il codice fiscale di persone nate in Azerbaigian", () => { 87 | expect(CodiceFiscale.compute({ 88 | name: 'Maria', 89 | surname: 'Rossi', 90 | gender: 'F', 91 | day: 10, 92 | month: 9, 93 | year: 1990, 94 | birthplace: 'Azerbaigian', 95 | birthplaceProvincia: 'EE' 96 | })) 97 | .toBe('RSSMRA90P50Z253A') 98 | }) 99 | 100 | test('se il comune non esiste lancia un eccezione', () => { 101 | var comuneInventato = function () { 102 | CodiceFiscale.compute({ 103 | name: 'Luca', 104 | surname: 'Moreno', 105 | gender: 'M', 106 | day: 1, 107 | month: 1, 108 | year: 2000, 109 | birthplace: 'Foo', 110 | birthplaceProvincia: 'EE' 111 | }) 112 | } 113 | expect(comuneInventato).toThrowError('Comune with name of Foo and prov EE doesn\'t exists') 114 | }) 115 | 116 | test('calcola il codice fiscale anche quando viene passato come birthplace il CC di un comune', ()=>{ 117 | expect(CodiceFiscale.compute({ name: "mario", surname: "rossi", gender: "M", birthday: "2000-01-01", birthplace: "H501" })).toBeDefined() 118 | }) 119 | }) -------------------------------------------------------------------------------- /tests/computeInverse.spec.js: -------------------------------------------------------------------------------- 1 | import CodiceFiscale from '../src/codice-fiscale.js'; 2 | 3 | describe('Calcolo codice fiscale inverso -> metodo .computeInverse', () => { 4 | test('è definito', () => { 5 | expect(CodiceFiscale.computeInverse).toBeDefined() 6 | }) 7 | 8 | test("se l'input non è una stringa lancia un eccezione", () => { 9 | var notAString = function () { 10 | CodiceFiscale.computeInverse(0) 11 | } 12 | expect(notAString).toThrowError("CodiceFiscale constructor accept either a valid string or a plain object. Check the documentation") 13 | }) 14 | 15 | test("restituisce falso se l'input è stringa formattata male", () => { 16 | var notValid = function () { 17 | CodiceFiscale.computeInverse('BNZVCN32SC0E573Z') 18 | } 19 | expect(notValid).toThrowError("Provided input is not a valid Codice Fiscale") 20 | }) 21 | 22 | 23 | /* Nome: MARIO 24 | * Cognome: ROSSI 25 | * Nato a : ROMA (RM) 26 | * Giorno : 23 27 | * Mese : Giugno (6) 28 | * Anno : 1980 29 | * Sesso : M 30 | */ 31 | let mario_rossi_cf = "RSSMRA80H23H501T"; 32 | 33 | test('restituisce il genere corretto', () => { 34 | expect(CodiceFiscale.computeInverse(mario_rossi_cf).gender).toEqual('M') 35 | }) 36 | 37 | test('restituisce la città natale corretta', () => { 38 | expect(CodiceFiscale.computeInverse(mario_rossi_cf).birthplace).toEqual('ROMA') 39 | }) 40 | 41 | test('restituisce la provincia della città natale corretta', () => { 42 | expect(CodiceFiscale.computeInverse(mario_rossi_cf).birthplaceProvincia).toEqual('RM') 43 | }) 44 | 45 | test('restituisce il giorno di nascita come numero compreso tra 1 e 31', () => { 46 | let day = CodiceFiscale.computeInverse(mario_rossi_cf).day 47 | expect(day >= 1 && day <= 31).toBe(true) 48 | }) 49 | 50 | test('restituisce il giorno corretto', () => { 51 | expect(CodiceFiscale.computeInverse(mario_rossi_cf).day).toBe(23) 52 | }) 53 | 54 | test('restituisce il mese corretto', () => { 55 | expect(CodiceFiscale.computeInverse(mario_rossi_cf).month).toBe(6); 56 | }) 57 | 58 | test('restituisce anno corretto', () => { 59 | expect(CodiceFiscale.computeInverse(mario_rossi_cf).year).toBe(1980); 60 | }) 61 | 62 | 63 | /* Nome: GIUSEPPE 64 | * Cognome: ESPOSITO 65 | * Nato a : NAPOLI (NP) 66 | * Giorno : 18 67 | * Mese : Febbraio (2) 68 | * Anno : 1975 69 | * Sesso : M 70 | * OMOCODIA: true 71 | */ 72 | let giuseppe_esposito_cf = "SPSGPP75B18F83VM"; 73 | 74 | test('restituisce la città natale corretta nonostante omocodia', () => { 75 | expect(CodiceFiscale.computeInverse(giuseppe_esposito_cf).birthplace).toEqual('NAPOLI') 76 | }) 77 | 78 | 79 | test('funziona con il codice fiscale di max', () => { 80 | expect(CodiceFiscale.computeInverse("CCHGNN67R05H1S3I")).toBeDefined() 81 | }) 82 | 83 | 84 | }); -------------------------------------------------------------------------------- /tests/comune.spec.js: -------------------------------------------------------------------------------- 1 | import { Comune } from '../src/comune.js'; 2 | 3 | describe("La classe Comune", ()=>{ 4 | test("trova il comune di Bolzano", ()=>{ 5 | let bz = new Comune("Bolzano", "BZ") 6 | expect(bz.nome).toEqual('BOLZANO') 7 | }) 8 | test('trova gli stati federati di micronesia come (MICRONESIA STATI FEDERATI)', () => { 9 | const micronesia = new Comune('MICRONESIA STATI FEDERATI', 'EE') 10 | expect(micronesia.nome).toEqual('MICRONESIA STATI FEDERATI') 11 | 12 | }) 13 | test('trova gli stati federati di micronesia come (STATI FEDERATI DI MICRONESIA)', () => { 14 | 15 | const micronesia = new Comune('STATI FEDERATI DI MICRONESIA', 'EE') 16 | expect(micronesia.nome).toEqual('STATI FEDERATI DI MICRONESIA') 17 | }) 18 | }) -------------------------------------------------------------------------------- /tests/index.spec.js: -------------------------------------------------------------------------------- 1 | import CodiceFiscale from '../src/codice-fiscale.js'; 2 | 3 | let { describe, test, expect } = global 4 | 5 | describe('Codice Fiscale', () => { 6 | test('esiste un oggetto chiamato CodiceFiscale', () => { 7 | expect(CodiceFiscale).toBeDefined() 8 | }) 9 | }) 10 | 11 | describe('CodiceFiscale.surnameCode', () => { 12 | test('è definito', () => { 13 | expect(CodiceFiscale.surnameCode).toBeDefined() 14 | }) 15 | 16 | test('restituisce il corretto risultato in caso di sufficienti consonanti', () => { 17 | expect(CodiceFiscale.surnameCode('Moreno')).toBe('MRN') 18 | }) 19 | 20 | test('restituisce il corretto risultato in caso di insufficienti consonanti', () => { 21 | expect(CodiceFiscale.surnameCode('Julea')).toBe('JLU') 22 | }) 23 | }) 24 | 25 | describe('CodiceFiscale.nameCode', () => { 26 | test('è definito', () => { 27 | expect(CodiceFiscale.nameCode).toBeDefined() 28 | }) 29 | 30 | test('restituisce il corretto risultato in caso di sufficienti consonanti', () => { 31 | expect(CodiceFiscale.nameCode('Marco')).toBe('MRC') 32 | }) 33 | 34 | test('restituisce il corretto risultato in caso di insufficienti consonanti', () => { 35 | expect(CodiceFiscale.nameCode('Luca')).toBe('LCU') 36 | }) 37 | }) 38 | 39 | describe('CodiceFiscale.dateCode', () => { 40 | test('è definito', () => { 41 | expect(CodiceFiscale.dateCode).toBeDefined() 42 | }) 43 | 44 | test('restituisce il corretto risultato', () => { 45 | expect(CodiceFiscale.dateCode(1, 1, 2000, 'M')).toBe('00A01') 46 | }) 47 | }) 48 | 49 | describe('CodiceFiscale.getCheckCode', () => { 50 | test('è definito', () => { 51 | expect(CodiceFiscale.getCheckCode).toBeDefined() 52 | }) 53 | 54 | test('restituisce il corretto risultato', () => { 55 | expect(CodiceFiscale.getCheckCode('MRNLCU00A01H501')).toBe('J') 56 | }) 57 | }) 58 | 59 | 60 | 61 | describe('CodiceFiscale.findLocationCode', () => { 62 | test('è definito', () => { 63 | expect(CodiceFiscale.findLocationCode).toBeDefined() 64 | }) 65 | 66 | test('trova il codice del comune', () => { 67 | expect(CodiceFiscale.findLocationCode('Roma', 'RM')).toBe('H501') 68 | }) 69 | 70 | test('trova il codice di un comune che contiene apostrofi', () => { 71 | expect(CodiceFiscale.findLocationCode("Sant'Angelo Romano", 'RM')).toBe('I284') 72 | }) 73 | 74 | test('trova il codice di un comune che contiene lettere accentate', () => { 75 | expect(CodiceFiscale.findLocationCode('Riccò del Golfo di Spezia', 'SP')).toBe('H275') 76 | }) 77 | 78 | test('se la provincia non esiste lancia un eccezione', () => { 79 | var comuneInventato = function () { 80 | CodiceFiscale.findLocationCode('Foo', 'Bar') 81 | } 82 | expect(comuneInventato).toThrowError('Comune with name of Foo and prov Bar doesn\'t exists') 83 | }) 84 | 85 | test('se il comune non esiste lancia un eccezione', () => { 86 | var comuneInventato = function () { 87 | CodiceFiscale.findLocationCode('Foo', 'RM') 88 | } 89 | expect(comuneInventato).toThrowError('Comune with name of Foo and prov RM doesn\'t exists') 90 | }) 91 | }) 92 | 93 | describe('CodiceFiscale.check', () => { 94 | test('è definito', () => { 95 | expect(CodiceFiscale.check).toBeDefined() 96 | }) 97 | 98 | test('controlla se il codice fiscale è valido', () => { 99 | expect(CodiceFiscale.check('MRNLCU00A01H501J')).toBe(true) 100 | }) 101 | 102 | test('controlla se un codice fiscale lowercase è valido', () => { 103 | expect(CodiceFiscale.check('MRNLCU00A01H501J'.toLowerCase())).toBe(true) 104 | }) 105 | 106 | test('controlla che sia composto dal non più 16 valori alfanumerici', () => { 107 | expect(CodiceFiscale.check('MRNLCU00A01H501JK')).toBe(false) 108 | }) 109 | 110 | test('controlla che sia composto dal almeno 16 valori alfanumerici', () => { 111 | expect(CodiceFiscale.check('MRNLCU00A01H501J3')).toBe(false) 112 | }) 113 | 114 | test('controlla che il carattere di controllo sia esatto', () => { 115 | expect(CodiceFiscale.check('VNDLDL87D07B963G')).toBe(false) 116 | }) 117 | 118 | test('funziona anche in caso di omocodie', () => { 119 | expect(CodiceFiscale.check('BNZVCN32S10E57PV')).toBe(true) 120 | expect(CodiceFiscale.check('BNZVCNPNSMLERTPX')).toBe(true) 121 | }) 122 | }) 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | describe("Il metodo toString()", ()=>{ 134 | test("funziona correttamente anche con le omocodie", ()=>{ 135 | let cf = new CodiceFiscale({ 136 | name: "Mario", 137 | surname: "Rossi", 138 | gender: "M", 139 | birthday: "1987-02-01", 140 | birthplace: "H501" 141 | }); 142 | 143 | expect(cf.toString()).toBe("RSSMRA87B01H501A"); 144 | cf.omocodie(); 145 | expect(cf.toString()).toBe("RSSMRA87B01H501A"); 146 | 147 | }) 148 | }) 149 | -------------------------------------------------------------------------------- /tests/inverse.spec.js: -------------------------------------------------------------------------------- 1 | import CodiceFiscale from '../src/codice-fiscale.js'; 2 | describe('Calcolo codice fiscale inverso ', () => { 3 | test('è definito', () => { 4 | expect(CodiceFiscale.computeInverse).toBeDefined() 5 | }) 6 | 7 | test("se l'input non è una stringa lancia un eccezione", () => { 8 | var notAString = function () { 9 | CodiceFiscale.computeInverse(0) 10 | } 11 | expect(notAString).toThrowError("CodiceFiscale constructor accept either a valid string or a plain object. Check the documentation") 12 | }) 13 | 14 | test("restituisce falso se l'input è stringa formattata male", () => { 15 | var notValid = function () { 16 | CodiceFiscale.computeInverse('BNZVCN32SC0E573Z') 17 | } 18 | expect(notValid).toThrowError("Provided input is not a valid Codice Fiscale") 19 | }) 20 | 21 | 22 | /* Nome: VINCENZO 23 | * Cognome: RIGHI 24 | * Nato a : NAPOLI (NA) 25 | * Giorno : 24 26 | * Mese : Luglio (7) 27 | * Anno : 1957 28 | * Sesso : M 29 | */ 30 | let enzo_righi_cf = "VNCRGH57L24F839U"; 31 | 32 | test('restituisce il genere corretto', () => { 33 | expect(CodiceFiscale.computeInverse(enzo_righi_cf).gender).toEqual('M') 34 | }) 35 | 36 | test('restituisce la città natale corretta', () => { 37 | expect(CodiceFiscale.computeInverse(enzo_righi_cf).birthplace).toEqual('NAPOLI') 38 | }) 39 | 40 | test('restituisce la provincia della città natale corretta', () => { 41 | expect(CodiceFiscale.computeInverse(enzo_righi_cf).birthplaceProvincia).toEqual('NA') 42 | }) 43 | 44 | test('restituisce il giorno di nascita come numero compreso tra 1 e 31', () => { 45 | let day = CodiceFiscale.computeInverse(enzo_righi_cf).day 46 | expect(day >= 1 && day <= 31).toBe(true) 47 | }) 48 | 49 | test('restituisce il giorno corretto', () => { 50 | expect(CodiceFiscale.computeInverse(enzo_righi_cf).day).toBe(24) 51 | }) 52 | 53 | test('restituisce il mese corretto', () => { 54 | expect(CodiceFiscale.computeInverse(enzo_righi_cf).month).toBe(7); 55 | }) 56 | 57 | test('restituisce anno corretto', () => { 58 | expect(CodiceFiscale.computeInverse(enzo_righi_cf).year).toBe(1957); 59 | }) 60 | 61 | test('la data corretta', () => { 62 | expect(CodiceFiscale.computeInverse(enzo_righi_cf).birthday).toBe("1957-07-24"); 63 | }) 64 | 65 | test('il cf segnalato da Max',()=>{ 66 | expect(CodiceFiscale.computeInverse('CCHGNN67R05H1S3I')).toBeDefined() 67 | expect(new CodiceFiscale('CCHGNN67R05H1S3I')).toBeDefined() 68 | }) 69 | 70 | }) 71 | 72 | 73 | describe('Calcolo codice fiscale inverso per le donne', () => { 74 | 75 | 76 | 77 | /* Nome: MARIA 78 | * Cognome: ROSSI 79 | * Nato a : ROMA (RM) 80 | * Giorno : 23 81 | * Mese : Giugno (6) 82 | * Anno : 1980 83 | * Sesso : F 84 | */ 85 | let maria_rossi_cf = "RSSMRA80H63H501X"; 86 | 87 | test('restituisce il genere corretto', () => { 88 | expect(CodiceFiscale.computeInverse(maria_rossi_cf).gender).toEqual('F') 89 | }) 90 | 91 | test('restituisce la città natale corretta', () => { 92 | expect(CodiceFiscale.computeInverse(maria_rossi_cf).birthplace).toEqual('ROMA') 93 | }) 94 | 95 | test('restituisce la provincia della città natale corretta', () => { 96 | expect(CodiceFiscale.computeInverse(maria_rossi_cf).birthplaceProvincia).toEqual('RM') 97 | }) 98 | 99 | test('restituisce il giorno di nascita come numero compreso tra 1 e 31', () => { 100 | let day = CodiceFiscale.computeInverse(maria_rossi_cf).day 101 | expect(day >= 1 && day <= 31).toBe(true) 102 | }) 103 | 104 | test('restituisce il giorno corretto', () => { 105 | expect(CodiceFiscale.computeInverse(maria_rossi_cf).day).toBe(23) 106 | }) 107 | 108 | test('restituisce il mese corretto', () => { 109 | expect(CodiceFiscale.computeInverse(maria_rossi_cf).month).toBe(6); 110 | }) 111 | 112 | test('restituisce anno corretto', () => { 113 | expect(CodiceFiscale.computeInverse(maria_rossi_cf).year).toBe(1980); 114 | }) 115 | 116 | test('la data corretta', () => { 117 | expect(CodiceFiscale.computeInverse(maria_rossi_cf).birthday).toBe("1980-06-23"); 118 | }) 119 | 120 | 121 | }) 122 | 123 | 124 | describe('Calcolo del codice fiscale inverso per comuni che sono diventati frazione o che hanno cambiato provincia',()=>{ 125 | 126 | /* Nome: MARIA 127 | * Cognome: ROSSI 128 | * Nato a : Acquacanina (MC) 129 | * Giorno : 23 130 | * Mese : Giugno (6) 131 | * Anno : 1980 132 | * Sesso : F 133 | */ 134 | // Acquacanina non è più un comune ma una frazione 135 | 136 | let maria_rossi_cf = "RSSMRA80T63A031E"; 137 | 138 | test('funziona con i comuni soppressi', () => { 139 | expect(CodiceFiscale.reverse(maria_rossi_cf).birthplace).toEqual('ACQUACANINA'); 140 | expect(CodiceFiscale.reverse(maria_rossi_cf).birthplaceProvincia).toEqual('MC'); 141 | }) 142 | 143 | 144 | /* Nome: MARIA 145 | * Cognome: ROSSI 146 | * Nato a : VIMERCATE (MI) 147 | * Giorno : 23 148 | * Mese : Giugno (6) 149 | * Anno : 1980 150 | * Sesso : F 151 | */ 152 | // Vimercate nel 1980 era in provincia di Milano, ora appartiene alla provincia di Monza e della Brianza (MB) 153 | 154 | let maria_rossi_cf2 = "RSSMRA80T63M052X"; 155 | test('funziona con i comuni che hanno cambiato provincia, restituendo la provincia a cui è assegnato attualmente il comune', () => { 156 | expect(CodiceFiscale.reverse(maria_rossi_cf2).birthplace).toEqual('VIMERCATE'); 157 | expect(CodiceFiscale.reverse(maria_rossi_cf2).birthplaceProvincia).toEqual('MB'); 158 | }); 159 | 160 | 161 | describe('non rileva anomalie con il comune di Calendasco',()=>{ 162 | 163 | test('calcola il codice fiscale', () => { 164 | expect(CodiceFiscale.compute({ 165 | name: 'Mario', 166 | surname: 'Rossi', 167 | gender: 'M', 168 | day: 25, 169 | month: 12, 170 | year: 1980, 171 | birthplace: 'Calendasco' 172 | })) 173 | .toBe('RSSMRA80T25B405Z') 174 | }) 175 | 176 | test("e anche il codice fiscale inverso", () => { 177 | 178 | let reverse = CodiceFiscale.reverse('RSSMRA80T25B405Z'); 179 | expect(reverse.name).toEqual('MRA'); 180 | expect(reverse.surname).toEqual('RSS'); 181 | expect(reverse.gender).toEqual('M'); 182 | expect(reverse.day).toEqual(25); 183 | expect(reverse.month).toEqual(12); 184 | expect(reverse.year).toEqual(1980); 185 | expect(reverse.birthplace).toEqual('CALENDASCO'); 186 | expect(reverse.birthplaceProvincia).toEqual('PC'); 187 | }); 188 | 189 | }); 190 | 191 | }) 192 | -------------------------------------------------------------------------------- /tests/omocodie.spec.js: -------------------------------------------------------------------------------- 1 | import CodiceFiscale from '../src/codice-fiscale.js'; 2 | 3 | describe('CodiceFiscale.getOmocodie', () => { 4 | test('è definito', () => { 5 | expect(CodiceFiscale.getOmocodie).toBeDefined() 6 | }) 7 | 8 | test('calcola le omocodie dato un codice fiscale', () => { 9 | expect(CodiceFiscale.getOmocodie('BNZVCN32S10E573Z')) 10 | .toEqual(expect.arrayContaining(['BNZVCN32S10E57PV', 'BNZVCNPNSMLERTPX'])) 11 | }) 12 | test('le omocodie generate sono tutte differenti', () => { 13 | const omocodie = CodiceFiscale.getOmocodie('BNZVCN32S10E573Z'); 14 | const omocodieSenzaDuplicati = [...new Set(omocodie)] 15 | expect(omocodie.length) 16 | .toEqual(omocodieSenzaDuplicati.length) 17 | }) 18 | test('calcola 127 omocodie per ogni codice fiscale codice fiscale', () => { 19 | expect(CodiceFiscale.getOmocodie('BNZVCN32S10E573Z').length) 20 | .toEqual(127) 21 | }) 22 | 23 | test('tutte le omocodie vengono riconosciute come codici fiscali validi', () => { 24 | const omocodie = CodiceFiscale.getOmocodie('BNZVCN32S10E573Z'); 25 | for(let omocodia of omocodie) 26 | expect(CodiceFiscale.check(omocodia)).toEqual(true) 27 | }) 28 | 29 | test('tutte le omocodie generate dal metodo vengono riconosciute come omocodie', () => { 30 | const omocodie = CodiceFiscale.getOmocodie('BNZVCN32S10E573Z'); 31 | for(let omocodia of omocodie) 32 | expect(CodiceFiscale.isOmocodia(omocodia)).toEqual(true) 33 | }) 34 | 35 | 36 | }) 37 | 38 | 39 | describe('CodiceFiscale.isOmocodia', () => { 40 | test('è definito', () => { 41 | expect(CodiceFiscale.isOmocodia).toBeDefined() 42 | }) 43 | 44 | test('verifica se un codice fornito è una omocodia', () => { 45 | expect(CodiceFiscale.isOmocodia('BNZVCN32S10E573Z')).toEqual(false); 46 | expect(CodiceFiscale.isOmocodia('BNZVCN32S10E57PV')).toEqual(true); 47 | expect(CodiceFiscale.isOmocodia('BNZVCNPNSMLERTPX')).toEqual(true); 48 | expect(CodiceFiscale.isOmocodia('CCHGNN67R05H1S3I')).toEqual(true); 49 | }) 50 | 51 | }) 52 | 53 | 54 | 55 | describe('CodiceFiscale.fromOmocodiaToOriginal', () => { 56 | test('è definito', () => { 57 | expect(CodiceFiscale.fromOmocodiaToOriginal).toBeDefined() 58 | }) 59 | 60 | test('calcola la versione non omocodica di un omocodia', () => { 61 | expect(CodiceFiscale.fromOmocodiaToOriginal('BNZVCN32S10E57PV')) 62 | .toEqual('BNZVCN32S10E573Z') 63 | }) 64 | 65 | 66 | test('tutte le omocodie vengono riconosciute come codici fiscali validi', () => { 67 | const omocodie = CodiceFiscale.getOmocodie('BNZVCN32S10E573Z'); 68 | for(let omocodia of omocodie) 69 | expect(CodiceFiscale.fromOmocodiaToOriginal(omocodia)).toEqual('BNZVCN32S10E573Z') 70 | }) 71 | 72 | 73 | 74 | }) 75 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "module": "commonjs", 5 | "esModuleInterop": true 6 | }, 7 | "exclude": ["./node_modules/**/*.ts"] 8 | } -------------------------------------------------------------------------------- /types/codice-fiscale.d.ts: -------------------------------------------------------------------------------- 1 | import { Comune } from "./comune"; 2 | import { birthplaceFields } from "./utils"; 3 | 4 | export type Gender = "F" | "M"; 5 | 6 | export interface ICodiceFiscaleObject { 7 | name: string; 8 | surname: string; 9 | gender: Gender; 10 | day: number; 11 | month: number; 12 | year: number; 13 | birthplace: string; 14 | birthplaceProvincia: string; 15 | cf?: string; 16 | } 17 | 18 | declare class CodiceFiscale { 19 | day: number; 20 | month: number; 21 | year: number; 22 | readonly cf: string; 23 | readonly nameCode: string; 24 | readonly surnameCode: string; 25 | readonly checkCode: string; 26 | static utils: { 27 | birthplaceFields: typeof birthplaceFields; 28 | }; 29 | birthday: Date; 30 | birthplace: Comune; 31 | name: string; 32 | surname: string; 33 | gender: Gender; 34 | private code; 35 | constructor(data: string | ICodiceFiscaleObject); 36 | static getCheckCode(codiceFiscale: string): string; 37 | static findLocationCode(name: string, prov?: string): string; 38 | static computeInverse(codiceFiscale: string): ICodiceFiscaleObject; 39 | static compute(obj: object): string; 40 | static check(codiceFiscale: string): boolean; 41 | static getOmocodie(cf: string): string[]; 42 | static nameCode(name: string): string; 43 | static surnameCode(surname: string): string; 44 | static dateCode(day: number, month: number, year: number, gender: Gender): string; 45 | toString(): string; 46 | toJSON(): ICodiceFiscaleObject; 47 | isValid(): boolean; 48 | omocodie(): string[]; 49 | compute(): void; 50 | reverse(): ICodiceFiscaleObject; 51 | private checkGender; 52 | private getSurnameCode; 53 | private getNameCode; 54 | private dateCode; 55 | } 56 | 57 | export default CodiceFiscale; 58 | -------------------------------------------------------------------------------- /types/comune.d.ts: -------------------------------------------------------------------------------- 1 | export interface IComuneObject { 2 | nome: string; 3 | prov?: string; 4 | cc?: string; 5 | } 6 | export declare class Comune { 7 | nome: string; 8 | prov: string; 9 | cc: string; 10 | readonly nomeNorm: string; 11 | constructor(nome: string, prov?: string, cc?: string, check?: boolean); 12 | static GetByName(name: string, prov?: string): Comune; 13 | static GetByCC(cc: string): Comune; 14 | private searchByName; 15 | private searchByNameAndProvince; 16 | } 17 | -------------------------------------------------------------------------------- /types/constants.d.ts: -------------------------------------------------------------------------------- 1 | export declare const MONTH_CODES: string[]; 2 | export declare const CHECK_CODE_ODD: { 3 | 0: number; 4 | 1: number; 5 | 2: number; 6 | 3: number; 7 | 4: number; 8 | 5: number; 9 | 6: number; 10 | 7: number; 11 | 8: number; 12 | 9: number; 13 | A: number; 14 | B: number; 15 | C: number; 16 | D: number; 17 | E: number; 18 | F: number; 19 | G: number; 20 | H: number; 21 | I: number; 22 | J: number; 23 | K: number; 24 | L: number; 25 | M: number; 26 | N: number; 27 | O: number; 28 | P: number; 29 | Q: number; 30 | R: number; 31 | S: number; 32 | T: number; 33 | U: number; 34 | V: number; 35 | W: number; 36 | X: number; 37 | Y: number; 38 | Z: number; 39 | }; 40 | export declare const CHECK_CODE_EVEN: { 41 | 0: number; 42 | 1: number; 43 | 2: number; 44 | 3: number; 45 | 4: number; 46 | 5: number; 47 | 6: number; 48 | 7: number; 49 | 8: number; 50 | 9: number; 51 | A: number; 52 | B: number; 53 | C: number; 54 | D: number; 55 | E: number; 56 | F: number; 57 | G: number; 58 | H: number; 59 | I: number; 60 | J: number; 61 | K: number; 62 | L: number; 63 | M: number; 64 | N: number; 65 | O: number; 66 | P: number; 67 | Q: number; 68 | R: number; 69 | S: number; 70 | T: number; 71 | U: number; 72 | V: number; 73 | W: number; 74 | X: number; 75 | Y: number; 76 | Z: number; 77 | }; 78 | export declare const OMOCODIA_TABLE: { 79 | 0: string; 80 | 1: string; 81 | 2: string; 82 | 3: string; 83 | 4: string; 84 | 5: string; 85 | 6: string; 86 | 7: string; 87 | 8: string; 88 | 9: string; 89 | }; 90 | export declare const CHECK_CODE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 91 | -------------------------------------------------------------------------------- /types/geo-data.d.ts: -------------------------------------------------------------------------------- 1 | export declare const COMUNI: string[][]; 2 | export declare const PROVINCE: { 3 | AG: string; 4 | AL: string; 5 | AN: string; 6 | AO: string; 7 | AP: string; 8 | AQ: string; 9 | AR: string; 10 | AT: string; 11 | AV: string; 12 | BA: string; 13 | BG: string; 14 | BI: string; 15 | BL: string; 16 | BN: string; 17 | BO: string; 18 | BR: string; 19 | BS: string; 20 | BT: string; 21 | BZ: string; 22 | CA: string; 23 | CB: string; 24 | CE: string; 25 | CH: string; 26 | CI: string; 27 | CL: string; 28 | CN: string; 29 | CO: string; 30 | CR: string; 31 | CS: string; 32 | CT: string; 33 | CZ: string; 34 | EN: string; 35 | FC: string; 36 | FE: string; 37 | FG: string; 38 | FI: string; 39 | FM: string; 40 | FR: string; 41 | GE: string; 42 | GO: string; 43 | GR: string; 44 | IM: string; 45 | IS: string; 46 | KR: string; 47 | LC: string; 48 | LE: string; 49 | LI: string; 50 | LO: string; 51 | LT: string; 52 | LU: string; 53 | MB: string; 54 | MC: string; 55 | ME: string; 56 | MI: string; 57 | MN: string; 58 | MO: string; 59 | MS: string; 60 | MT: string; 61 | NA: string; 62 | NO: string; 63 | NU: string; 64 | OG: string; 65 | OR: string; 66 | OT: string; 67 | PA: string; 68 | PC: string; 69 | PD: string; 70 | PE: string; 71 | PG: string; 72 | PI: string; 73 | PN: string; 74 | PO: string; 75 | PR: string; 76 | PT: string; 77 | PU: string; 78 | PV: string; 79 | PZ: string; 80 | RA: string; 81 | RC: string; 82 | RE: string; 83 | RG: string; 84 | RI: string; 85 | RM: string; 86 | RN: string; 87 | RO: string; 88 | SA: string; 89 | SI: string; 90 | SO: string; 91 | SP: string; 92 | SR: string; 93 | SS: string; 94 | SV: string; 95 | TA: string; 96 | TE: string; 97 | TN: string; 98 | TO: string; 99 | TP: string; 100 | TR: string; 101 | TS: string; 102 | TV: string; 103 | UD: string; 104 | VA: string; 105 | VB: string; 106 | VC: string; 107 | VE: string; 108 | VI: string; 109 | VR: string; 110 | VS: string; 111 | VT: string; 112 | VV: string; 113 | }; 114 | -------------------------------------------------------------------------------- /types/utils.d.ts: -------------------------------------------------------------------------------- 1 | export declare function normalizeString(str: string): string; 2 | export declare function daysInMonth(m: number, y: number): 29 | 28 | 30 | 31; 3 | export declare function isValidDate(d: number, m: number, y: number): boolean; 4 | export declare function getValidDate(d: number, m: number, y: number): Date; 5 | export declare function extractVowels(str: string): string; 6 | export declare function extractConsonants(str: string): string; 7 | export declare function pad(n: number, size?: number): string; 8 | export declare function birthplaceFields(selector: string): void; 9 | -------------------------------------------------------------------------------- /update_comuni.py: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/python 3 | # -*- coding: iso-8859-1 -*- 4 | 5 | import urllib.request 6 | from os import path, curdir 7 | import csv 8 | import re 9 | import os 10 | 11 | # PERMALINK : do not change without a reason 12 | ISTAT_DATA_URL = "https://www.istat.it/storage/codici-unita-amministrative/Elenco-comuni-italiani.csv" 13 | ISTAT_FILE_NAME = "Elenco-comuni-italiani.csv" 14 | ISTAT_FILE_PATH = path.join(curdir, ISTAT_FILE_NAME) 15 | 16 | COMUNI_FILE_NAME = "lista-comuni.js" 17 | COMUNI_FILE_PATH = path.join(curdir, 'src', COMUNI_FILE_NAME) 18 | 19 | PROVINCE_FILE_NAME = "lista-province.js" 20 | PROVINCE_FILE_PATH = path.join(curdir, 'src', PROVINCE_FILE_NAME) 21 | 22 | print('Scarico i dati...') 23 | urllib.request.urlretrieve(ISTAT_DATA_URL, ISTAT_FILE_PATH) 24 | 25 | print('Download completato') 26 | print('Lettura dei nuovi dati in corso') 27 | 28 | nuova_lista_comuni = [] 29 | nuova_lista_province = [] 30 | with open(ISTAT_FILE_PATH) as csvfile: 31 | reader = csv.DictReader(csvfile, delimiter=';') 32 | #next(reader, None) #skip the header 33 | 34 | for row in reader: 35 | cod = row['Codice Catastale del comune'] 36 | prov = row['Sigla automobilistica'] 37 | name = row["Denominazione in italiano"] 38 | 39 | 40 | # Remove accents and use uppercase for comune's name 41 | name = name.lower() 42 | 43 | # Remove a the end of a word 44 | name = re.compile(r"(à|á)(?=\s|$|-)").sub( "a'", name) 45 | name = re.compile(r"(è|é)(?=\s|$|-)").sub( "e'", name) 46 | name = re.compile(r"(ì|í)(?=\s|$|-)").sub( "i'", name) 47 | name = re.compile(r"(ò|ó)(?=\s|$|-)").sub( "o'", name) 48 | name = re.compile(r"(ù|ú)(?=\s|$|-)").sub( "u'", name) 49 | 50 | #Remove inside a word 51 | name = name.translate(str.maketrans("àáâêèéìíôòóùúç","aaaeeeiiooouuc")) 52 | 53 | #make everything uppercase and remove empty spaces 54 | name = name.upper().strip() 55 | 56 | 57 | nuova_lista_comuni.append([ cod, prov, name]) 58 | 59 | print("Confronto i nuovi dati con quelli presenti") 60 | with open(COMUNI_FILE_PATH, 'r') as f: 61 | txt = f.read() 62 | txt = txt.replace("export const COMUNI = ", "") 63 | lista_comuni = eval(txt) 64 | for comune in lista_comuni: 65 | del comune[3] 66 | 67 | with open(PROVINCE_FILE_PATH, 'r') as f: 68 | txt = f.read() 69 | txt = txt.replace("export const PROVINCE = ", "").replace(':', '":').replace(",\n",",\n\"").replace("{\n","{\n\"") 70 | lista_province = eval(txt+"\n").keys() 71 | 72 | 73 | 74 | nuove_province = [] 75 | nuovi_comuni = [] 76 | for comune in nuova_lista_comuni: 77 | if comune not in lista_comuni: 78 | lista_comuni.append(comune) 79 | nuovi_comuni.append(comune) 80 | if comune[1] not in lista_province: 81 | nuove_province.append(comune[1]) 82 | 83 | 84 | for comune in lista_comuni: 85 | if comune[:3] in nuova_lista_comuni: 86 | try: 87 | comune[3] = 1 88 | except: 89 | comune.append(1) 90 | else: 91 | try: 92 | comune[3] = 0 93 | except: 94 | comune.append(0) 95 | 96 | nuove_province = list(set(nuove_province)) # Remove duplicates 97 | 98 | print(f"Trovati {len(nuovi_comuni)} nuovi comuni") 99 | print(f"Trovati {len(nuove_province)} nuove province") 100 | 101 | # Nuove province 102 | if len(nuove_province): 103 | NUOVE_PROVINCE_FILE_NAME = "nuove_province.txt" 104 | NUOVE_PROVINCE_FILE_PATH = path.join(curdir, NUOVE_PROVINCE_FILE_NAME) 105 | print(f"Le sigle delle nuove province sono salvate nel file {NUOVE_PROVINCE_FILE_NAME}") 106 | with open(NUOVE_PROVINCE_FILE_PATH, 'w') as f: 107 | for provincia in nuove_province: 108 | print(provincia, file=f) 109 | f.close() 110 | 111 | # Sorting 112 | comuni_txt = list(map(lambda x: "\r,\r".join([x[2],x[0],x[1],str(x[3])]), lista_comuni)) 113 | comuni_txt.sort() 114 | 115 | with open(COMUNI_FILE_PATH,'w') as f: 116 | f.write("export const COMUNI = [ ") 117 | last_idx = len(comuni_txt) - 1 118 | for i, el in enumerate(comuni_txt): 119 | comps = el.split("\r,\r") 120 | if " * " in comps[0]: 121 | comps[0] = comps[0].split(" * ")[0] 122 | f.write(f"[\"{comps[1]}\",\"{comps[2]}\",\"{comps[0]}\",{comps[3]}]") 123 | if i != last_idx: 124 | f.write(",") 125 | f.write("\n") 126 | f.write("]") 127 | 128 | 129 | print(f"File {COMUNI_FILE_NAME} aggiornato") 130 | # Clean up 131 | os.remove(ISTAT_FILE_PATH) -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | fs.createReadStream('./dist/codice.fiscale.var.js') 3 | .pipe(fs.createWriteStream('./dist/codice-fiscale-var.js')) -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const webpack = require('webpack') 3 | const createVariants = require('parallel-webpack').createVariants 4 | 5 | function createConfig (options) { 6 | return { 7 | mode: "production", 8 | entry: { 9 | 'codice.fiscale': './src/codice-fiscale.js' 10 | }, 11 | output: { 12 | path: path.resolve(__dirname, 'dist'), 13 | filename: 'codice.fiscale.' + options.target + '.js', 14 | library: 'CodiceFiscale', 15 | libraryTarget: options.target 16 | }, 17 | module: { 18 | rules: [ 19 | { 20 | test: /\.json$/, 21 | loader: 'json-loader' 22 | }, { 23 | test: /\.js$/, 24 | exclude: /(node_modules|bower_components)/, 25 | use: { 26 | loader: 'babel-loader', 27 | } 28 | } 29 | ] 30 | }, 31 | optimization: { 32 | minimize: true 33 | } 34 | } 35 | } 36 | 37 | module.exports = createVariants({ 38 | target: [ 39 | 'var', 40 | 'commonjs2', 41 | 'umd', 42 | 'amd' 43 | ] 44 | }, createConfig) 45 | --------------------------------------------------------------------------------