@rjweb/utils
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -0,1 +1,5 @@ | ||
## 1.3.1 | ||
- Add `system.cpu` | ||
## 1.3.0 | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "@rjweb/utils", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
@@ -31,2 +31,3 @@ "use strict"; | ||
__export(system_exports, { | ||
cpu: () => cpu, | ||
execute: () => execute | ||
@@ -36,2 +37,18 @@ }); | ||
var child = __toESM(require("child_process")); | ||
var os = __toESM(require("os")); | ||
var import__ = require("."); | ||
function cpuAverage() { | ||
let totalIdle = 0, totalTick = 0; | ||
const cpus = os.cpus(); | ||
for (const cpu2 of cpus) { | ||
for (const time of Object.values(cpu2.times)) { | ||
totalTick += time; | ||
} | ||
totalIdle += cpu2.times.idle; | ||
} | ||
return { | ||
idle: totalIdle / cpus.length, | ||
total: totalTick / cpus.length | ||
}; | ||
} | ||
function execute(command, options) { | ||
@@ -54,5 +71,16 @@ var _a; | ||
} | ||
async function cpu(captureTime = 250) { | ||
return new Promise((resolve) => { | ||
const startUsage = cpuAverage(); | ||
setTimeout(() => { | ||
const usage = cpuAverage(); | ||
const idle = usage.idle - startUsage.idle, total = usage.total - startUsage.total; | ||
return resolve(import__.number.round(100 - 100 * idle / total, 2)); | ||
}, captureTime); | ||
}); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
cpu, | ||
execute | ||
}); |
{ | ||
"name": "@rjweb/utils", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
import * as child from "child_process"; | ||
import * as os from "os"; | ||
import { number } from "."; | ||
function cpuAverage() { | ||
let totalIdle = 0, totalTick = 0; | ||
const cpus = os.cpus(); | ||
for (const cpu2 of cpus) { | ||
for (const time of Object.values(cpu2.times)) { | ||
totalTick += time; | ||
} | ||
totalIdle += cpu2.times.idle; | ||
} | ||
return { | ||
idle: totalIdle / cpus.length, | ||
total: totalTick / cpus.length | ||
}; | ||
} | ||
function execute(command, options) { | ||
@@ -19,4 +35,15 @@ var _a; | ||
} | ||
async function cpu(captureTime = 250) { | ||
return new Promise((resolve) => { | ||
const startUsage = cpuAverage(); | ||
setTimeout(() => { | ||
const usage = cpuAverage(); | ||
const idle = usage.idle - startUsage.idle, total = usage.total - startUsage.total; | ||
return resolve(number.round(100 - 100 * idle / total, 2)); | ||
}, captureTime); | ||
}); | ||
} | ||
export { | ||
cpu, | ||
execute | ||
}; |
@@ -14,6 +14,16 @@ /** | ||
/** | ||
* Whether to use async fs | ||
* @default false | ||
* Whether to use async fs | ||
* @default false | ||
* @since 1.3.0 | ||
*/ async?: boolean; | ||
}>(command: string, options: Options): Options['async'] extends true ? Promise<string> : string; | ||
*/ async?: boolean; | ||
}>(command: string, options?: Options): Options['async'] extends true ? Promise<string> : string; | ||
/** | ||
* Get the Systems CPU Usage | ||
* @example | ||
* ``` | ||
* import { system } from "@rjweb/utils" | ||
* | ||
* await system.cpu() // 3.76 | ||
* ``` | ||
* @since 1.3.1 | ||
*/ export declare function cpu(captureTime?: number): Promise<number>; |
{ | ||
"name": "@rjweb/utils", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56308
1618
3