hardware-info
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,2 +0,2 @@ | ||
export function getCpus(): { | ||
export function getCpu(): { | ||
total: number; | ||
@@ -3,0 +3,0 @@ model: string; |
32
index.js
@@ -5,5 +5,5 @@ import os from 'node:os'; | ||
export function getCpus() { | ||
export function getCpu() { | ||
return { | ||
total: Number.parseInt(cpus.length, 10), | ||
threads: Number.parseInt(cpus.length, 10), | ||
model: `${cpus[0].model}`, | ||
@@ -21,2 +21,30 @@ speed: Number.parseInt(cpus[0].speed, 10), | ||
export function getOsArch() { | ||
return { | ||
arch: `${os.arch()}`, | ||
}; | ||
} | ||
export function getNetInterfaces() { | ||
const interfaces = os.networkInterfaces(); | ||
const response = Object.keys(interfaces).map(element => { | ||
if (Array.isArray(interfaces[element])) { | ||
return { | ||
name: element, | ||
addresses: interfaces[element].map(_interface => ({ | ||
path: _interface.address, | ||
internal: _interface.internal, | ||
})), | ||
}; | ||
} | ||
return { | ||
name: element, | ||
addresses: interfaces[element].address, | ||
}; | ||
}); | ||
return response; | ||
} | ||
function formatBytes(bytes) { | ||
@@ -23,0 +51,0 @@ const units = ['bytes', 'KB', 'MB', 'GB', 'TB']; |
{ | ||
"name": "hardware-info", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A lightweight way to get the hardware information.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,11 +10,17 @@ # hardware-info | ||
```javascript | ||
import {getCpus} from 'hardware-info'; | ||
import {getCpu, getRam, get} from 'hardware-info'; | ||
console.log(getCpus()); | ||
// => { total: 16, model: 'Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz', speed: 2904 }' | ||
console.log(getCpu()); | ||
// => { threads: 16, model: 'Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz', speed: 2904 }' | ||
console.log(getRam()); | ||
//=> '{ total: '15.93 GB', free: '7.15 GB' }' | ||
console.log(getNetInterfaces()); | ||
//=> '[{"name":"Ethernet 7","addresses":[{"path":"fe80::81aa:d714:a0f:90cf","internal":false},{"path":"192.168.56.1","internal":false}]' | ||
console.log(getOsArch()); | ||
//=> '{"arch":"x64"}' | ||
``` | ||
## Unpacked Size | ||
Less than 5 kB |
2545
57
26