fix(package): modernize package configuration and stabilize ping typings and tests
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartping',
|
||||
version: '1.0.8',
|
||||
description: 'a ping utility'
|
||||
name: '@push.rocks/smartping',
|
||||
version: '1.0.9',
|
||||
description: 'A utility for performing ping operations in Node.js environments.'
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
import * as plugins from './smartping.plugins.js';
|
||||
|
||||
export type TPingResponse = Awaited<ReturnType<typeof plugins.ping.promise.probe>>;
|
||||
|
||||
export class Smartping {
|
||||
public async ping(hostArg: string, timeoutArg: number = 500): Promise<plugins.ping.PingResponse> {
|
||||
public async ping(hostArg: string, timeoutArg: number = 500): Promise<TPingResponse> {
|
||||
const result = await plugins.ping.promise.probe(hostArg, {
|
||||
timeout: timeoutArg
|
||||
})
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public async pingAlive(hostArg: string, timeoutArg: number = 500): Promise<boolean> {
|
||||
const result = await plugins.ping.promise.probe(hostArg, {
|
||||
timeout: timeoutArg
|
||||
}).catch();
|
||||
//console.log(result);
|
||||
if (result.alive) {
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
const result = await this.ping(hostArg, timeoutArg);
|
||||
return result.alive;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ import ping from 'ping';
|
||||
|
||||
export {
|
||||
ping
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user