2018-09-03 17:16:53 +02:00
|
|
|
# TypeScript
|
2018-09-03 14:59:53 +02:00
|
|
|
Create and compute
|
|
|
|
-------
|
|
|
|
|
|
|
|
Compute a codice fiscale given:
|
|
|
|
|
|
|
|
- Name (String)
|
|
|
|
- Surname (String)
|
|
|
|
- Gender (String) ["M","F"]
|
|
|
|
- Birthday day (Number)
|
|
|
|
- Birthday month (Number)
|
|
|
|
- Birthday year (Number)
|
|
|
|
- Place of birth (String)
|
|
|
|
- Province of birth (String)
|
|
|
|
|
|
|
|
```js
|
2019-03-28 23:04:38 +01:00
|
|
|
import CodiceFiscale from 'codice-fiscale-js';
|
2018-09-03 14:59:53 +02:00
|
|
|
const cf = new CodiceFiscale({
|
|
|
|
name: "Enzo",
|
|
|
|
surname: "Righi",
|
|
|
|
gender: "M",
|
|
|
|
day: 24,
|
|
|
|
month: 7,
|
|
|
|
year: 1957,
|
|
|
|
birthplace: "Napoli",
|
|
|
|
birthplaceProvincia: "NA" // Optional
|
|
|
|
});
|
|
|
|
console.log(cf);
|
|
|
|
```
|
|
|
|
Support foreign countries
|
|
|
|
===
|
|
|
|
Use the italian name of the foreign country (e.g. Francia, for France) as birthplace
|
|
|
|
and "EE" as birthplace_provincia
|
|
|
|
```js
|
|
|
|
const cf = new CodiceFiscale({
|
|
|
|
name: "Enzo",
|
|
|
|
surname: "Righi",
|
|
|
|
gender: "M",
|
|
|
|
day: 24,
|
|
|
|
month: 7,
|
|
|
|
year: 1957,
|
|
|
|
birthplace: "Francia",
|
|
|
|
birthplaceProvincia: "EE"
|
|
|
|
});
|
|
|
|
console.log(cf);
|
|
|
|
```
|
|
|
|
----------
|
|
|
|
Inverse Computation
|
|
|
|
-------
|
|
|
|
Get a person data for a given Codice Fiscale. Throws an exeption if the code provided as argument is invalid.
|
|
|
|
```js
|
|
|
|
const cf = new CodiceFiscale("RGHNZE10L24F839E");
|
|
|
|
console.log(cf.toJSON());
|
|
|
|
/**
|
|
|
|
OUTPUT
|
|
|
|
{
|
|
|
|
name: "NZE",
|
|
|
|
surname: "RGH",
|
|
|
|
gender: "M",
|
|
|
|
day: 24,
|
|
|
|
month: 7,
|
|
|
|
year: 2010,
|
|
|
|
birthplace: "NAPOLI",
|
|
|
|
birthplaceProvincia: "NA"
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
```
|
|
|
|
Or you can access reversed attribute via instance properties:
|
|
|
|
```js
|
|
|
|
const cf = new CodiceFiscale("RGHNZE10L24F839E");
|
|
|
|
console.log(cf.toJSON());
|
|
|
|
cf.name === "NZE"; // true
|
|
|
|
cf.surname === "RGH"; // true
|
|
|
|
cf.gender === "M"; // true
|
|
|
|
cf.day === 24; // true
|
|
|
|
cf.month === 7; // true
|
|
|
|
cf.year === 2010; // true
|
|
|
|
cf.birthday === new Date(2010, 6, 24,0,0,0,0); // true
|
|
|
|
cf.birthplace === "NAPOLI"; // true
|
|
|
|
cf.birthplaceProvincia === "NA"; // true
|
|
|
|
```
|
|
|
|
Omocodie
|
|
|
|
-------
|
|
|
|
Get all the omocodie for a given Codice Fiscale. It returns an array of strings
|
|
|
|
|
|
|
|
```js
|
|
|
|
const cf = new CodiceFiscale("VNDLDL10A01G410Z");
|
|
|
|
const omocodie = cf.omocodie();
|
|
|
|
```
|