StephanGeorg / node-dig-dns

Use dig command (domain information grope) for DNS queries in node
MIT License
37 stars 21 forks source link

Add typescript definitions #3

Open BelfordZ opened 6 years ago

BelfordZ commented 6 years ago

As the title suggests =P

krei-se commented 3 months ago

Plus one

GregLtrnr commented 1 month ago

Here's an example for the lib declaration that I use, you can surely use it to include it to the project

declare module "node-dig-dns" {
  interface MXRecord {
    priority: number;
    server: string;
  }

  interface ParsedSection {
    domain: string;
    type: string;
    ttl: string | number;
    class: string;
    value: string | MXRecord;
  }

  interface ParsedResult {
    header?: ParsedSection[];
    question?: ParsedSection[];
    answer?: ParsedSection[];
    authority?: ParsedSection[];
    additional?: ParsedSection[];
    time: number;
    server: string;
    datetime: string;
    size: number;
  }

  interface DigOptions {
    /**
     * Get the raw output as a string. If `+short` option is passed in `args`, raw output is returned by default.
     */
    raw?: boolean;

    /**
     * Manually set the dig command (e.g., '/my/custom/path/to/dig').
     */
    dig?: string;
  }

  /**
   * Parses a DNS section based on its values.
   * @param values Array of section values.
   * @param section The section type (e.g., 'answer', 'additional').
   */
  function parseSection(values: any[], section: string): ParsedSection | any[];

  /**
   * Parses the output from the `dig` command.
   * @param output The raw output from the `dig` command.
   * @returns A parsed object containing DNS information.
   */
  function parse(output?: string): ParsedResult;

  /**
   * Runs the `dig` command with given arguments.
   * @param args Array of arguments for the `dig` command.
   * @param options Options for executing the `dig` command.
   * @returns A promise that resolves with the result of the `dig` command.
   */
  function dig(args?: string[], options?: DigOptions): Promise<ParsedResult | string>;

  export default dig;
}
StephanGeorg commented 1 month ago

Thank you @GregLtrnr. Could you pls add a PR?