From ad8b942cfc997845046e1e2122d61de44b6e8d96 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 26 Oct 2023 22:32:30 +0200 Subject: [PATCH] fix execSync encoding --- lib/audio.js | 2 +- lib/bluetooth.js | 2 +- lib/cpu.js | 6 +++--- lib/filesystem.js | 8 ++++---- lib/graphics.js | 2 +- lib/memory.js | 6 +++--- lib/network.js | 24 ++++++++++++------------ lib/osinfo.js | 4 ++-- lib/processes.js | 6 +++--- lib/system.js | 12 ++++++------ lib/wifi.js | 16 ++++++++-------- 11 files changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/audio.js b/lib/audio.js index dc1f9b0e..9d84cadb 100644 --- a/lib/audio.js +++ b/lib/audio.js @@ -59,7 +59,7 @@ function getLinuxAudioPci() { let cmd = 'lspci -v 2>/dev/null'; let result = []; try { - const parts = execSync(cmd).toString().split('\n\n'); + const parts = execSync(cmd, { encoding: 'utf8' }).toString().split('\n\n'); parts.forEach(element => { const lines = element.split('\n'); if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) { diff --git a/lib/bluetooth.js b/lib/bluetooth.js index f0bf288c..e3a02dea 100644 --- a/lib/bluetooth.js +++ b/lib/bluetooth.js @@ -129,7 +129,7 @@ function bluetoothDevices(callback) { }); // determine "connected" with hcitool con try { - const hdicon = execSync('hcitool con').toString().toLowerCase(); + const hdicon = execSync('hcitool con', { encoding: 'utf8' }).toString().toLowerCase(); for (let i = 0; i < result.length; i++) { if (result[i].macDevice && result[i].macDevice.length > 10 && hdicon.indexOf(result[i].macDevice.toLowerCase()) >= 0) { result[i].connected = true; diff --git a/lib/cpu.js b/lib/cpu.js index 79b64ac0..54004276 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -702,7 +702,7 @@ function getCpu() { if (os.arch() === 'arm64') { result.socket = 'SOC'; try { - const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type').toString().split('\n'); + const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type', { encoding: 'utf8' }).toString().split('\n'); const efficiencyCores = clusters.filter(line => line.indexOf('"E"') >= 0).length; const performanceCores = clusters.filter(line => line.indexOf('"P"') >= 0).length; result.efficiencyCores = efficiencyCores; @@ -1048,7 +1048,7 @@ function cpuTemperature(callback) { // CPU Chipset, Socket try { const cmd = 'cat /sys/class/thermal/thermal_zone*/type 2>/dev/null; echo "-----"; cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null;'; - const parts = execSync(cmd).toString().split('-----\n'); + const parts = execSync(cmd, { encoding: 'utf8' }).toString().split('-----\n'); if (parts.length === 2) { const lines = parts[0].split('\n'); const lines2 = parts[1].split('\n'); @@ -1604,7 +1604,7 @@ function getLoad() { // linux: try to get other cpu stats if (_linux) { try { - const lines = execSync('cat /proc/stat 2>/dev/null | grep cpu').split('\n'); + const lines = execSync('cat /proc/stat 2>/dev/null | grep cpu', { encoding: 'utf8' }).split('\n'); if (lines.length > 1) { lines.shift(); if (lines.length === cpus.length) { diff --git a/lib/filesystem.js b/lib/filesystem.js index e00bd68c..109eadfb 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -139,7 +139,7 @@ function fsSize(drive, callback) { if (_linux) { try { cmd = 'export LC_ALL=C; df -lkPTx squashfs; unset LC_ALL'; - execSync('cat /proc/mounts 2>/dev/null').toString().split('\n').filter(line => { + execSync('cat /proc/mounts 2>/dev/null', { encoding: 'utf8' }).toString().split('\n').filter(line => { return line.startsWith('/'); }).forEach((line) => { osMounts[line.split(' ')[0]] = osMounts[line.split(' ')[0]] || false; @@ -426,7 +426,7 @@ function raidMatchLinux(data) { try { data.forEach(element => { if (element.type.startsWith('raid')) { - const lines = execSync(`mdadm --export --detail /dev/${element.name}`).toString().split('\n'); + const lines = execSync(`mdadm --export --detail /dev/${element.name}`, { encoding: 'utf8' }).toString().split('\n'); const mdData = decodeMdabmData(lines); element.label = mdData.label; // <- assign label info @@ -1087,7 +1087,7 @@ function diskLayout(callback) { } catch (e) { // fallback to older version of lsblk try { - const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL').toString(); + const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL', { encoding: 'utf8' }).toString(); let lines = blkStdoutToObject(out2).split('\n'); const data = parseBlk(lines); devices = data.filter(item => { return (item.type === 'disk') && item.size > 0 && ((item.model !== null && item.model !== '') || (item.mount === '' && item.label === '' && item.fsType === '')); }); @@ -1100,7 +1100,7 @@ function diskLayout(callback) { const BSDName = '/dev/' + device.name; const logical = device.name; try { - mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational 2>/dev/null').toString().split('\n')[0]; + mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational 2>/dev/null', { encoding: 'utf8' }).toString().split('\n')[0]; } catch (e) { util.noop(); } diff --git a/lib/graphics.js b/lib/graphics.js index 22285cf2..6ef4e8a6 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -216,7 +216,7 @@ function graphics(callback) { // PCI bus IDs let pciIDs = []; try { - pciIDs = execSync('export LC_ALL=C; dmidecode -t 9 2>/dev/null; unset LC_ALL | grep "Bus Address: "').toString().split('\n'); + pciIDs = execSync('export LC_ALL=C; dmidecode -t 9 2>/dev/null; unset LC_ALL | grep "Bus Address: "', { encoding: 'utf8' }).toString().split('\n'); for (let i = 0; i < pciIDs.length; i++) { pciIDs[i] = pciIDs[i].replace('Bus Address:', '').replace('0000:', '').trim(); } diff --git a/lib/memory.js b/lib/memory.js index 1db4997d..a4e949b8 100644 --- a/lib/memory.js +++ b/lib/memory.js @@ -399,7 +399,7 @@ function memLayout(callback) { // Try Raspberry PI try { - let stdout = execSync('cat /proc/cpuinfo 2>/dev/null'); + let stdout = execSync('cat /proc/cpuinfo 2>/dev/null', { encoding: 'utf8' }); let lines = stdout.toString().split('\n'); let model = util.getValue(lines, 'hardware', ':', true).toUpperCase(); let version = util.getValue(lines, 'revision', ':', true).toLowerCase(); @@ -419,14 +419,14 @@ function memLayout(callback) { result[0].clockSpeed = version && version[4] && version[4] === 'd' ? 500 : result[0].clockSpeed; result[0].formFactor = 'SoC'; - stdout = execSync('vcgencmd get_config sdram_freq 2>/dev/null'); + stdout = execSync('vcgencmd get_config sdram_freq 2>/dev/null', { encoding: 'utf8' }); lines = stdout.toString().split('\n'); let freq = parseInt(util.getValue(lines, 'sdram_freq', '=', true), 10) || 0; if (freq) { result[0].clockSpeed = freq; } - stdout = execSync('vcgencmd measure_volts sdram_p 2>/dev/null'); + stdout = execSync('vcgencmd measure_volts sdram_p 2>/dev/null', { encoding: 'utf8' }); lines = stdout.toString().split('\n'); let voltage = parseFloat(util.getValue(lines, 'volt', '=', true)) || 0; if (voltage) { diff --git a/lib/network.js b/lib/network.js index 61d10cdb..938abc4e 100644 --- a/lib/network.js +++ b/lib/network.js @@ -91,7 +91,7 @@ function getDefaultNetworkInterface() { } if (_linux) { let cmd = 'ip route 2> /dev/null | grep default'; - let result = execSync(cmd); + let result = execSync(cmd, { encoding: 'utf8' }); let parts = result.toString().split('\n')[0].split(/\s+/); if (parts[0] === 'none' && parts[5]) { ifacename = parts[5]; @@ -108,7 +108,7 @@ function getDefaultNetworkInterface() { if (_linux) { cmd = 'ip route 2> /dev/null | grep default | awk \'{print $5}\''; } if (_darwin) { cmd = 'route -n get default 2>/dev/null | grep interface: | awk \'{print $2}\''; } if (_freebsd || _openbsd || _netbsd || _sunos) { cmd = 'route get 0.0.0.0 | grep interface:'; } - let result = execSync(cmd); + let result = execSync(cmd, { encoding: 'utf8' }); ifacename = result.toString().split('\n')[0]; if (ifacename.indexOf(':') > -1) { ifacename = ifacename.split(':')[1].trim(); @@ -130,7 +130,7 @@ function getMacAddresses() { if (_linux || _freebsd || _openbsd || _netbsd) { if (typeof pathToIp === 'undefined') { try { - const lines = execSync('which ip').toString().split('\n'); + const lines = execSync('which ip', { encoding: 'utf8' }).toString().split('\n'); if (lines.length && lines[0].indexOf(':') === -1 && lines[0].indexOf('/') === 0) { pathToIp = lines[0]; } else { @@ -142,7 +142,7 @@ function getMacAddresses() { } try { const cmd = 'export LC_ALL=C; ' + ((pathToIp) ? pathToIp + ' link show up' : '/sbin/ifconfig') + '; unset LC_ALL'; - let res = execSync(cmd); + let res = execSync(cmd, { encoding: 'utf8' }); const lines = res.toString().split('\n'); for (let i = 0; i < lines.length; i++) { if (lines[i] && lines[i][0] !== ' ') { @@ -172,7 +172,7 @@ function getMacAddresses() { if (_darwin) { try { const cmd = '/sbin/ifconfig'; - let res = execSync(cmd); + let res = execSync(cmd, { encoding: 'utf8' }); const lines = res.toString().split('\n'); for (let i = 0; i < lines.length; i++) { if (lines[i] && lines[i][0] !== '\t' && lines[i].indexOf(':') > 0) { @@ -511,7 +511,7 @@ function getLinuxIfaceConnectionName(interfaceName) { const cmd = `nmcli device status 2>/dev/null | grep ${interfaceName}`; try { - const result = execSync(cmd).toString(); + const result = execSync(cmd, { encoding: 'utf8' }).toString(); const resultFormat = result.replace(/\s+/g, ' ').trim(); const connectionNameLines = resultFormat.split(' ').slice(3); const connectionName = connectionNameLines.join(' '); @@ -525,7 +525,7 @@ function checkLinuxDCHPInterfaces(file) { let result = []; try { let cmd = `cat ${file} 2> /dev/null | grep 'iface\\|source'`; - const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n'); + const lines = execSync(cmd, { maxBuffer: 1024 * 20000, encoding: 'utf8' }).toString().split('\n'); lines.forEach(line => { const parts = line.replace(/\s+/g, ' ').trim().split(' '); @@ -550,7 +550,7 @@ function getLinuxDHCPNics() { let cmd = 'ip a 2> /dev/null'; let result = []; try { - const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n'); + const lines = execSync(cmd, { maxBuffer: 1024 * 20000, encoding: 'utf8' }).toString().split('\n'); const nsections = splitSectionsNics(lines); result = (parseLinuxDHCPNics(nsections)); } catch (e) { @@ -591,7 +591,7 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) { if (connectionName) { const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep ipv4.method;`; try { - const lines = execSync(cmd).toString(); + const lines = execSync(cmd, { encoding: 'utf8' }).toString(); const resultFormat = lines.replace(/\s+/g, ' ').trim(); let dhcStatus = resultFormat.split(' ').slice(1).toString(); @@ -631,7 +631,7 @@ function getLinuxIfaceDNSsuffix(connectionName) { if (connectionName) { const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep ipv4.dns-search;`; try { - const result = execSync(cmd).toString(); + const result = execSync(cmd, { encoding: 'utf8' }).toString(); const resultFormat = result.replace(/\s+/g, ' ').trim(); const dnsSuffix = resultFormat.split(' ').slice(1).toString(); return dnsSuffix == '--' ? 'Not defined' : dnsSuffix; @@ -647,7 +647,7 @@ function getLinuxIfaceIEEE8021xAuth(connectionName) { if (connectionName) { const cmd = `nmcli connection show "${connectionName}" 2>/dev/null | grep 802-1x.eap;`; try { - const result = execSync(cmd).toString(); + const result = execSync(cmd, { encoding: 'utf8' }).toString(); const resultFormat = result.replace(/\s+/g, ' ').trim(); const authenticationProtocol = resultFormat.split(' ').slice(1).toString(); @@ -875,7 +875,7 @@ function networkInterfaces(callback, rescan, defaultString) { let lines = []; try { - lines = execSync(cmd).toString().split('\n'); + lines = execSync(cmd, { encoding: 'utf8' }).toString().split('\n'); const connectionName = getLinuxIfaceConnectionName(ifaceSanitized); dhcp = getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics); dnsSuffix = getLinuxIfaceDNSsuffix(connectionName); diff --git a/lib/osinfo.js b/lib/osinfo.js index e9b64480..a18f2758 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -168,13 +168,13 @@ function getFQDN() { let fqdn = os.hostname; if (_linux || _darwin) { try { - const stdout = execSync('hostnamectl --json short 2>/dev/null'); + const stdout = execSync('hostnamectl --json short 2>/dev/null', { encoding: 'utf8' }); const json = JSON.parse(stdout.toString()); fqdn = json['StaticHostname']; } catch (e) { try { - const stdout = execSync('hostname -f 2>/dev/null'); + const stdout = execSync('hostname -f 2>/dev/null', { encoding: 'utf8' }); fqdn = stdout.toString().split(os.EOL)[0]; } catch (e) { util.noop(); diff --git a/lib/processes.js b/lib/processes.js index 8314bc93..2de6cbcb 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -152,7 +152,7 @@ function services(srv, callback) { if (_linux || _freebsd || _openbsd || _netbsd || _darwin) { if ((_linux || _freebsd || _openbsd || _netbsd) && srvString === '*') { try { - const tmpsrv = execSync('systemctl --all --type=service --no-legend 2> /dev/null').toString().split('\n'); + const tmpsrv = execSync('systemctl --all --type=service --no-legend 2> /dev/null', { encoding: 'utf8' }).toString().split('\n'); srvs = []; for (const s of tmpsrv) { const name = s.split('.service')[0]; @@ -164,7 +164,7 @@ function services(srv, callback) { } catch (d) { try { srvString = ''; - const tmpsrv = execSync('service --status-all 2> /dev/null').toString().split('\n'); + const tmpsrv = execSync('service --status-all 2> /dev/null', { encoding: 'utf8' }).toString().split('\n'); for (const s of tmpsrv) { const parts = s.split(']'); if (parts.length === 2) { @@ -174,7 +174,7 @@ function services(srv, callback) { srvs = srvString.split('|'); } catch (e) { try { - const srvStr = execSync('ls /etc/init.d/ -m 2> /dev/null').toString().split('\n').join(''); + const srvStr = execSync('ls /etc/init.d/ -m 2> /dev/null', { encoding: 'utf8' }).toString().split('\n').join(''); srvString = ''; if (srvStr) { const tmpsrv = srvStr.split(','); diff --git a/lib/system.js b/lib/system.js index 08354d53..15875c63 100644 --- a/lib/system.js +++ b/lib/system.js @@ -61,7 +61,7 @@ function system(callback) { echo -n "product_version: "; cat /sys/devices/virtual/dmi/id/product_version 2>/dev/null; echo; echo -n "sys_vendor: "; cat /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null; echo;`; try { - lines = execSync(cmd).toString().split('\n'); + lines = execSync(cmd, { encoding: 'utf8' }).toString().split('\n'); result.manufacturer = result.manufacturer === '' ? util.getValue(lines, 'sys_vendor') : result.manufacturer; result.model = result.model === '' ? util.getValue(lines, 'product_name') : result.model; result.version = result.version === '' ? util.getValue(lines, 'product_version') : result.version; @@ -107,7 +107,7 @@ function system(callback) { } if (!result.virtual) { try { - const disksById = execSync('ls -1 /dev/disk/by-id/ 2>/dev/null').toString(); + const disksById = execSync('ls -1 /dev/disk/by-id/ 2>/dev/null', { encoding: 'utf8' }).toString(); if (disksById.indexOf('_QEMU_') >= 0) { result.virtual = true; result.virtualHost = 'QEMU'; @@ -129,7 +129,7 @@ function system(callback) { } if ((_freebsd || _openbsd || _netbsd) && !result.virtualHost) { try { - const procInfo = execSync('dmidecode -t 4'); + const procInfo = execSync('dmidecode -t 4', { encoding: 'utf8' }); const procLines = procInfo.toString().split('\n'); const procManufacturer = util.getValue(procLines, 'manufacturer', ':', true); switch (procManufacturer.toLowerCase()) { @@ -155,7 +155,7 @@ function system(callback) { result.model = 'Docker Container'; } try { - const stdout = execSync('dmesg 2>/dev/null | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen" | grep -viE "Nested Virtualization|/virtual/"'); + const stdout = execSync('dmesg 2>/dev/null | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen" | grep -viE "Nested Virtualization|/virtual/"', { encoding: 'utf8' }); // detect virtual machines let lines = stdout.toString().split('\n'); if (lines.length > 0) { @@ -369,7 +369,7 @@ function bios(callback) { echo -n "bios_vendor: "; cat /sys/devices/virtual/dmi/id/bios_vendor 2>/dev/null; echo; echo -n "bios_version: "; cat /sys/devices/virtual/dmi/id/bios_version 2>/dev/null; echo;`; try { - lines = execSync(cmd).toString().split('\n'); + lines = execSync(cmd, { encoding: 'utf8' }).toString().split('\n'); result.vendor = !result.vendor ? util.getValue(lines, 'bios_vendor') : result.vendor; result.version = !result.version ? util.getValue(lines, 'bios_version') : result.version; datetime = util.getValue(lines, 'bios_date'); @@ -483,7 +483,7 @@ function baseboard(callback) { echo -n "board_vendor: "; cat /sys/devices/virtual/dmi/id/board_vendor 2>/dev/null; echo; echo -n "board_version: "; cat /sys/devices/virtual/dmi/id/board_version 2>/dev/null; echo;`; try { - lines = execSync(cmd).toString().split('\n'); + lines = execSync(cmd, { encoding: 'utf8' }).toString().split('\n'); result.manufacturer = !result.manufacturer ? util.getValue(lines, 'board_vendor') : result.manufacturer; result.model = !result.model ? util.getValue(lines, 'board_name') : result.model; result.version = !result.version ? util.getValue(lines, 'board_version') : result.version; diff --git a/lib/wifi.js b/lib/wifi.js index 666ae499..9548a993 100644 --- a/lib/wifi.js +++ b/lib/wifi.js @@ -127,7 +127,7 @@ function ifaceListLinux() { const result = []; const cmd = 'iw dev 2>/dev/null'; try { - const all = execSync(cmd).toString().split('\n').map(line => line.trim()).join('\n'); + const all = execSync(cmd, { encoding: 'utf8' }).toString().split('\n').map(line => line.trim()).join('\n'); const parts = all.split('\nInterface '); parts.shift(); parts.forEach(ifaceDetails => { @@ -146,7 +146,7 @@ function ifaceListLinux() { return result; } catch (e) { try { - const all = execSync('nmcli -t -f general,wifi-properties,wired-properties,interface-flags,capabilities,nsp device show 2>/dev/null').toString(); + const all = execSync('nmcli -t -f general,wifi-properties,wired-properties,interface-flags,capabilities,nsp device show 2>/dev/null', { encoding: 'utf8' }).toString(); const parts = all.split('\nGENERAL.DEVICE:'); let i = 1; parts.forEach(ifaceDetails => { @@ -175,7 +175,7 @@ function ifaceListLinux() { function nmiDeviceLinux(iface) { const cmd = `nmcli -t -f general,wifi-properties,capabilities,ip4,ip6 device show ${iface} 2>/dev/null`; try { - const lines = execSync(cmd).toString().split('\n'); + const lines = execSync(cmd, { encoding: 'utf8' }).toString().split('\n'); const ssid = util.getValue(lines, 'GENERAL.CONNECTION'); return { iface, @@ -193,7 +193,7 @@ function nmiDeviceLinux(iface) { function nmiConnectionLinux(ssid) { const cmd = `nmcli -t --show-secrets connection show ${ssid} 2>/dev/null`; try { - const lines = execSync(cmd).toString().split('\n'); + const lines = execSync(cmd, { encoding: 'utf8' }).toString().split('\n'); const bssid = util.getValue(lines, '802-11-wireless.seen-bssids').toLowerCase(); return { ssid: ssid !== '--' ? ssid : null, @@ -211,7 +211,7 @@ function nmiConnectionLinux(ssid) { function wpaConnectionLinux(iface) { const cmd = `wpa_cli -i ${iface} status 2>&1`; try { - const lines = execSync(cmd).toString().split('\n'); + const lines = execSync(cmd, { encoding: 'utf8' }).toString().split('\n'); const freq = util.toInt(util.getValue(lines, 'freq', '=')); return { ssid: util.getValue(lines, 'ssid', '='), @@ -230,7 +230,7 @@ function getWifiNetworkListNmi() { const result = []; const cmd = 'nmcli -t -m multiline --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags device wifi list 2>/dev/null'; try { - const stdout = execSync(cmd, { maxBuffer: 1024 * 20000 }); + const stdout = execSync(cmd, { maxBuffer: 1024 * 20000, encoding: 'utf8' }); const parts = stdout.toString().split('ACTIVE:'); parts.shift(); parts.forEach(part => { @@ -263,7 +263,7 @@ function getWifiNetworkListNmi() { function getWifiNetworkListIw(iface) { const result = []; try { - let iwlistParts = execSync(`export LC_ALL=C; iwlist ${iface} scan 2>&1; unset LC_ALL`).toString().split(' Cell '); + let iwlistParts = execSync(`export LC_ALL=C; iwlist ${iface} scan 2>&1; unset LC_ALL`, { encoding: 'utf8' }).toString().split(' Cell '); if (iwlistParts[0].indexOf('resource busy') >= 0) { return -1; } if (iwlistParts.length > 1) { iwlistParts.shift(); @@ -397,7 +397,7 @@ function wifiNetworks(callback) { result = getWifiNetworkListNmi(); if (result.length === 0) { try { - const iwconfigParts = execSync('export LC_ALL=C; iwconfig 2>/dev/null; unset LC_ALL').toString().split('\n\n'); + const iwconfigParts = execSync('export LC_ALL=C; iwconfig 2>/dev/null; unset LC_ALL', { encoding: 'utf8' }).toString().split('\n\n'); let iface = ''; iwconfigParts.forEach(element => { if (element.indexOf('no wireless') === -1 && element.trim() !== '') {