Socket
Socket
Sign inDemoInstall

@rjweb/utils

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rjweb/utils - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## 1.3.1
- Add `system.cpu`
## 1.3.0

@@ -2,0 +6,0 @@

2

lib/cjs/pckg.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc