code cleanup
This commit is contained in:
+16
-16
@@ -29,7 +29,7 @@ const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function getLinuxAudioPci() {
|
||||
let cmd = 'lspci -v 2>/dev/null'
|
||||
let cmd = 'lspci -v 2>/dev/null';
|
||||
let result = [];
|
||||
try {
|
||||
const parts = execSync(cmd).toString().split('\n\n');
|
||||
@@ -38,7 +38,7 @@ function getLinuxAudioPci() {
|
||||
if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) {
|
||||
const audio = {};
|
||||
audio.slotId = lines[0].split(' ')[0];
|
||||
audio.driver = util.getValue(lines, 'Kernel driver in use', ':', true) || util.getValue(lines, 'Kernel modules', ':', true)
|
||||
audio.driver = util.getValue(lines, 'Kernel driver in use', ':', true) || util.getValue(lines, 'Kernel modules', ':', true);
|
||||
result.push(audio);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ function parseLinuxAudioPciMM(lines, audioPCI) {
|
||||
const result = {};
|
||||
const slotId = util.getValue(lines, 'Slot');
|
||||
|
||||
const pciMatch = audioPCI.filter(function (item) { return item.slotId === slotId })
|
||||
const pciMatch = audioPCI.filter(function (item) { return item.slotId === slotId; });
|
||||
|
||||
result.id = slotId;
|
||||
result.name = util.getValue(lines, 'SDevice');
|
||||
@@ -87,14 +87,14 @@ function parseDarwinAudio(audioObject, id) {
|
||||
const channelStr = ((audioObject.coreaudio_device_transport || '') + ' ' + (audioObject._name || '')).toLowerCase();
|
||||
|
||||
result.id = id;
|
||||
result.name = audioObject._name
|
||||
result.name = audioObject._name;
|
||||
result.manufacturer = audioObject.coreaudio_device_manufacturer;
|
||||
result.revision = null;
|
||||
result.driver = null;
|
||||
result.default = !!(audioObject.coreaudio_default_audio_input_device || '') || !!(audioObject.coreaudio_default_audio_output_device || '');
|
||||
result.channel = parseDarwinChannel(channelStr);
|
||||
result.in = !!(audioObject.coreaudio_device_input || '')
|
||||
result.out = !!(audioObject.coreaudio_device_output || '')
|
||||
result.in = !!(audioObject.coreaudio_device_input || '');
|
||||
result.out = !!(audioObject.coreaudio_device_output || '');
|
||||
result.status = 'online';
|
||||
|
||||
return result;
|
||||
@@ -109,12 +109,12 @@ function parseWindowsAudio(lines) {
|
||||
result.name = util.getValue(lines, 'name', '=');
|
||||
result.manufacturer = util.getValue(lines, 'manufacturer', '=');
|
||||
result.revision = null;
|
||||
result.driver = null
|
||||
result.default = null
|
||||
result.in = null
|
||||
result.out = null
|
||||
result.interfaceType = null
|
||||
result.status = status
|
||||
result.driver = null;
|
||||
result.default = null;
|
||||
result.in = null;
|
||||
result.out = null;
|
||||
result.interfaceType = null;
|
||||
result.status = status;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -125,7 +125,7 @@ function audio(callback) {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux || _freebsd || _openbsd || _netbsd) {
|
||||
let cmd = 'lspci -vmm 2>/dev/null'
|
||||
let cmd = 'lspci -vmm 2>/dev/null';
|
||||
exec(cmd, function (error, stdout) {
|
||||
// PCI
|
||||
if (!error) {
|
||||
@@ -146,7 +146,7 @@ function audio(callback) {
|
||||
});
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPAudioDataType -json'
|
||||
let cmd = 'system_profiler SPAudioDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
try {
|
||||
@@ -158,7 +158,7 @@ function audio(callback) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop()
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
@@ -173,7 +173,7 @@ function audio(callback) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (util.getValue(parts[i].split('\n'), 'name', '=')) {
|
||||
result.push(parseWindowsAudio(parts[i].split('\n'), i))
|
||||
result.push(parseWindowsAudio(parts[i].split('\n'), i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -64,7 +64,7 @@ function parseDarwinBluetoothDevices(bluetoothObject, macAddr2) {
|
||||
result.device = bluetoothObject.device_services || '';
|
||||
result.name = bluetoothObject.device_name || '';
|
||||
result.manufacturer = bluetoothObject.device_manufacturer || '';
|
||||
result.macDevice = (bluetoothObject.device_addr || '').toLowerCase().replace(/-/g, ':');;
|
||||
result.macDevice = (bluetoothObject.device_addr || '').toLowerCase().replace(/-/g, ':');
|
||||
result.macHost = macAddr2;
|
||||
result.batteryPercent = bluetoothObject.device_batteryPercent || null;
|
||||
result.type = parseBluetoothTyoe(typeStr);
|
||||
@@ -124,7 +124,7 @@ function bluetoothDevices(callback) {
|
||||
resolve(result);
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPBluetoothDataType -json'
|
||||
let cmd = 'system_profiler SPBluetoothDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
try {
|
||||
@@ -148,7 +148,7 @@ function bluetoothDevices(callback) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop()
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
@@ -163,7 +163,7 @@ function bluetoothDevices(callback) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (util.getValue(parts[i].split('\n'), 'PNPClass', '=') === 'Bluetooth') {
|
||||
result.push(parseWindowsBluetooth(parts[i].split('\n'), i))
|
||||
result.push(parseWindowsBluetooth(parts[i].split('\n'), i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -382,7 +382,7 @@ function isUefiWindows() {
|
||||
resolve(line.toLowerCase().indexOf('uefi') >= 0);
|
||||
}
|
||||
resolve(false);
|
||||
})
|
||||
});
|
||||
}
|
||||
resolve(false);
|
||||
});
|
||||
|
||||
+11
-11
@@ -532,7 +532,7 @@ function sanitizeShellString(str) {
|
||||
}
|
||||
|
||||
function isPrototypePolluted() {
|
||||
const s = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
const s = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let notPolluted = true;
|
||||
let st = '';
|
||||
|
||||
@@ -541,16 +541,16 @@ function isPrototypePolluted() {
|
||||
st.__proto__.toString = stringToString;
|
||||
st.__proto__.substr = stringSubstr;
|
||||
|
||||
notPolluted = notPolluted || !(s.length === 62)
|
||||
notPolluted = notPolluted || !(s.length === 62);
|
||||
const ms = Date.now();
|
||||
if (typeof ms === 'number' && ms > 1600000000000) {
|
||||
const l = ms % 100 + 15;
|
||||
for (let i = 0; i < l; i++) {
|
||||
const r = Math.random() * 61.99999999 + 1;
|
||||
const rs = parseInt(Math.floor(r).toString(), 10)
|
||||
const rs = parseInt(Math.floor(r).toString(), 10);
|
||||
const rs2 = parseInt(r.toString().split('.')[0], 10);
|
||||
const q = Math.random() * 61.99999999 + 1;
|
||||
const qs = parseInt(Math.floor(q).toString(), 10)
|
||||
const qs = parseInt(Math.floor(q).toString(), 10);
|
||||
const qs2 = parseInt(q.toString().split('.')[0], 10);
|
||||
notPolluted = notPolluted && !(r === q);
|
||||
notPolluted = notPolluted && rs === rs2 && qs === qs2;
|
||||
@@ -578,7 +578,7 @@ function isPrototypePolluted() {
|
||||
|
||||
// lower
|
||||
const stl = st.toLowerCase();
|
||||
notPolluted = notPolluted && (stl.length === l) && stl[l - 1] && !(stl[l])
|
||||
notPolluted = notPolluted && (stl.length === l) && stl[l - 1] && !(stl[l]);
|
||||
for (let i = 0; i < l; i++) {
|
||||
const s1 = st[i];
|
||||
s1.__proto__.toLowerCase = stringToLower;
|
||||
@@ -591,7 +591,7 @@ function isPrototypePolluted() {
|
||||
}
|
||||
|
||||
function hex2bin(hex) {
|
||||
return ("00000000" + (parseInt(hex, 16)).toString(2)).substr(-8);
|
||||
return ('00000000' + (parseInt(hex, 16)).toString(2)).substr(-8);
|
||||
}
|
||||
|
||||
function getFilesInPath(source) {
|
||||
@@ -605,10 +605,10 @@ function getFilesInPath(source) {
|
||||
function isFile(source) { return lstatSync(source).isFile(); }
|
||||
|
||||
function getDirectories(source) {
|
||||
return readdirSync(source).map(function (name) { return join(source, name); }).filter(isDirectory)
|
||||
return readdirSync(source).map(function (name) { return join(source, name); }).filter(isDirectory);
|
||||
}
|
||||
function getFiles(source) {
|
||||
return readdirSync(source).map(function (name) { return join(source, name); }).filter(isFile)
|
||||
return readdirSync(source).map(function (name) { return join(source, name); }).filter(isFile);
|
||||
}
|
||||
|
||||
function getFilesRecursively(source) {
|
||||
@@ -750,7 +750,7 @@ function decodePiCpuinfo(lines) {
|
||||
manufacturer: '512MB Embest',
|
||||
processor: 'BCM2835'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const processorList = [
|
||||
'BCM2835',
|
||||
@@ -803,7 +803,7 @@ function decodePiCpuinfo(lines) {
|
||||
processor: oldRevisionCodes[revisionCode].processor,
|
||||
type: oldRevisionCodes[revisionCode].type,
|
||||
revision: oldRevisionCodes[revisionCode].revision,
|
||||
}
|
||||
};
|
||||
|
||||
} else {
|
||||
// new revision code
|
||||
@@ -824,7 +824,7 @@ function decodePiCpuinfo(lines) {
|
||||
processor,
|
||||
type: {}.hasOwnProperty.call(typeList, typeCode) ? typeList[typeCode] : '',
|
||||
revision: '1.' + revision.substr(7, 1),
|
||||
}
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user