Completed
Pull Request — master (#70)
by Sander
03:14
created

js/exporters/exporter-csv.js   A

Complexity

Total Complexity 6
Complexity/F 3

Size

Lines of Code 42
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
B PassmanExporter.csv.export 0 34 1
1
/** global: PassmanExporter */
2
PassmanExporter.csv = {
3
	info: {
4
		name: 'CSV',
5
		id: 'csv',
6
		description: 'Export credentials as csv.'
7
	}
8
};
9
10
PassmanExporter.csv.export = function (credentials) {
11
	/** global: C_Promise */
12
	return new C_Promise(function () {
13
		var _this = this;
14
		var headers = ['label', 'username', 'password', 'email', 'description', 'tags'];
15
		var file_data = '"' + headers.join('","') + '"\n';
16
		for (var i = 0; i < credentials.length; i++) {
17
			var _credential = credentials[i];
18
			var row_data = [];
19
			for (var h = 0; h < headers.length; h++) {
20
				var field = headers[h];
21
				if (field === 'tags') {
22
					var _tags = [];
23
					for (var t = 0; t < _credential[field].length; t++) {
24
						_tags.push(_credential[field][t].text);
25
					}
26
					var data = '[' + _tags.join(",") + ']';
27
					row_data.push('"' + data + '"');
28
				} else {
29
					row_data.push('"' + _credential[field] + '"');
30
				}
31
			}
32
			var progress = {
33
				percent: i / credentials.length * 100,
34
				loaded: i,
35
				total: credentials.length
36
			};
37
			_this.call_progress(progress);
38
			file_data += row_data.join(',') + "\n";
39
		}
40
		_this.call_then();
41
		download(file_data, 'passman-export.csv');
42
	});
43
};
44