Merge branch 'master' into master

This commit is contained in:
Luca Adalberto Vandro 2021-02-17 11:26:51 +01:00 committed by GitHub
commit 8c39175b24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 14 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "codice-fiscale-js", "name": "codice-fiscale-js",
"version": "2.3.7", "version": "2.3.8",
"description": "The Italian Tax Code Library for Javascript and Typescript", "description": "The Italian Tax Code Library for Javascript and Typescript",
"main": "dist/codice.fiscale.commonjs2.js", "main": "dist/codice.fiscale.commonjs2.js",
"types": "types/codice-fiscale.d.ts", "types": "types/codice-fiscale.d.ts",
@ -29,7 +29,8 @@
"test": "jest", "test": "jest",
"fix": "standard --fix", "fix": "standard --fix",
"standard": "standard", "standard": "standard",
"rename": "node utils.js" "rename": "node utils.js",
"webpack": "webpack"
}, },
"author": "Luca Vandro <lucavandro@gmail.com>", "author": "Luca Vandro <lucavandro@gmail.com>",
"contributors": [ "contributors": [

View File

@ -35,6 +35,7 @@ class CodiceFiscale {
} }
constructor (data) { constructor (data) {
if (typeof data === 'string') { if (typeof data === 'string') {
data = data.toUpperCase()
if (CodiceFiscale.check(data)) { if (CodiceFiscale.check(data)) {
this.code = data this.code = data
this.reverse() this.reverse()
@ -157,8 +158,8 @@ class CodiceFiscale {
} }
omocodie () { omocodie () {
const results = [] const results = []
let lastOmocode = (this.code = this.code.slice(0, 15)) let lastOmocode = (this.code.slice(0, 15))
for (let i = this.code.length - 1; i >= 0; i = i - 1) { for (let i = this.code.length - 1; i >= 0; i--) {
const char = this.code[i] const char = this.code[i]
if (char.match(/\d/) !== null) { if (char.match(/\d/) !== null) {
lastOmocode = `${lastOmocode.substr(0, i)}${OMOCODIA_TABLE[char]}${lastOmocode.substr(i + 1)}` lastOmocode = `${lastOmocode.substr(0, i)}${OMOCODIA_TABLE[char]}${lastOmocode.substr(i + 1)}`

View File

@ -105,7 +105,10 @@ describe('CodiceFiscale.compute', () => {
.toBeDefined() .toBeDefined()
}) })
let invalidCfis = "BLIPTR93MO4A674Q";
test('controlla il codice fiscale con una regex', () => {
expect(CodiceFiscale.check(invalidCfis)).toEqual(false);
});
test("calcola il codice fiscale di persone nate all'estero", () => { test("calcola il codice fiscale di persone nate all'estero", () => {
@ -444,7 +447,21 @@ describe("La classe Comune", ()=>{
}) })
}) })
let invalidCfis = "BLIPTR93MO4A674Q";
test('check invalid cfis by regex control', () => {
expect(CodiceFiscale.check(invalidCfis)).toEqual(false); 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");
})
})