get() added function to get partial system info
This commit is contained in:
Vendored
+1
@@ -681,3 +681,4 @@ export function vboxInfo(cb?: (data: Systeminformation.VboxInfoData[]) => any):
|
||||
export function getStaticData(cb?: (data: Systeminformation.StaticData) => any): Promise<Systeminformation.StaticData>;
|
||||
export function getDynamicData(srv?: string, iface?: string, cb?: (data: any) => any): Promise<any>;
|
||||
export function getAllData(srv?: string, iface?: string, cb?: (data: any) => any): Promise<any>;
|
||||
export function get(valuesObject: any, cb?: (data: any) => any): Promise<any>;
|
||||
|
||||
@@ -308,6 +308,40 @@ function getAllData(srv, iface, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function get(valueObject, callback) {
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
const allPromises = Object.keys(valueObject)
|
||||
.filter(func => ({}.hasOwnProperty.call(exports, func)))
|
||||
.map(func => exports[func]());
|
||||
|
||||
Promise.all(allPromises).then(data => {
|
||||
const result = {};
|
||||
let i = 0;
|
||||
for (let key in valueObject) {
|
||||
if ({}.hasOwnProperty.call(valueObject, key) && {}.hasOwnProperty.call(exports, key) && data.length >= i) {
|
||||
if (valueObject[key] === '*' || valueObject[key] === 'all') {
|
||||
result[key] = data[i];
|
||||
} else {
|
||||
const keys = valueObject[key].replace(/,/g, ' ').replace(/ +/g, ' ').split(' ');
|
||||
const partialRes = {};
|
||||
keys.forEach(k => {
|
||||
if ({}.hasOwnProperty.call(data[i], k)) {
|
||||
partialRes[k] = data[i][k];
|
||||
}
|
||||
});
|
||||
result[key] = partialRes;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// export all libs
|
||||
// ----------------------------------------------------------------------------------
|
||||
@@ -374,3 +408,5 @@ exports.vboxInfo = vbox.vboxInfo;
|
||||
exports.getStaticData = getStaticData;
|
||||
exports.getDynamicData = getDynamicData;
|
||||
exports.getAllData = getAllData;
|
||||
exports.get = get;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user