mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[ping] Add new definition file for ping (#35618)
* Add definitions for node-ping * Fix linting and test errors
This commit is contained in:
parent
70eeed4f7d
commit
b244a1ab2e
94
types/ping/index.d.ts
vendored
Normal file
94
types/ping/index.d.ts
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
// Type definitions for ping 0.2
|
||||
// Project: http://github.com/danielzzz/node-ping
|
||||
// Definitions by: Richard Honor <https://github.com/RMHonor>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
export interface PingConfig {
|
||||
/**
|
||||
* Map IP address to hostname or not. Default `true`
|
||||
*/
|
||||
numeric?: boolean;
|
||||
/**
|
||||
* Time duration, in seconds, for ping command to exit. Default `2` on Mac/Linux, `5` on Windows.
|
||||
*/
|
||||
timeout?: number;
|
||||
/**
|
||||
* Exit after sending number of `ECHO_REQUEST`. Default `1`
|
||||
*/
|
||||
min_reply?: number;
|
||||
/**
|
||||
* Ping via ipv6 or not. Default `false`
|
||||
*/
|
||||
v6?: boolean;
|
||||
/**
|
||||
* Source address for sending the ping.
|
||||
*/
|
||||
sourceAddr?: string;
|
||||
/**
|
||||
* Additional arguments. Default `[]`
|
||||
*/
|
||||
extra?: string[];
|
||||
}
|
||||
|
||||
export interface PingResponse {
|
||||
/**
|
||||
* The input IP address or host. `unknown` if ping fails.
|
||||
*/
|
||||
host: string;
|
||||
/**
|
||||
* Numeric target IP address
|
||||
*/
|
||||
numeric_host?: string;
|
||||
/**
|
||||
* `true` for existing host
|
||||
*/
|
||||
alive: boolean;
|
||||
/**
|
||||
* Raw stdout from system ping
|
||||
*/
|
||||
output: string;
|
||||
/**
|
||||
* Time (float) in ms for first successful ping response. `unknown` if ping fails.
|
||||
*/
|
||||
time: number | 'unknown';
|
||||
/**
|
||||
* Minimum time for collection records. `unknown` if ping fails.
|
||||
*/
|
||||
min: string;
|
||||
/**
|
||||
* Maximum time for collection records. `unknown` if ping fails.
|
||||
*/
|
||||
max: string;
|
||||
/**
|
||||
* Average time for collection records. `unknown` if ping fails.
|
||||
*/
|
||||
avg: string;
|
||||
/**
|
||||
* Standard deviation time for collected records. `unknown` if ping fails.
|
||||
*/
|
||||
stddev: string;
|
||||
}
|
||||
|
||||
export const sys: {
|
||||
/**
|
||||
* Performs a system ping utility.
|
||||
*
|
||||
* @param addr Hostname or IP address
|
||||
* @param cb Response callback.
|
||||
* First argument is successful response boolean.
|
||||
* Second argument is any error, `null` if no error.
|
||||
* @param config Optional configuration
|
||||
*/
|
||||
probe(addr: string, cb: (isAlive: boolean, error: any) => void, config?: PingConfig): void;
|
||||
};
|
||||
|
||||
export const promise: {
|
||||
/**
|
||||
* Performs a system ping utility.
|
||||
*
|
||||
* @param addr Hostname or IP address
|
||||
* @param config Optional configuration
|
||||
*/
|
||||
probe(addr: string, config?: PingConfig): Promise<PingResponse>;
|
||||
};
|
||||
38
types/ping/ping-tests.ts
Normal file
38
types/ping/ping-tests.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import {
|
||||
PingConfig,
|
||||
promise,
|
||||
sys,
|
||||
} from 'ping';
|
||||
|
||||
const config: PingConfig = {
|
||||
numeric: false,
|
||||
timeout: 1000,
|
||||
min_reply: 5,
|
||||
v6: false,
|
||||
sourceAddr: 'localhost',
|
||||
extra: [],
|
||||
};
|
||||
|
||||
sys.probe('test', (isAlive: boolean, err: any) => {
|
||||
const alive: boolean = isAlive;
|
||||
});
|
||||
|
||||
async function test() {
|
||||
const res = await promise.probe('test', config);
|
||||
|
||||
const alive: boolean = res.alive;
|
||||
const host: string = res.host;
|
||||
const output: string = res.output;
|
||||
const min: string = res.min;
|
||||
const max: string = res.max;
|
||||
const avg: string = res.avg;
|
||||
const stddev: string = res.stddev;
|
||||
|
||||
if (res.time !== 'unknown') {
|
||||
const time: number = res.time;
|
||||
}
|
||||
|
||||
if (res.numeric_host) {
|
||||
const numHost: string = res.numeric_host;
|
||||
}
|
||||
}
|
||||
23
types/ping/tsconfig.json
Normal file
23
types/ping/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ping-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/ping/tslint.json
Normal file
1
types/ping/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user