diff --git a/index.d.ts b/index.d.ts index 2230264..9d464d1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,83 +1,115 @@ -type CommonOptions = { - /** WHOIS server to query. Default: WHOIS server from IANA */ - host?: string - /** WHOIS server request timeout in ms. Default: `1500` */ - timeout?: number - /** Return the raw WHOIS result in response. Added to `__raw` */ - raw?: boolean -} +declare module 'whoiser' { + interface Options { + /** + * WHOIS server to query. + */ + host?: string -interface Whoiser { - /** - * Get WHOIS data for any internet address - * - * @param {string|number} query - * @param {Object} options - * @returns {Promise<*>} Parsed WHOIS server response - */ - (query: string | number, options?: CommonOptions & Record): Promise + port?: number + + /** + * WHOIS server request timeout in ms. + * + * @default: 1500 + */ + timeout?: number + + /** + * How many WHOIS server to query. + * 1 = registry server (faster), + * 2 = registry + registrar (more domain details). + * + * @default: 2 + */ + follow?: number + + /** + * Return the raw WHOIS result in response. + * Added to `__raw` + */ + raw?: boolean + + query?: string + /** + * Low level end of query suffix. + * + * @default '\r\n' + */ + querySuffix?: string + } + + type OptionsIp = Pick + type OptionsAsn = OptionsIp + type OptionsQuery = Omit + type OptionsTld = Pick + type OptionsDomain = Omit + type OptionsGeneric = OptionsIp | OptionsTld | OptionsDomain + + interface WhoisSearchResult { + [key: string]: string | Array | WhoisSearchResult + } /** - * Get WHOIS data for a TLD + * Returns a list of all TLDs, + * [downloaded from IANA](https://www.iana.org/domains/root/db) * - * @param {string} tld Ex. `.net` - * @param {Object} options - * @returns {Promise<*>} Parsed WHOIS server response + * @returns {Promise} */ - tld(tld: string, options?: Omit): Promise; + function allTlds(): Promise /** - * Query a WHOIS server for data + * Get WHOIS data for an AS number * - * @param {Object} options - * @returns {Promise} Raw WHOIS server response + * @param {string|number} asn + * @param {OptionsAsn} options + * @returns {Promise} Parsed WHOIS server response */ - query(options: CommonOptions & { - query: string; - /** Low level end of query suffix. Default `\r\n` */ - querySuffix?: string; - }): Promise + function asn(asn: string | number, options?: OptionsAsn): Promise /** * Get parsed WHOIS data for a domain * - * @param domain - * @param options + * @param {string} domain + * @param {OptionsDomain} options + * @returns {Promise} Parsed WHOIS server response */ - domain( - domain: string, - options?: CommonOptions & { - /** How many WHOIS server to query. 1 = registry server (faster), 2 = registry + registrar (more domain details). Default: 2 */ - follow?: number - } - ): Promise + function domain(domain: string, options?: OptionsDomain): Promise /** * Get WHOIS data for a IP * * @param {string} ip - * @param {Object} options - * @returns {Promise<*>} Parsed WHOIS server response + * @param {OptionsIp} options + * @returns {Promise} Parsed WHOIS server response */ - ip(ip: string, options?: CommonOptions): Promise + function ip(ip: string, options?: OptionsIp): Promise /** - * Get WHOIS data for an AS number + * Query a WHOIS server for data * - * @param {string|number} asn - * @param {Object} options - * @returns {Promise<*>} Parsed WHOIS server response + * @param {OptionsQuery} options + * @returns {Promise} Raw WHOIS server response */ - asn(asn: string | number, options?: CommonOptions): Promise; + function query(options: OptionsQuery): Promise /** - * Returns a list of all TLDs, [downloaded from IANA](https://www.iana.org/domains/root/db) + * Get WHOIS data for a TLD * - * @returns {Promise} + * @param {string} tld Ex. `.net` + * @param {OptionsTld} options + * @returns {Promise} Parsed WHOIS server response */ - allTlds(): Promise; -} + function tld(tld: string, options?: OptionsTld): Promise -declare const whoiser: Whoiser; -export = whoiser; + /** + * Tries to guess query type and get WHOIS data + * + * @param {string} query + * @param {Options} options + * @returns {Promise} Parsed WHOIS server response + */ + function whoiser(query: string, options?: OptionsGeneric): Promise + + export = whoiser +}