Dependency updates, some code cleaned up

This commit is contained in:
Christian Kuster
2019-09-21 11:56:22 +02:00
parent d1eac84058
commit 32b516e302
10 changed files with 125 additions and 99 deletions

View File

@ -15,9 +15,9 @@ const detector = tool + ' show alias';
* an approach of analyzing the structure of the output
*/
function parseOutput(str, callback) {
var blocks = str.split('\n\n');
var wifis = [];
var err = null;
let blocks = str.split('\n\n');
let wifis = [];
let err = null;
try {
if (blocks.length < 2) {
// 2nd try, with \r\n
@ -40,18 +40,18 @@ function parseOutput(str, callback) {
// Channel : 6
// Basic rates (MBit/s) : 1 2 5.5 11
// Other rates (MBit/s) : 6 9 12 18 24 36 48 54
for (var i = 1, l = blocks.length; i < l; i++) {
var network = {};
var lines = blocks[i].split('\n');
var regexChannel = /[a-zA-Z0-9()\s]+:[\s]*[0-9]+$/g;
for (let i = 1, l = blocks.length; i < l; i++) {
let network = {};
let lines = blocks[i].split('\n');
let regexChannel = /[a-zA-Z0-9()\s]+:[\s]*[0-9]+$/g;
if (!lines || lines.length < 2) {
continue;
}
// First line is always the SSID (which can be empty)
var ssid = lines[0].substring(lines[0].indexOf(':') + 1).trim();
let ssid = lines[0].substring(lines[0].indexOf(':') + 1).trim();
for (var t = 1, n = lines.length; t < n; t++) {
for (let t = 1, n = lines.length; t < n; t++) {
if (lines[t].split(':').length === 7) {
// This is the mac address, use this one as trigger for a new network
if (network.mac) {
@ -61,14 +61,12 @@ function parseOutput(str, callback) {
ssid: ssid,
mac : lines[t].substring(lines[t].indexOf(':') + 1).trim()
};
}
else if (lines[t].indexOf('%') > 0) {
} else if (lines[t].indexOf('%') > 0) {
// Network signal strength, identified by '%'
var level = parseInt(lines[t].split(':')[1].split('%')[0].trim(), 10);
let level = parseInt(lines[t].split(':')[1].split('%')[0].trim(), 10);
network.rssi = (level / 2) - 100;
}
else if (!network.channel) {
} else if (!network.channel) {
// A tricky one: the channel is the first one having just ONE number. Set only
// if the channel is not already set ("Basic Rates" can be a single number also)
if (regexChannel.exec(lines[t].trim())) {