get() added function to get partial system info

This commit is contained in:
Sebastian Hildebrandt 2020-05-07 07:33:34 +02:00
parent ba3469db0c
commit 8fa0d3065a
7 changed files with 102 additions and 2 deletions

View File

@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 4.25.0 | 2020-05-07 | `get()` added function to get partial system info |
| 4.24.2 | 2020-05-06 | `cpu()` fix (BSD), `networkStats()` fix BSD |
| 4.24.1 | 2020-05-03 | `processes()` fix parsing command and params |
| 4.24.0 | 2020-05-01 | `networkInterfaces()` added subnet mask ip4 and ip6 |

View File

@ -87,13 +87,13 @@ si.cpu()
(last 7 major and minor version releases)
- Version 4.25.0: `get()` added function to get partial system info
- Version 4.24.0: `networkInterfaces()` added subnet mask ip4 and ip6
- Version 4.23.0: `versions()` added param to specify which program/lib versions to detect
- Version 4.22.0: `services()` added pids (windows)
- Version 4.21.0: added npx copmpatibility
- Version 4.20.0: `battery()` added designcapacity, voltage, unit
- Version 4.19.0: `osInfo()` added uefi (OS uses UEFI during startup)
- Version 4.18.0: `networkInterfaces()` added dhcp for mac os, added dhcp linux fallback
- ...
You can find all changes here: [detailed changelog][changelog-url]
@ -639,6 +639,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| si.getStaticData(cb) | {...} | X | X | X | X | X | all static data at once |
| si.getDynamicData(srv,iface,cb) | {...} | X | X | X | X | X | all dynamic data at once<br>Specify services and interfaces to monitor<br>Defaults to first external network interface<br>Pass "*" for ALL services (linux/win only)<br>Pass "*" for ALL network interfaces |
| si.getAllData(srv,iface,cb) | {...} | X | X | X | X | X | all data at once<br>Specify services and interfaces to monitor<br>Defaults to first external network interface<br>Pass "*" for ALL services (linux/win only)<br>Pass "*" for ALL network interfaces |
| si.get(valueObject,cb) | {...} | X | X | X | X | X | get partial system info data at once<br>In valueObject you can define<br>all values, you want to get back <br>(see documentation for details) |
### cb: Asynchronous Function Calls (callback)

View File

@ -174,6 +174,62 @@
<td>X</td>
<td>all data at once<br>Specify services and interfaces to monitor<br>Defaults to first external network interface<br>Pass "*" for ALL services (linux/win only)<br>Pass "*" for ALL network interfaces</td>
</tr>
<tr>
<td>si.get(valueObject,cb)</td>
<td>{...}</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>get partial data at once<br>Specify return object for all<br>values that should be returned.<br>See example:</td>
</tr>
<tr class="example">
<td></td>
<td colspan="7">
<h5>Example</h5>
<pre><code class="js">const si = require('systeminformation');
// define all values, you want to get back
valueObject = {
cpu: '*',
osInfo: 'platform, release',
system: 'model, manufacturer'
}
si.get(valueObject).then(data => console.log(data));</code></pre class="example">
<pre class="example">
{
cpu: {
manufacturer: 'Intel®',
brand: 'Core™ i7-8569U',
vendor: 'GenuineIntel',
family: '6',
model: '142',
stepping: '10',
revision: '',
voltage: '',
speed: '2.80',
speedmin: '2.80',
speedmax: '2.80',
governor: '',
cores: 8,
physicalCores: 4,
processors: 1,
socket: '',
cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 8388608 }
},
osInfo: {
platform: 'darwin',
release: '10.15.4'
},
system: {
model: 'MacBookPro15,2',
manufacturer: 'Apple Inc.'
}
}
</pre>
</tr>
</tbody>
</table>
<p><strong>Static data</strong> is all hardware related (or more or less constant) data like system, baseboard, bios, OS, versions, cpu, network interfces, memory and disk layout</p>

View File

@ -83,6 +83,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.25.0</th>
<td>2020-05-07</td>
<td><span class="code">get()</span> added function to get partial system info /td>
</tr>
<tr>
<th scope="row">4.24.2</th>
<td>2020-05-06</td>

View File

@ -168,7 +168,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.24.2</span></div>
<div class="version">Current Version: <span id="version">4.25.0</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">

1
lib/index.d.ts vendored
View File

@ -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>;

View File

@ -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;