This commit is contained in:
Luca Vandro 2016-03-22 20:23:28 +01:00
commit 87832b28ee
9 changed files with 33011 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

33
.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
node_modules
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history

15
Gulpfile.js Normal file
View File

@ -0,0 +1,15 @@
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require("gulp-rename");
gulp.task('compress', function() {
return gulp.src('codice.fiscale.js')
.pipe(uglify())
.pipe(rename('codice.fiscale.min.js'))
.pipe(gulp.dest('.'));
});
gulp.task('default', ['compress'], function() {
// place code for your default task here
});

32734
codice.fiscale.js Normal file

File diff suppressed because it is too large Load Diff

6
codice.fiscale.min.js vendored Normal file

File diff suppressed because one or more lines are too long

70
karma.conf.js Normal file
View File

@ -0,0 +1,70 @@
// Karma configuration
// Generated on Wed Mar 16 2016 15:24:23 GMT+0100 (CET)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'codice.fiscale.js',
'tests/specs.js',
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}

26
package.json Normal file
View File

@ -0,0 +1,26 @@
{
"name": "codice-fiscale-js",
"version": "1.0.0",
"description": "Calcolo del codice fiscale",
"main": "codice.fiscale.js",
"directories": {
"test": "tests"
},
"dependencies": {
},
"devDependencies": {
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.3.7",
"karma-phantomjs-launcher": "^1.0.0",
"phantomjs-prebuilt": "^2.1.5",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.5.3"
},
"scripts": {
"test": "karma start"
},
"author": "Luca Vandro",
"license": "MIT"
}

45
readme.md Normal file
View File

@ -0,0 +1,45 @@
CodiceFiscale.js
===================
CodiceFiscale.js is a utility library to compute and validate Italian Italian Tax code (codice fiscale).
Usage
=====
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
var cf = CodiceFiscale.compute("Enzo","Righi","M",24,7,1957,"Napoli", "NA");
```
----------
Check
-------
Check if a codice fiscale is valid. It returns a **boolean** value.
```js
var isValid = CodiceFiscale.check("VNDLDL10A01G410Z");
```
----------
Omocodie
-------
Get all the omocodie for a given Codice Fiscale. It returns an array of strings
```js
var omocodie = CodiceFiscale.getOmocodie("VNDLDL10A01G410Z");
```

82
tests/specs.js Normal file
View File

@ -0,0 +1,82 @@
describe("Codice Fiscale", function() {
it("esiste un oggetto chiamato CodiceFiscale", function() {
expect(CodiceFiscale).not.toBe(undefined);
});
});
describe("CodiceFiscale.compute", function() {
it("è definito", function() {
expect(CodiceFiscale.compute).not.toBe(undefined);
});
it("compute il codice fiscale", function() {
expect(CodiceFiscale.compute("Luca", "Moreno",'M', 1, 1, 2000, "Roma", "RM")).toBe("MRNLCU00A01H501J");
});
it("se il comune non esiste lancia un eccezione", function() {
var comuneInventato = function(){
CodiceFiscale.compute("Luca", "Moreno",'M', 1, 1, 2000, "Pufflandia", "CE");
}
expect(comuneInventato).toThrowError("Comune not found");
});
});
describe("CodiceFiscale.findComuneCode", function() {
it("è definito", function() {
expect(CodiceFiscale.findComuneCode).not.toBe(undefined);
});
it("trova il codice del comune", function() {
expect(CodiceFiscale.findComuneCode("Roma", "RM")).toBe("H501");
});
it("se il comune non esiste lancia un eccezione", function() {
var comuneInventato = function(){
CodiceFiscale.findComuneCode("Pufflandia", "RM");
}
expect(comuneInventato).toThrowError("Comune not found");
});
});
describe("CodiceFiscale.check", function() {
it("è definito", function() {
expect(CodiceFiscale.check).not.toBe(undefined);
});
it("controlla se il codice fiscale è valido", function() {
expect(CodiceFiscale.check("MRNLCU00A01H501J")).toBe(true);
});
it("controlla che sia composto dal non più 16 valori alfanumerici", function() {
expect(CodiceFiscale.check("MRNLCU00A01H501JK")).toBe(false);
});
it("controlla che sia composto dal almeno 16 valori alfanumerici", function() {
expect(CodiceFiscale.check("MRNLCU00A01H501J3")).toBe(false);
});
it("controlla che il carattere di controllo sia esatto", function() {
expect(CodiceFiscale.check("VNDLDL87D07B963G")).toBe(false);
});
it("funziona anche in caso di omocodie", function() {
expect(CodiceFiscale.check("BNZVCN32S10E57PV")).toBe(true);
expect(CodiceFiscale.check("BNZVCNPNSMLERTPX")).toBe(true);
});
});
describe("CodiceFiscale.getOmocodie", function() {
it("è definito", function() {
expect(CodiceFiscale.getOmocodie).not.toBe(undefined);
});
it("calcola le omocodie dato un codice fiscale", function() {
expect(CodiceFiscale.getOmocodie("BNZVCN32S10E573Z"))
.toEqual(jasmine.arrayContaining(["BNZVCN32S10E57PV", "BNZVCNPNSMLERTPX"]));
});
});