node-ping icon indicating copy to clipboard operation
node-ping copied to clipboard

typescript definition file?

Open vrmerlin opened this issue 8 years ago • 6 comments

Is there a definition file for this module? I couldn't find one, and am having problems trying to create one of my own.

Thanks, John

vrmerlin avatar Oct 28 '16 20:10 vrmerlin

No. I guess we don't have such definition yet.

What else I can help although I am not familiar with the typescript at all :D

mondwan avatar Oct 29 '16 02:10 mondwan

It would be a good thing to add; i'll play with creating one of my own in the meantime.

vrmerlin avatar Nov 03 '16 00:11 vrmerlin

@vrmerlin any progress?

cojack avatar Jun 16 '17 12:06 cojack

This may not be completely exhaustive, and may not be 100% accurate, but it's a starting point:


declare module 'ping' {

  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
     */
    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
     */
    time: number;
    /**
     * Array of Time (float) in ms for each ping response
     */
    times: number[];
    /**
     * Minimum time for collection records
     */
    min: string;
    /**
     * Maximum time for collection records
     */
    max: string;
    /**
     * Average time for collection records
     */
    avg: string;
    /**
     * Standard deviation time for collected records
     */
    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>;
  }
}

RMHonor avatar May 17 '19 14:05 RMHonor

I know this an old issue, but for the sake of anyone still looking for a typescript type file, i am the creator of pingman module based on this one, but complete with ts types and couple of other features. Its also has a much more smaller unpacked size due to using only core node features and having no dependencies. It would be great if you guys could check it out.

dopecodez avatar May 19 '20 06:05 dopecodez

maybe a PR would help here, please

danielzzz avatar Apr 28 '22 06:04 danielzzz