app/js/renderer/bwa/analyser.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 1.67

Size

Lines of Code 118
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 53
mnd 4
bc 4
fnc 6
dl 0
loc 118
rs 10
bpm 0.6666
cpm 1.6666
noi 13
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B analyser.js ➔ showTable 0 38 8
A analyser.js ➔ getInitials 0 9 2
1
// jshint esversion: 8, -W030
2
3
/** global: appSettings */
4
const whois = require('../../common/whoisWrapper'),
0 ignored issues
show
Unused Code introduced by
The constant whois seems to be never used. Consider removing it.
Loading history...
5
  conversions = require('../../common/conversions'),
0 ignored issues
show
Unused Code introduced by
The constant conversions seems to be never used. Consider removing it.
Loading history...
6
  fs = require('fs'),
0 ignored issues
show
Unused Code introduced by
The constant fs seems to be never used. Consider removing it.
Loading history...
7
  Papa = require('papaparse'),
0 ignored issues
show
Unused Code introduced by
The constant Papa seems to be never used. Consider removing it.
Loading history...
8
  dt = require('datatables')();
0 ignored issues
show
Unused Code introduced by
The constant dt seems to be never used. Consider removing it.
Loading history...
9
10
const {
11
  ipcRenderer
12
} = require('electron');
13
14
var bwaFileContents;
15
16
/*
17
  ipcRenderer.on('bwa:analyser.tablegen', function() {...});
18
    Generate analyser content table
19
  parameters
20
    event
21
    contents
22
 */
23
ipcRenderer.on('bwa:analyser.tablegen', function(event, contents) {
24
  bwaFileContents = contents;
25
  showTable();
26
27
  return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
28
});
29
30
/*
31
  $('#bwaAnalyserButtonClose').click(function() {...});
32
    Bulk whois analyser close button
33
 */
34
$('#bwaAnalyserButtonClose').click(function() {
35
  ipcRenderer.send('app:debug', '#bwaAnalyserButtonClose clicked');
36
  $('#bwaAnalyserModalClose').addClass('is-active');
37
38
  return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
39
});
40
41
/*
42
  $('#bwaAnalyserModalCloseButtonYes').click(function() {...});
43
    bwa, close dialog confirm/yes
44
 */
45
$('#bwaAnalyserModalCloseButtonYes').click(function() {
46
  $('#bwaAnalyser').addClass('is-hidden');
47
  $('#bwaAnalyserModalClose').removeClass('is-active');
48
  $('#bwaEntry').removeClass('is-hidden');
49
50
  return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
51
});
52
53
/*
54
  $('#bwaAnalyserModalCloseButtonNo').click(function() {...});
55
    Bulk whois analyser close dialog cancel/no button
56
 */
57
$('#bwaAnalyserModalCloseButtonNo').click(function() {
58
  $('#bwaAnalyserModalClose').removeClass('is-active');
59
60
  return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
61
});
62
63
/*
64
  showTable
65
    ipsum
66
 */
67
function showTable() {
68
  var header = {},
69
    body = {};
70
  header.columns = Object.keys(bwaFileContents.data[0]);
71
  body.records = bwaFileContents.data;
72
73
  // Generate header column content
74
  header.content = '<tr>\n';
75
  for (var column in header.columns) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
76
    header.content += '\t<th><abbr title="{0}">{1}</abbr></th>\n'.format(header.columns[column], getInitials(header.columns[column]));
77
  }
78
  header.content += '</tr>';
79
80
  $('#bwaAnalyserTableThead').html(header.content);
81
82
  // Generate record fields
83
  body.content = '';
84
  for (var record in body.records) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
85
    body.content += '<tr>\n';
86
87
    for (var field in body.records[record]) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
88
      body.content += '\t<td>{0}</td>\n'.format(body.records[record][field]);
89
    }
90
    body.content += '</tr>\n';
91
  }
92
  $('#bwaAnalyserTableTbody').html(body.content);
93
94
  body.table = $('#bwaAnalyserTable').dataTable({
95
    'destroy': true
96
  });
97
98
99
  $('#bwaFileinputconfirm').addClass('is-hidden');
100
  $('#bwaAnalyser').removeClass('is-hidden');
101
  //body.content.destroy();
102
103
  return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
104
}
105
106
/*
107
  getInitials
108
    ipsum
109
  parameters
110
    string
111
    threshold
112
 */
113
function getInitials(string, threshold = 1) {
114
  var initials = string.match(/\b\w/g);
115
116
  initials = (initials.length > threshold) ?
117
    initials.join("").toString() :
118
    string.substring(0, threshold + 1);
119
120
  return initials;
121
}
122