heavybeard / codice-fiscale

Javascript object for managing the italian tax code
http://heavybeard.github.io/codice-fiscale/
MIT License
9 stars 4 forks source link

Cannot read the property of '1' of undefinied #5

Closed emiljano539 closed 6 years ago

emiljano539 commented 6 years ago

Issue in line 285 of CodiceFiscale.js for the commune recognition : return this._commune()[0][1];

heavybeard commented 6 years ago

Hi @emiljano539 , can you provide the steps to reproduce the error?

Or if you can, a PR to fix it

Many thanks!

as reference -> https://github.com/heavybeard/codice-fiscale/blob/master/source/CodiceFiscale.js#L285

emiljano539 commented 6 years ago

THE HTML CODE :

<html>
<script src="./CodiceFiscale.js" type="text/javascript"></script>
<script>
  var person = new CodiceFiscale({
    name: 'Mario',
    lastname: 'Rossi',
    day: '25',
    month: '04',
    year: '1945',
    isMale: true,
    communeName: 'Milano'
  });
  console.log(person.taxCode());       // RSSMRA45D25F205N
  console.log(person.lastnameCode());  // RSS
  person.nameCode();      //    MRA
  person.dateCode();      //       45D25
  person.yearCode();      //       45
  person.monthCode();     //         D
  person.dayCode();       //          25
  person.communeCode();   //            F205
  person.controlChar();   //                N
</script>
</html>

Is showing the error. Where is the mistake ? Am i missing something in the javascript code or what?

emiljano539 commented 6 years ago

The console log :

Uncaught TypeError: Cannot read property '1' of undefined
    at CodiceFiscale.communeCode (CodiceFiscale.js:285)
    at CodiceFiscale.taxCode (CodiceFiscale.js:165)
    at index.html:13
heavybeard commented 6 years ago

Understood! Thanks for your example.

You need to use the dist version of the script, I suggest the minified version.

<script src="./CodiceFiscale.min.js" type="text/javascript"></script>

The source version hasn't the cadastral codes list, so the undefined error comes up

emiljano539 commented 6 years ago

Now it's working thanks. What about a reverse codicefiscale search? How can it be done?

emiljano539 commented 6 years ago

How can i insert a codice fiscale that shows the birthday/birthplace or gender?

heavybeard commented 6 years ago

At the time the functionality you asked doesn't exist, but it can be a great feature. Unfortunately now I can't work on it, but I'll be glad to help who want to develop it.

If you think you can do it, you can fork this repo, work on the feature and return with a PR.

heavybeard commented 6 years ago

If you want you can work with strings (.substring method maybe) for taking a specific info, it's not the most elegant way, but it works