Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript definition file? #53

Open
vrmerlin opened this issue Oct 28, 2016 · 6 comments
Open

typescript definition file? #53

vrmerlin opened this issue Oct 28, 2016 · 6 comments

Comments

@vrmerlin
Copy link

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

@mondwan
Copy link
Collaborator

mondwan commented Oct 29, 2016

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

@vrmerlin
Copy link
Author

vrmerlin commented Nov 3, 2016

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

@cojack
Copy link

cojack commented Jun 16, 2017

@vrmerlin any progress?

@RMHonor
Copy link

RMHonor commented May 17, 2019

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>;
  }
}

@dopecodez
Copy link

dopecodez commented May 19, 2020

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.

@danielzzz
Copy link
Owner

maybe a PR would help here, please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants