This commit is contained in:
Luca Vandro 2021-02-17 10:45:00 +01:00
parent 6223e44534
commit eaa9556597
3 changed files with 21 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "codice-fiscale-js",
"version": "2.3.7",
"version": "2.3.8",
"description": "The Italian Tax Code Library for Javascript and Typescript",
"main": "dist/codice.fiscale.commonjs2.js",
"types": "types/codice-fiscale.d.ts",

View File

@ -154,8 +154,8 @@ class CodiceFiscale {
}
omocodie () {
const results = []
let lastOmocode = (this.code = this.code.slice(0, 15))
for (let i = this.code.length - 1; i >= 0; i = i - 1) {
let lastOmocode = (this.code.slice(0, 15))
for (let i = this.code.length - 1; i >= 0; i--) {
const char = this.code[i]
if (char.match(/\d/) !== null) {
lastOmocode = `${lastOmocode.substr(0, i)}${OMOCODIA_TABLE[char]}${lastOmocode.substr(i + 1)}`

View File

@ -441,5 +441,23 @@ describe("La classe Comune", ()=>{
let bz = new Comune("Bolzano", "BZ")
expect(bz.nome).toEqual('BOLZANO')
})
})
describe("Il metodo toString()", ()=>{
test("funziona correttamente anche con le omocodie", ()=>{
let cf = new CodiceFiscale({
name: "Mario",
surname: "Rossi",
gender: "M",
birthday: "1987-02-01",
birthplace: "H501"
});
expect(cf.toString()).toBe("RSSMRA87B01H501A");
cf.omocodie();
expect(cf.toString()).toBe("RSSMRA87B01H501A");
})
})