mirror of
https://github.com/danog/CodiceFiscaleJS.git
synced 2024-11-26 20:14:55 +01:00
841 lines
278 KiB
JavaScript
841 lines
278 KiB
JavaScript
|
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
||
|
"use strict";
|
||
|
|
||
|
var _comune = require("./comune");
|
||
|
|
||
|
var _constants = require("./constants");
|
||
|
|
||
|
var _utils = require("./utils");
|
||
|
|
||
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||
|
|
||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||
|
|
||
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||
|
|
||
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||
|
|
||
|
var CodiceFiscale =
|
||
|
/*#__PURE__*/
|
||
|
function () {
|
||
|
_createClass(CodiceFiscale, [{
|
||
|
key: "day",
|
||
|
get: function get() {
|
||
|
return this.birthday.getDate();
|
||
|
},
|
||
|
set: function set(d) {
|
||
|
this.birthday.setDate(d);
|
||
|
}
|
||
|
}, {
|
||
|
key: "month",
|
||
|
get: function get() {
|
||
|
return this.birthday.getMonth() + 1;
|
||
|
},
|
||
|
set: function set(m) {
|
||
|
this.birthday.setMonth(m - 1);
|
||
|
}
|
||
|
}, {
|
||
|
key: "year",
|
||
|
get: function get() {
|
||
|
return this.birthday.getFullYear();
|
||
|
},
|
||
|
set: function set(y) {
|
||
|
this.birthday.setFullYear(y);
|
||
|
}
|
||
|
}, {
|
||
|
key: "cf",
|
||
|
get: function get() {
|
||
|
return this.code;
|
||
|
}
|
||
|
}, {
|
||
|
key: "nameCode",
|
||
|
get: function get() {
|
||
|
return this.code.substr(3, 3);
|
||
|
}
|
||
|
}, {
|
||
|
key: "surnameCode",
|
||
|
get: function get() {
|
||
|
return this.code.substr(0, 3);
|
||
|
}
|
||
|
}, {
|
||
|
key: "checkCode",
|
||
|
get: function get() {
|
||
|
return this.code.substr(15, 1);
|
||
|
}
|
||
|
}]);
|
||
|
|
||
|
function CodiceFiscale(data) {
|
||
|
_classCallCheck(this, CodiceFiscale);
|
||
|
|
||
|
if (typeof data === 'string') {
|
||
|
if (CodiceFiscale.check(data)) {
|
||
|
this.code = data;
|
||
|
this.reverse();
|
||
|
} else {
|
||
|
throw new Error('Provided input is not a valid Codice Fiscale');
|
||
|
}
|
||
|
} else if (_typeof(data) === 'object') {
|
||
|
var cfData = data;
|
||
|
this.name = cfData.name;
|
||
|
this.surname = cfData.surname;
|
||
|
this.gender = this.checkGender(cfData.gender);
|
||
|
this.birthday = cfData.birthday ? (0, _utils.getValidDate)(cfData.birthday) : (0, _utils.getValidDate)(cfData.day, cfData.month, cfData.year);
|
||
|
this.birthplace = new _comune.Comune(cfData.birthplace, cfData.birthplaceProvincia);
|
||
|
this.compute();
|
||
|
} else {
|
||
|
throw new Error('Comune constructor accept either a string or a plain object. Check the documentation');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
_createClass(CodiceFiscale, [{
|
||
|
key: "toString",
|
||
|
value: function toString() {
|
||
|
return this.code;
|
||
|
}
|
||
|
}, {
|
||
|
key: "toJSON",
|
||
|
value: function toJSON() {
|
||
|
return {
|
||
|
name: this.name,
|
||
|
surname: this.surname,
|
||
|
gender: this.gender,
|
||
|
birthday: this.birthday.getFullYear() + '-' + ('00' + this.birthday.getMonth()).slice(-2) + '-' + ('00' + this.birthday.getDate()).slice(-2),
|
||
|
birthplace: this.birthplace.nome,
|
||
|
birthplaceProvincia: this.birthplace.prov,
|
||
|
cf: this.code
|
||
|
};
|
||
|
}
|
||
|
}, {
|
||
|
key: "isValid",
|
||
|
value: function isValid() {
|
||
|
if (typeof this.code !== 'string') {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
this.code = this.code.toUpperCase();
|
||
|
|
||
|
if (this.code.length !== 16) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
var expectedCheckCode = this.code.charAt(15);
|
||
|
var cf = this.code.slice(0, 15);
|
||
|
return CodiceFiscale.getCheckCode(cf) === expectedCheckCode;
|
||
|
}
|
||
|
}, {
|
||
|
key: "omocodie",
|
||
|
value: function omocodie() {
|
||
|
var results = [];
|
||
|
var lastOmocode = this.code = this.code.slice(0, 15);
|
||
|
|
||
|
for (var i = this.code.length - 1; i >= 0; i = i - 1) {
|
||
|
var char = this.code[i];
|
||
|
|
||
|
if (char.match(/\d/) !== null) {
|
||
|
lastOmocode = "".concat(lastOmocode.substr(0, i)).concat(_constants.OMOCODIA_TABLE[char]).concat(lastOmocode.substr(i + 1));
|
||
|
results.push(lastOmocode + CodiceFiscale.getCheckCode(lastOmocode));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return results;
|
||
|
}
|
||
|
}, {
|
||
|
key: "compute",
|
||
|
value: function compute() {
|
||
|
var code = this.getSurnameCode();
|
||
|
code += this.getNameCode();
|
||
|
code += this.dateCode();
|
||
|
code += this.birthplace.cc;
|
||
|
code += CodiceFiscale.getCheckCode(code);
|
||
|
this.code = code;
|
||
|
}
|
||
|
}, {
|
||
|
key: "reverse",
|
||
|
value: function reverse() {
|
||
|
this.name = this.code.substr(3, 3);
|
||
|
this.surname = this.code.substr(0, 3);
|
||
|
var yearCode = this.code.substr(6, 2);
|
||
|
var year19XX = parseInt("19".concat(yearCode), 10);
|
||
|
var year20XX = parseInt("20".concat(yearCode), 10);
|
||
|
var currentYear20XX = new Date().getFullYear();
|
||
|
var year = year20XX > currentYear20XX ? year19XX : year20XX;
|
||
|
var monthChar = this.code.substr(8, 1);
|
||
|
|
||
|
var month = _constants.MONTH_CODES.indexOf(monthChar);
|
||
|
|
||
|
this.gender = 'M';
|
||
|
var day = parseInt(this.code.substr(9, 2), 10);
|
||
|
|
||
|
if (day > 31) {
|
||
|
this.gender = 'F';
|
||
|
day = day - 40;
|
||
|
}
|
||
|
|
||
|
this.birthday = new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
|
||
|
var cc = this.code.substr(11, 4);
|
||
|
this.birthplace = _comune.Comune.GetByCC(cc);
|
||
|
return this.toJSON();
|
||
|
}
|
||
|
}, {
|
||
|
key: "checkGender",
|
||
|
value: function checkGender(gender) {
|
||
|
this.gender = gender !== undefined ? gender.toUpperCase() : this.gender.toUpperCase();
|
||
|
|
||
|
if (typeof this.gender !== 'string') {
|
||
|
throw new Error('Gender must be a string');
|
||
|
}
|
||
|
|
||
|
if (this.gender !== 'M' && this.gender !== 'F') {
|
||
|
throw new Error('Gender must be either \'M\' or \'F\'');
|
||
|
}
|
||
|
|
||
|
return gender;
|
||
|
}
|
||
|
}, {
|
||
|
key: "getSurnameCode",
|
||
|
value: function getSurnameCode() {
|
||
|
var codeSurname = "".concat((0, _utils.extractConsonants)(this.surname)).concat((0, _utils.extractVowels)(this.surname), "XXX");
|
||
|
return codeSurname.substr(0, 3).toUpperCase();
|
||
|
}
|
||
|
}, {
|
||
|
key: "getNameCode",
|
||
|
value: function getNameCode() {
|
||
|
var codNome = (0, _utils.extractConsonants)(this.name);
|
||
|
|
||
|
if (codNome.length >= 4) {
|
||
|
codNome = codNome.charAt(0) + codNome.charAt(2) + codNome.charAt(3);
|
||
|
} else {
|
||
|
codNome += "".concat((0, _utils.extractVowels)(this.name), "XXX");
|
||
|
codNome = codNome.substr(0, 3);
|
||
|
}
|
||
|
|
||
|
return codNome.toUpperCase();
|
||
|
}
|
||
|
}, {
|
||
|
key: "dateCode",
|
||
|
value: function dateCode() {
|
||
|
var year = "0".concat(this.birthday.getFullYear());
|
||
|
year = year.substr(year.length - 2, 2);
|
||
|
|
||
|
var month = _constants.MONTH_CODES[this.birthday.getMonth()];
|
||
|
|
||
|
var day = this.birthday.getDate();
|
||
|
|
||
|
if (this.gender.toUpperCase() === 'F') {
|
||
|
day += 40;
|
||
|
}
|
||
|
|
||
|
var dayStr = "0".concat(day);
|
||
|
dayStr = dayStr.substr(dayStr.length - 2, 2);
|
||
|
return String(year + month + dayStr);
|
||
|
}
|
||
|
}], [{
|
||
|
key: "getCheckCode",
|
||
|
value: function getCheckCode(codiceFiscale) {
|
||
|
var val = 0;
|
||
|
|
||
|
for (var i = 0; i < 15; i = i + 1) {
|
||
|
var c = codiceFiscale[i];
|
||
|
val += i % 2 !== 0 ? _constants.CHECK_CODE_EVEN[c] : _constants.CHECK_CODE_ODD[c];
|
||
|
}
|
||
|
|
||
|
val = val % 26;
|
||
|
return _constants.CHECK_CODE_CHARS.charAt(val);
|
||
|
}
|
||
|
}, {
|
||
|
key: "findLocationCode",
|
||
|
value: function findLocationCode(name, prov) {
|
||
|
return new _comune.Comune(name, prov).cc;
|
||
|
}
|
||
|
}, {
|
||
|
key: "computeInverse",
|
||
|
value: function computeInverse(codiceFiscale) {
|
||
|
return new CodiceFiscale(codiceFiscale).toJSON();
|
||
|
}
|
||
|
}, {
|
||
|
key: "compute",
|
||
|
value: function compute(obj) {
|
||
|
return new CodiceFiscale(obj).toString();
|
||
|
}
|
||
|
}, {
|
||
|
key: "check",
|
||
|
value: function check(codiceFiscale) {
|
||
|
if (typeof codiceFiscale !== 'string') {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
var cf = codiceFiscale.toUpperCase();
|
||
|
|
||
|
if (cf.length !== 16) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
var expectedCheckCode = codiceFiscale.charAt(15);
|
||
|
cf = codiceFiscale.slice(0, 15);
|
||
|
return CodiceFiscale.getCheckCode(cf) === expectedCheckCode;
|
||
|
}
|
||
|
}, {
|
||
|
key: "getOmocodie",
|
||
|
value: function getOmocodie(cf) {
|
||
|
return new CodiceFiscale(cf).omocodie();
|
||
|
}
|
||
|
}]);
|
||
|
|
||
|
return CodiceFiscale;
|
||
|
}();
|
||
|
|
||
|
CodiceFiscale.utils = {
|
||
|
birthplaceFields: _utils.birthplaceFields
|
||
|
};
|
||
|
module.exports = CodiceFiscale;
|
||
|
},{"./comune":2,"./constants":3,"./utils":5}],2:[function(require,module,exports){
|
||
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.Comune = void 0;
|
||
|
|
||
|
var _geoData = require("./geo-data");
|
||
|
|
||
|
var _utils = require("./utils");
|
||
|
|
||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||
|
|
||
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||
|
|
||
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||
|
|
||
|
var Comune =
|
||
|
/*#__PURE__*/
|
||
|
function () {
|
||
|
_createClass(Comune, [{
|
||
|
key: "nomeNorm",
|
||
|
get: function get() {
|
||
|
return (0, _utils.normalizeString)(this.nome);
|
||
|
}
|
||
|
}]);
|
||
|
|
||
|
function Comune(nome, prov, cc) {
|
||
|
var check = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
||
|
|
||
|
_classCallCheck(this, Comune);
|
||
|
|
||
|
if (check || cc === undefined || prov === undefined) {
|
||
|
var comune;
|
||
|
comune = prov !== undefined ? this.searchByNameAndProvince(nome, prov) : this.searchByName(nome);
|
||
|
|
||
|
if (comune === undefined && nome.length === 4) {
|
||
|
comune = this.searchByCC(nome);
|
||
|
}
|
||
|
|
||
|
if (comune === undefined) {
|
||
|
throw new Error("Comune with name ".concat(nome, " doesn't exist"));
|
||
|
} else if (cc !== undefined && comune.cc !== cc) {
|
||
|
throw new Error("Comune with cc ".concat(cc, " doesn't exist"));
|
||
|
} else {
|
||
|
this.nome = comune.nome;
|
||
|
this.prov = comune.prov;
|
||
|
this.cc = comune.cc;
|
||
|
}
|
||
|
} else {
|
||
|
this.nome = nome;
|
||
|
this.prov = prov;
|
||
|
this.cc = cc;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
_createClass(Comune, [{
|
||
|
key: "searchByCC",
|
||
|
value: function searchByCC(cc) {
|
||
|
var result;
|
||
|
|
||
|
try {
|
||
|
result = Comune.GetByCC(cc);
|
||
|
} catch (e) {}
|
||
|
|
||
|
if (result !== undefined) {
|
||
|
return result.toJSON();
|
||
|
}
|
||
|
}
|
||
|
}, {
|
||
|
key: "searchByName",
|
||
|
value: function searchByName(nome) {
|
||
|
var query = (0, _utils.normalizeString)(nome);
|
||
|
var left = 0;
|
||
|
var right = _geoData.COMUNI.length - 1;
|
||
|
var result = [];
|
||
|
|
||
|
while (left <= right) {
|
||
|
var middle = Math.floor((left + right) / 2);
|
||
|
var currentItem = _geoData.COMUNI[middle];
|
||
|
|
||
|
if (query === currentItem[2]) {
|
||
|
result.push(currentItem);
|
||
|
|
||
|
if (middle > 0 && _geoData.COMUNI[middle - 1][2] === query) {
|
||
|
result.push(_geoData.COMUNI[middle - 1]);
|
||
|
} else if (middle < _geoData.COMUNI.length - 1 && _geoData.COMUNI[middle + 1][2] === query) {
|
||
|
result.push(_geoData.COMUNI[middle + 1]);
|
||
|
}
|
||
|
|
||
|
break;
|
||
|
} else if (query < currentItem[2]) {
|
||
|
right = middle - 1;
|
||
|
} else {
|
||
|
left = middle + 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (result.length === 1) {
|
||
|
return {
|
||
|
cc: result[0][0],
|
||
|
prov: result[0][1],
|
||
|
nome: result[0][2]
|
||
|
};
|
||
|
} else if (result.length > 1) {
|
||
|
throw new Error("Comune with name of ".concat(nome, " is found in more than one province. Please specify the province code"));
|
||
|
}
|
||
|
}
|
||
|
}, {
|
||
|
key: "searchByNameAndProvince",
|
||
|
value: function searchByNameAndProvince(nome, prov) {
|
||
|
var query = (0, _utils.normalizeString)(nome);
|
||
|
var left = 0;
|
||
|
var right = _geoData.COMUNI.length - 1;
|
||
|
var result;
|
||
|
|
||
|
while (left <= right) {
|
||
|
var middle = Math.floor((left + right) / 2);
|
||
|
var currentItem = _geoData.COMUNI[middle];
|
||
|
|
||
|
if (query === currentItem[2]) {
|
||
|
if (prov === currentItem[1]) {
|
||
|
result = currentItem;
|
||
|
} else if (middle > 0 && _geoData.COMUNI[middle - 1][2] === query && prov === _geoData.COMUNI[middle - 1][1]) {
|
||
|
result = _geoData.COMUNI[middle - 1];
|
||
|
} else if (middle < _geoData.COMUNI.length - 1 && _geoData.COMUNI[middle + 1][2] === query && prov === _geoData.COMUNI[middle + 1][1]) {
|
||
|
result = _geoData.COMUNI[middle + 1];
|
||
|
}
|
||
|
|
||
|
break;
|
||
|
} else if (query < currentItem[2]) {
|
||
|
right = middle - 1;
|
||
|
} else {
|
||
|
left = middle + 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (result !== undefined) {
|
||
|
return {
|
||
|
cc: result[0],
|
||
|
prov: result[1],
|
||
|
nome: result[2]
|
||
|
};
|
||
|
} else {
|
||
|
throw new Error("Comune with name of ".concat(nome, " and prov ").concat(prov, " doesn't exists"));
|
||
|
}
|
||
|
}
|
||
|
}, {
|
||
|
key: "toJSON",
|
||
|
value: function toJSON() {
|
||
|
return {
|
||
|
cc: this.cc,
|
||
|
nome: this.nome,
|
||
|
prov: this.prov
|
||
|
};
|
||
|
}
|
||
|
}], [{
|
||
|
key: "GetByName",
|
||
|
value: function GetByName(name, prov) {
|
||
|
return new Comune(name, prov);
|
||
|
}
|
||
|
}, {
|
||
|
key: "GetByCC",
|
||
|
value: function GetByCC(cc) {
|
||
|
var result;
|
||
|
var _iteratorNormalCompletion = true;
|
||
|
var _didIteratorError = false;
|
||
|
var _iteratorError = undefined;
|
||
|
|
||
|
try {
|
||
|
for (var _iterator = _geoData.COMUNI[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||
|
var item = _step.value;
|
||
|
|
||
|
if (item[0] === cc) {
|
||
|
result = item;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
} catch (err) {
|
||
|
_didIteratorError = true;
|
||
|
_iteratorError = err;
|
||
|
} finally {
|
||
|
try {
|
||
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
||
|
_iterator.return();
|
||
|
}
|
||
|
} finally {
|
||
|
if (_didIteratorError) {
|
||
|
throw _iteratorError;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (result !== undefined) {
|
||
|
return new Comune(result[2], result[1], result[0], false);
|
||
|
}
|
||
|
|
||
|
throw new Error("Comune with cc ".concat(cc, " doesn't exist"));
|
||
|
}
|
||
|
}]);
|
||
|
|
||
|
return Comune;
|
||
|
}();
|
||
|
|
||
|
exports.Comune = Comune;
|
||
|
},{"./geo-data":4,"./utils":5}],3:[function(require,module,exports){
|
||
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.CHECK_CODE_CHARS = exports.OMOCODIA_TABLE = exports.CHECK_CODE_EVEN = exports.CHECK_CODE_ODD = exports.MONTH_CODES = void 0;
|
||
|
var MONTH_CODES = ['A', 'B', 'C', 'D', 'E', 'H', 'L', 'M', 'P', 'R', 'S', 'T'];
|
||
|
exports.MONTH_CODES = MONTH_CODES;
|
||
|
var CHECK_CODE_ODD = {
|
||
|
0: 1,
|
||
|
1: 0,
|
||
|
2: 5,
|
||
|
3: 7,
|
||
|
4: 9,
|
||
|
5: 13,
|
||
|
6: 15,
|
||
|
7: 17,
|
||
|
8: 19,
|
||
|
9: 21,
|
||
|
A: 1,
|
||
|
B: 0,
|
||
|
C: 5,
|
||
|
D: 7,
|
||
|
E: 9,
|
||
|
F: 13,
|
||
|
G: 15,
|
||
|
H: 17,
|
||
|
I: 19,
|
||
|
J: 21,
|
||
|
K: 2,
|
||
|
L: 4,
|
||
|
M: 18,
|
||
|
N: 20,
|
||
|
O: 11,
|
||
|
P: 3,
|
||
|
Q: 6,
|
||
|
R: 8,
|
||
|
S: 12,
|
||
|
T: 14,
|
||
|
U: 16,
|
||
|
V: 10,
|
||
|
W: 22,
|
||
|
X: 25,
|
||
|
Y: 24,
|
||
|
Z: 23
|
||
|
};
|
||
|
exports.CHECK_CODE_ODD = CHECK_CODE_ODD;
|
||
|
var CHECK_CODE_EVEN = {
|
||
|
0: 0,
|
||
|
1: 1,
|
||
|
2: 2,
|
||
|
3: 3,
|
||
|
4: 4,
|
||
|
5: 5,
|
||
|
6: 6,
|
||
|
7: 7,
|
||
|
8: 8,
|
||
|
9: 9,
|
||
|
A: 0,
|
||
|
B: 1,
|
||
|
C: 2,
|
||
|
D: 3,
|
||
|
E: 4,
|
||
|
F: 5,
|
||
|
G: 6,
|
||
|
H: 7,
|
||
|
I: 8,
|
||
|
J: 9,
|
||
|
K: 10,
|
||
|
L: 11,
|
||
|
M: 12,
|
||
|
N: 13,
|
||
|
O: 14,
|
||
|
P: 15,
|
||
|
Q: 16,
|
||
|
R: 17,
|
||
|
S: 18,
|
||
|
T: 19,
|
||
|
U: 20,
|
||
|
V: 21,
|
||
|
W: 22,
|
||
|
X: 23,
|
||
|
Y: 24,
|
||
|
Z: 25
|
||
|
};
|
||
|
exports.CHECK_CODE_EVEN = CHECK_CODE_EVEN;
|
||
|
var OMOCODIA_TABLE = {
|
||
|
0: 'L',
|
||
|
1: 'M',
|
||
|
2: 'N',
|
||
|
3: 'P',
|
||
|
4: 'Q',
|
||
|
5: 'R',
|
||
|
6: 'S',
|
||
|
7: 'T',
|
||
|
8: 'U',
|
||
|
9: 'V'
|
||
|
};
|
||
|
exports.OMOCODIA_TABLE = OMOCODIA_TABLE;
|
||
|
var CHECK_CODE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||
|
exports.CHECK_CODE_CHARS = CHECK_CODE_CHARS;
|
||
|
},{}],4:[function(require,module,exports){
|
||
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.PROVINCE = exports.COMUNI = void 0;
|
||
|
var COMUNI = [['A001', 'PD', 'ABANO TERME'], ['A004', 'LO', 'ABBADIA CERRETO'], ['A005', 'LC', 'ABBADIA LARIANA'], ['A006', 'SI', 'ABBADIA SAN SALVATORE'], ['A007', 'OR', 'ABBASANTA'], ['A008', 'PE', 'ABBATEGGIO'], ['A010', 'MI', 'ABBIATEGRASSO'], ['A012', 'PT', 'ABETONE'], ['A013', 'PZ', 'ABRIOLA'], ['A014', 'RG', 'ACATE'], ['A015', 'FG', 'ACCADIA'], ['A016', 'CN', 'ACCEGLIO'], ['A017', 'MT', 'ACCETTURA'], ['A018', 'AQ', 'ACCIANO'], ['A019', 'RI', 'ACCUMOLI'], ['A020', 'PZ', 'ACERENZA'], ['A023', 'SA', 'ACERNO'], ['A024', 'NA', 'ACERRA'], ['A025', 'CT', 'ACI BONACCORSI'], ['A026', 'CT', 'ACI CASTELLO'], ['A027', 'CT', 'ACI CATENA'], ['A029', 'CT', 'ACI SANT\'ANTONIO'], ['A028', 'CT', 'ACIREALE'], ['A031', 'MC', 'ACQUACANINA'], ['A032', 'FR', 'ACQUAFONDATA'], ['A033', 'CS', 'ACQUAFORMOSA'], ['A034', 'BS', 'ACQUAFREDDA'], ['A035', 'PU', 'ACQUALAGNA'], ['A039', 'CR', 'ACQUANEGRA CREMONESE'], ['A038', 'MN', 'ACQUANEGRA SUL CHIESE'], ['A040', 'VT', 'ACQUAPENDENTE'], ['A041', 'CS', 'ACQUAPPESA'], ['A042', 'LE', 'ACQUARICA DEL CAPO'], ['A043', 'VV', 'ACQUARO'], ['A044', 'AP', 'ACQUASANTA TERME'], ['A045', 'TR', 'ACQUASPARTA'], ['A050', 'CB', 'ACQUAVIVA COLLECROCE'], ['A051', 'IS', 'ACQUAVIVA D\'ISERNIA'], ['A048', 'BA', 'ACQUAVIVA DELLE FONTI'], ['A047', 'AP', 'ACQUAVIVA PICENA'], ['A049', 'CL', 'ACQUAVIVA PLATANI'], ['M211', 'ME', 'ACQUEDOLCI'], ['A052', 'AL', 'ACQUI TERME'], ['A053', 'CS', 'ACRI'], ['A054', 'FR', 'ACUTO'], ['A055', 'BA', 'ADELFIA'], ['A056', 'CT', 'ADRANO'], ['A057', 'BG', 'ADRARA SAN MARTINO'], ['A058', 'BG', 'ADRARA SAN ROCCO'], ['A059', 'RO', 'ADRIA'], ['A060', 'BS', 'ADRO'], ['A061', 'VR', 'AFFI'], ['A062', 'RM', 'AFFILE'], ['Z200', 'EE', 'AFGHANISTAN'], ['A064', 'NA', 'AFRAGOLA'], ['A065', 'RC', 'AFRICO'], ['A067', 'PC', 'AGAZZANO'], ['A068', 'NA', 'AGEROLA'], ['A069', 'SS', 'AGGIUS'], ['A070', 'EN', 'AGIRA'], ['A071', 'PT', 'AGLIANA'], ['A072', 'AT', 'AGLIANO TERME'], ['A074', 'TO', 'AGLIE\''], ['H848', 'SS', 'AGLIENTU'], ['A075', 'PD', 'AGNA'], ['A076', 'CR', 'AGNADELLO'], ['A077', 'RC', 'AGNANA CALABRA'], ['A080', 'IS', 'AGNONE'], ['A082', 'BS', 'AGNOSINE'], ['A083', 'BL', 'AGORDO'], ['A084', 'RM', 'AGOSTA'], ['A085', 'VA', 'AGRA'], ['A087', 'MB', 'AGRATE BRIANZA'], ['A087', 'MI', 'AGRATE BRIANZA'], ['A088', 'NO', 'AGRATE CONTURBIA'], ['A089', 'AG', 'AGRIGENTO'], ['A091', 'SA', 'AGROPOLI'], ['A092', 'AN', 'AGUGLIANO'], ['A093', 'VI', 'AGUGLIARO'], ['A096', 'MB', 'AICURZIO'], ['A096', 'MI', 'AICURZIO'], ['A097', 'OR', 'AIDOMAGGIORE'], ['A098', 'EN', 'AIDONE'], ['A100', 'AQ', 'AIELLI'], ['A102', 'CS', 'AIELLO CALABRO'], ['A103', 'UD', 'AIELLO DEL FRIULI'], ['A101', 'AV', 'AIELLO DEL SABATO'], ['A105', 'CS', 'AIETA'], ['A106', 'CE', 'AILANO'], ['A107', 'BI', 'AILOCHE'], ['A109', 'TO', 'AIRASCA'], ['A110', 'BN', 'AIROLA'], ['A111', 'IM', 'AIROLE'], ['A112', 'LC', 'AIRUNO'], ['A113', 'CN', 'AISONE'], ['A116', 'TN', 'ALA'], ['A117', 'TO', 'ALA DI STURA'], ['A115', 'SS', 'ALA\' DEI SARDI'], ['A118', 'PV', 'ALAGNA'], ['A119', 'VC', 'ALAGNA VALSESIA'], ['A120', 'PE', 'ALANNO'], ['A121', 'BL', 'ALANO DI PIAVE'], ['A122', 'SV', 'ALASSIO'], ['A123', 'FR', 'ALATRI'], ['A124', 'CN', 'ALBA'], ['A125', 'TE', 'ALBA ADRIATICA'], ['A126', 'OR', 'ALBAGIARA'], ['A127', 'MI', 'ALBAIRATE'], ['A128', 'SA', 'ALBANELLA'], ['Z100', 'EE', 'ALBANIA'], ['A131', 'PZ', 'ALBANO DI LUCANIA'], ['A132', 'RM', 'ALBANO LAZIALE'], ['A129', 'BG', 'ALBANO SANT\'ALESSANDRO'], ['A130', 'VC', 'ALBANO VERCELLESE'], ['A134', 'PV', 'ALBAREDO ARNABOLDI'], ['A137', 'VR', 'ALBAREDO D\'ADIGE'], ['A135', 'SO', 'ALBAREDO PER SAN MARCO'], ['A138', 'PR', 'ALBARETO'], ['A139', 'CN', 'ALBARETTO DELLA TORRE'], ['A143', 'CO', 'ALBAVILLA'], ['A145', 'SV', 'ALBENGA'], ['A146', 'AL', 'ALBERA LIGURE'], ['A149', 'BA', 'ALBEROBELLO'], ['A150', 'FG', 'ALBERONA'], ['A153', 'CO', 'ALBESE CON CASSANO'], ['A154', 'VI', 'ALBETTONE'], ['A155', 'CZ', 'ALBI'], ['A158', 'TN', 'ALBIANO'], ['A157', 'TO', 'ALBIANO D\'IVREA'], ['A159', 'MB', 'ALBIATE'], ['A159', 'MI', 'ALBIATE'], ['A160', 'CS', 'ALBIDONA'], ['A161', 'PD', 'ALBIGNASEGO'], ['A162', 'RE', 'ALBINEA'], ['A163', 'BG
|
||
|
exports.COMUNI = COMUNI;
|
||
|
var PROVINCE = {
|
||
|
AG: 'Agrigento',
|
||
|
AL: 'Alessandria',
|
||
|
AN: 'Ancona',
|
||
|
AO: 'Aosta',
|
||
|
AP: 'Ascoli Piceno',
|
||
|
AQ: 'L\'Aquila',
|
||
|
AR: 'Arezzo',
|
||
|
AT: 'Asti',
|
||
|
AV: 'Avellino',
|
||
|
BA: 'Bari',
|
||
|
BG: 'Bergamo',
|
||
|
BI: 'Biella',
|
||
|
BL: 'Belluno',
|
||
|
BN: 'Benevento',
|
||
|
BO: 'Bologna',
|
||
|
BR: 'Brindisi',
|
||
|
BS: 'Brescia',
|
||
|
BT: 'Barletta-Andria-Trani',
|
||
|
BZ: 'Bolzano',
|
||
|
CA: 'Cagliari',
|
||
|
CB: 'Campobasso',
|
||
|
CE: 'Caserta',
|
||
|
CH: 'Chieti',
|
||
|
CI: 'Carbonia-Iglesias',
|
||
|
CL: 'Caltanissetta',
|
||
|
CN: 'Cuneo',
|
||
|
CO: 'Como',
|
||
|
CR: 'Cremona',
|
||
|
CS: 'Cosenza',
|
||
|
CT: 'Catania',
|
||
|
CZ: 'Catanzaro',
|
||
|
EN: 'Enna',
|
||
|
FC: 'Forlì-Cesena',
|
||
|
FE: 'Ferrara',
|
||
|
FG: 'Foggia',
|
||
|
FI: 'Firenze',
|
||
|
FM: 'Fermo',
|
||
|
FR: 'Frosinone',
|
||
|
GE: 'Genova',
|
||
|
GO: 'Gorizia',
|
||
|
GR: 'Grosseto',
|
||
|
IM: 'Imperia',
|
||
|
IS: 'Isernia',
|
||
|
KR: 'Crotone',
|
||
|
LC: 'Lecco',
|
||
|
LE: 'Lecce',
|
||
|
LI: 'Livorno',
|
||
|
LO: 'Lodi',
|
||
|
LT: 'Latina',
|
||
|
LU: 'Lucca',
|
||
|
MB: 'Monza e della Brianza',
|
||
|
MC: 'Macerata',
|
||
|
ME: 'Messina',
|
||
|
MI: 'Milano',
|
||
|
MN: 'Mantova',
|
||
|
MO: 'Modena',
|
||
|
MS: 'Massa-Carrara',
|
||
|
MT: 'Matera',
|
||
|
NA: 'Napoli',
|
||
|
NO: 'Novara',
|
||
|
NU: 'Nuoro',
|
||
|
OG: 'Ogliastra',
|
||
|
OR: 'Oristano',
|
||
|
OT: 'Olbia-Tempio',
|
||
|
PA: 'Palermo',
|
||
|
PC: 'Piacenza',
|
||
|
PD: 'Padova',
|
||
|
PE: 'Pescara',
|
||
|
PG: 'Perugia',
|
||
|
PI: 'Pisa',
|
||
|
PN: 'Pordenone',
|
||
|
PO: 'Prato',
|
||
|
PR: 'Parma',
|
||
|
PT: 'Pistoia',
|
||
|
PU: 'Pesaro e Urbino',
|
||
|
PV: 'Pavia',
|
||
|
PZ: 'Potenza',
|
||
|
RA: 'Ravenna',
|
||
|
RC: 'Reggio Calabria',
|
||
|
RE: 'Reggio Emilia',
|
||
|
RG: 'Ragusa',
|
||
|
RI: 'Rieti',
|
||
|
RM: 'Roma',
|
||
|
RN: 'Rimini',
|
||
|
RO: 'Rovigo',
|
||
|
SA: 'Salerno',
|
||
|
SI: 'Siena',
|
||
|
SO: 'Sondrio',
|
||
|
SP: 'La Spezia',
|
||
|
SR: 'Siracusa',
|
||
|
SS: 'Sassari',
|
||
|
SV: 'Savona',
|
||
|
TA: 'Taranto',
|
||
|
TE: 'Teramo',
|
||
|
TN: 'Trento',
|
||
|
TO: 'Torino',
|
||
|
TP: 'Trapani',
|
||
|
TR: 'Terni',
|
||
|
TS: 'Trieste',
|
||
|
TV: 'Treviso',
|
||
|
UD: 'Udine',
|
||
|
VA: 'Varese',
|
||
|
VB: 'Verbano-Cusio-Ossola',
|
||
|
VC: 'Vercelli',
|
||
|
VE: 'Venezia',
|
||
|
VI: 'Vicenza',
|
||
|
VR: 'Verona',
|
||
|
VS: 'Medio Campidano',
|
||
|
VT: 'Viterbo',
|
||
|
VV: 'Vibo Valentia',
|
||
|
EE: 'Estero'
|
||
|
};
|
||
|
exports.PROVINCE = PROVINCE;
|
||
|
},{}],5:[function(require,module,exports){
|
||
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.normalizeString = normalizeString;
|
||
|
exports.daysInMonth = daysInMonth;
|
||
|
exports.isValidDate = isValidDate;
|
||
|
exports.getValidDate = getValidDate;
|
||
|
exports.extractVowels = extractVowels;
|
||
|
exports.extractConsonants = extractConsonants;
|
||
|
exports.pad = pad;
|
||
|
exports.birthplaceFields = birthplaceFields;
|
||
|
|
||
|
var _geoData = require("./geo-data");
|
||
|
|
||
|
function normalizeString(str) {
|
||
|
return str.trim().replace(new RegExp(/[àá]/g), 'a\'').replace(new RegExp(/[èé]/g), 'e\'').replace(new RegExp(/[ìí]/g), 'i\'').replace(new RegExp(/[òó]/g), 'o\'').replace(new RegExp(/[ùú]/g), 'u\'').toUpperCase();
|
||
|
}
|
||
|
|
||
|
function daysInMonth(m, y) {
|
||
|
switch (m) {
|
||
|
case 1:
|
||
|
return y % 4 === 0 && y % 100 !== 0 || y % 400 === 0 ? 29 : 28;
|
||
|
|
||
|
case 8:
|
||
|
case 3:
|
||
|
case 5:
|
||
|
case 10:
|
||
|
return 30;
|
||
|
|
||
|
default:
|
||
|
return 31;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function isValidDate(d, m, y) {
|
||
|
var month = m - 1;
|
||
|
return month >= 0 && month < 12 && d > 0 && d <= daysInMonth(month, y);
|
||
|
}
|
||
|
|
||
|
function getValidDate(d, m, y) {
|
||
|
if (typeof d === 'string' && m === undefined && y === undefined) {
|
||
|
return new Date(d);
|
||
|
} else if (isValidDate(d, m, y)) {
|
||
|
return new Date(y, m - 1, d, 0, 0, 0, 0);
|
||
|
} else {
|
||
|
throw new Error("The date ".concat(y, "/").concat(m, "/").concat(d, " is not a valid date"));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function extractVowels(str) {
|
||
|
return str.replace(/[^AEIOU]/gi, '');
|
||
|
}
|
||
|
|
||
|
function extractConsonants(str) {
|
||
|
return str.replace(/[^BCDFGHJKLMNPQRSTVWXYZ]/gi, '');
|
||
|
}
|
||
|
|
||
|
function pad(n) {
|
||
|
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
||
|
var s = String(n);
|
||
|
|
||
|
while (s.length < size) {
|
||
|
s = "0".concat(s);
|
||
|
}
|
||
|
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
function birthplaceFields(provinceSelector, birthplaceSelector) {
|
||
|
var provinceSelect = document.querySelector(provinceSelector);
|
||
|
var birthplaceSelect = document.querySelector(birthplaceSelector);
|
||
|
var optGroupProv = document.createElement('optgroup');
|
||
|
var optGroupEE = document.createElement('optgroup');
|
||
|
optGroupEE.label = '-----------';
|
||
|
provinceSelect.appendChild(optGroupProv);
|
||
|
provinceSelect.appendChild(optGroupEE);
|
||
|
Object.keys(_geoData.PROVINCE).forEach(function (code, i) {
|
||
|
var name = _geoData.PROVINCE[code];
|
||
|
var option = document.createElement('option');
|
||
|
option.value = code;
|
||
|
option.textContent = name;
|
||
|
|
||
|
if (code === 'EE') {
|
||
|
optGroupEE.appendChild(option);
|
||
|
} else {
|
||
|
optGroupProv.appendChild(option);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
provinceSelect.onchange = function (e) {
|
||
|
var province = provinceSelect.value;
|
||
|
|
||
|
while (birthplaceSelect.firstChild) {
|
||
|
birthplaceSelect.removeChild(birthplaceSelect.firstChild);
|
||
|
}
|
||
|
|
||
|
_geoData.COMUNI.forEach(function (comune) {
|
||
|
var cc = comune[0];
|
||
|
var nome = comune[2];
|
||
|
var prov = comune[1];
|
||
|
|
||
|
if (prov === province) {
|
||
|
var option = document.createElement('option');
|
||
|
option.value = cc;
|
||
|
option.textContent = nome.toLowerCase().replace(/\b\w/g, function (l) {
|
||
|
return l.toUpperCase();
|
||
|
});
|
||
|
birthplaceSelect.appendChild(option);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
provinceSelect.selectedIndex = '0';
|
||
|
provinceSelect.onchange();
|
||
|
}
|
||
|
},{"./geo-data":4}]},{},[1]);
|