hongfangze-computer
v1.2.0
Published
comm.computer
Readme
电脑的CPU、内存等相关信息
介绍
获取电脑的硬件等信息
import { cpuNumbers,cpuInfo,cpuUsage,diskUsage,memoryUsage } from "hongfangze-computer";
/**
* 获取CPU的核心数
*/
export declare const cpuNumbers: number;
/**
* 获取 CPU 信息
* @return {{
* total: {
* user: number,
* sys: number,
* idle: number,
* irq: number,
* }, detail: {
* model: string,
* speed: number,
* times: {
* user: number,
* sys: number,
* idle: number,
* irq: number,
* }
* }[]
* }} CPU信息
* - total.user CPU花费在用户模式下的毫秒时间数(所有核心总和)
* - total.nice CPU花费在良好模式下的毫秒时间数(所有核心总和)
* - total.sys CPU花费在系统模式下的毫秒时间数(所有核心总和)
* - idle CPU花费在空闲模式下的毫秒时间数(所有核心总和)
* - total.irq CPU花费在中断请求模式下的毫秒时间数(所有核心总和)
* - detail 每个核心的数据
* - detail.model CPU型号描述,一般包含品牌型号以及频率等
* - detail.speed 单核(该核心)的CPU频率,单位:兆赫兹
* - detail.times 每个CPU核心单独消耗的毫秒时间数
*/
export declare const cpuInfo: () => {
total: {
user: number;
sys: number;
idle: number;
irq: number;
};
detail: {
model: string;
speed: number;
times: {
user: number;
sys: number;
idle: number;
irq: number;
};
}[];
};
/**
* 获取某时间段 CPU 利用率
* @param {number} [ms] 时间段,单位毫秒,默认1000
* @param {boolean} [percentage] 以百分比结果返回,默认true
* - true 结果返回string类型,如"90%"
* - false 结果返回number类型,如"0.9"
* @return {(Promise<string | number>)}
*/
export declare const cpuUsage: (ms?: number, percentage?: boolean) => Promise<string | number>;
/**
* 获取指定目录的磁盘(分区)使用情况
* @param {string} dir 需要获取的目录
* @return {Promise<{
* root: {
* total: string,
* used: string,
* available: string,
* "total-h": string,
* "used-h": string,
* "available-h": string,
* percentageUsed: string,
* },
* dir: {
* used: string,
* "used-h": string,
* percentageUsed: string,
* }
* }>} 指定目录及指定目录所在根目录的磁盘使用信息
* - root.total 指定目录所在根目录的磁盘总空间,单位千字节
* - root.used 指定目录所在根目录的磁盘已使用空间,单位千字节
* - root.available 指定目录所在根目录的磁盘剩余空间,单位千字节
* - root["total-h"] 指定目录所在根目录的磁盘总空间(已转换为最合适的单位表示)
* - root["used-h"] 指定目录所在根目录的磁盘已使用空间(已转换为最合适的单位表示)
* - root["available-h"] 指定目录所在根目录的磁盘剩余空间(已转换为最合适的单位表示)
* - root.percentageUsed 指定目录所在根目录的磁盘利用率
* dir.used 指定目录的磁盘已使用空间,单位千字节
* dir["used-h"] 指定目录的磁盘已使用空间(已转换为最合适的单位表示)
* dir.percentageUsed 指定目录的磁盘利用率(对于整个分区)
*/
export declare const diskUsage: (dir: string) => Promise<{
root: {
total: string;
used: string;
available: string;
"total-h": string;
"used-h": string;
"available-h": string;
percentageUsed: string;
};
dir: {
used: string;
"used-h": string;
percentageUsed: string;
};
}>;
/**
* 获取内存信息
* @return {{
* freemem: number,
* totalmem: number,
* "totalmem-h": string,
* "freemem-h": string,
* percentageUsed: string,
* }} 内存数据
* - freemem 剩余内存,单位字节
* - totalmem 总内存,单位字节
* - "freemem-h" 以"G"为单位返回剩余内存
* - "totalmem-h" 以"G"为单位返回总内存
* - percentageUsed 内存已使用百分比
*/
export declare const memoryUsage: () => {
freemem: number;
totalmem: number;
"totalmem-h": string;
"freemem-h": string;
percentageUsed: string;
};
/**
* 获取操作系统类型
* @return {({
* type: "windows" | "linux" | "macos",
* subType?: "redhat" | "debian"
* })} 操作系统类型
* - subType 只有在linux下才会返回
*/
export declare const osType: () => {
type: "windows" | "linux" | "macos";
subType?: "redhat" | "debian";
};
/**
* 操作系统、平台、架构信息
* @return {({
* type: "windows" | "linux" | "macos" | "ios" | "android" | "other",
* linuxType: 'redhat' | 'debian' | undefined,
* release: string,
* platform: 'aix' | 'darwin' | 'freebsd' | 'linux' | 'openbsd' | 'sunos' | 'win32' | 'android',
* arch: 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64'
* })} 返回数据
* - type 指定Node.js编译时的操作系统类型,ios目前为无效值,Android为实验期
* - linuxType Linux系统的分支版本,debian(如debian和ubuntu等)和redhat(CentOS等)
* - release 操作系统的发行版本
* - platform 指定Node.js编译时的操作系统平台 \
* 注意: 如果Node.js 在Android操作系统上构建, 'android'值 可能被返回. 然而, Android支持Node.js在当前被认为是实验期。 \
* ios目前为无效值
* - arch 表明 Node.js 二进制编译所用的 操作系统CPU架构
*/
export declare const info: () => {
type: "windows" | "linux" | "macos" | 'android' | "ios" | "other";
linuxType: 'redhat' | 'debian' | undefined;
release: string;
platform: 'aix' | 'darwin' | 'freebsd' | 'linux' | 'openbsd' | 'sunos' | 'win32' | 'android';
arch: 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64';
};
版本迭代记录
2025-06-05 v1.2.0
- 添加info函数,更详细的描述操作系统及平台信息。
2025-04-17 v1.1.0
- 增加获取操作系统类型的函数。
2025-04-16 v1.0.0
- 被移除后更名发布。
