fix(formatting): Fix minor formatting issues and newline consistency across project files

This commit is contained in:
2025-05-03 18:56:00 +00:00
parent 7d087e39ef
commit def467a27b
9 changed files with 53 additions and 50 deletions

View File

@ -44,9 +44,7 @@ export class SmartNetwork {
* get network speed
* @param opts optional speed test parameters
*/
public async getSpeed(
opts?: { parallelStreams?: number; duration?: number },
) {
public async getSpeed(opts?: { parallelStreams?: number; duration?: number }) {
const cloudflareSpeedInstance = new CloudflareSpeed(opts);
return cloudflareSpeedInstance.speedTest();
}
@ -54,10 +52,7 @@ export class SmartNetwork {
/**
* Send ICMP pings to a host. Optionally specify count for multiple pings.
*/
public async ping(
host: string,
opts?: { timeout?: number; count?: number },
): Promise<any> {
public async ping(host: string, opts?: { timeout?: number; count?: number }): Promise<any> {
const timeout = opts?.timeout ?? 500;
const count = opts?.count && opts.count > 1 ? opts.count : 1;
const pinger = new plugins.smartping.Smartping();
@ -85,11 +80,7 @@ export class SmartNetwork {
const min = valid.length ? Math.min(...valid) : NaN;
const max = valid.length ? Math.max(...valid) : NaN;
const avg = valid.length ? stats.average(valid) : NaN;
const stddev = valid.length
? Math.sqrt(
stats.average(valid.map((v) => (v - avg) ** 2)),
)
: NaN;
const stddev = valid.length ? Math.sqrt(stats.average(valid.map((v) => (v - avg) ** 2))) : NaN;
const packetLoss = ((count - aliveCount) / count) * 100;
return {
host,
@ -168,7 +159,9 @@ export class SmartNetwork {
*/
public async isRemotePortAvailable(
target: string,
portOrOpts?: number | { port?: number; protocol?: 'tcp' | 'udp'; timeout?: number; retries?: number },
portOrOpts?:
| number
| { port?: number; protocol?: 'tcp' | 'udp'; timeout?: number; retries?: number },
): Promise<boolean> {
let hostPart: string;
let port: number | undefined;
@ -252,7 +245,9 @@ export class SmartNetwork {
/**
* Resolve DNS records (A, AAAA, MX)
*/
public async resolveDns(host: string): Promise<{ A: string[]; AAAA: string[]; MX: { exchange: string; priority: number }[] }> {
public async resolveDns(
host: string,
): Promise<{ A: string[]; AAAA: string[]; MX: { exchange: string; priority: number }[] }> {
try {
const dns = await import('dns');
const { resolve4, resolve6, resolveMx } = dns.promises;
@ -316,14 +311,10 @@ export class SmartNetwork {
const { exec } = await import('child_process');
const cmd = `traceroute -n -m ${maxHops} ${host}`;
const stdout: string = await new Promise((resolve, reject) => {
exec(
cmd,
{ encoding: 'utf8', timeout },
(err, stdout) => {
if (err) return reject(err);
resolve(stdout);
},
);
exec(cmd, { encoding: 'utf8', timeout }, (err, stdout) => {
if (err) return reject(err);
resolve(stdout);
});
});
const hops: Hop[] = [];
for (const raw of stdout.split('\n')) {