Completed
Push — phpunit ( 7f2080...75f541 )
by Marcos
14:28 queued 10:45
created

js/importers/importer-dashlanecsv.js   A

Complexity

Total Complexity 7
Complexity/F 2.33

Size

Lines of Code 48
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 48
rs 10
wmc 7
mnd 2
bc 7
fnc 3
bpm 2.3333
cpm 2.3333
noi 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
B PassmanImporter.dashLaneCsv.readFile 0 35 1
A 0 47 1
1
// Importers should always start with this
2
var PassmanImporter = PassmanImporter || {};
1 ignored issue
show
Bug introduced by
The variable PassmanImporter seems to be never initialized.
Loading history...
3
(function(window, $, PassmanImporter) {
4
	'use strict';
5
	// Define the importer
6
	PassmanImporter.dashLaneCsv = {
7
		info: {
8
			name: 'Dashlane 4 csv',
9
			id: 'dashLaneCsv',
10
			description: 'Create an csv export. Go to File -> export -> Unsecured archive (readable) in CSV format'
11
		}
12
	};
13
14
	PassmanImporter.dashLaneCsv.readFile = function (file_data) {
15
		return new C_Promise(function(){
0 ignored issues
show
Bug introduced by
The variable C_Promise seems to be never declared. If this is a global, consider adding a /** global: C_Promise */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
16
			var rows = file_data.split('\n');
17
			var credential_list = [];
18
			for (var i = 0; i < rows.length; i++) {
19
				var row = rows[i];
20
				var row_data = row.split('","');
21
				if (row_data[0].charAt(0) == '"') {
22
					row_data[0] = row_data[0].substring(1);
23
				}
24
25
				if (row_data[row_data.length-1].toString().charAt(row_data[row_data.length - 1].length - 1) == '"') {
26
					row_data[row_data.length - 1] = row_data[row_data.length -1].substring(0, row_data[row_data.length - 1].length - 1);
27
				}
28
29
				var _credential = PassmanImporter.newCredential();
30
				_credential.label = row_data[0];
31
				_credential.username = row_data[2];
32
				_credential.password = row_data[row_data.length - 2];
33
				_credential.url = row_data[0];
34
				_credential.description = row_data[row_data.length - 1];
35
				if(_credential.label){
36
					credential_list.push(_credential);
37
				}
38
39
				var progress = {
40
					percent: i/rows.length*100,
41
					loaded: i,
42
					total: rows.length
43
				};
44
				this.call_progress(progress);
45
			}
46
			this.call_then(credential_list);
47
		});
48
	};
49
})(window, $, PassmanImporter);
50