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

Cleanup types for package #36

Merged
merged 1 commit into from
May 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 85 additions & 53 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>): Promise<any>
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<Options, 'host' | 'timeout' | 'raw'>
type OptionsAsn = OptionsIp
type OptionsQuery = Omit<Options, 'raw' | 'follow'>
type OptionsTld = Pick<Options, 'timeout' | 'raw'>
type OptionsDomain = Omit<Options, 'querySuffix' | 'query' | 'port'>
type OptionsGeneric = OptionsIp | OptionsTld | OptionsDomain

interface WhoisSearchResult {
[key: string]: string | Array<string> | 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<string[]>}
*/
tld(tld: string, options?: Omit<CommonOptions, 'host'>): Promise<any>;
function allTlds(): Promise<string[]>

/**
* Query a WHOIS server for data
* Get WHOIS data for an AS number
*
* @param {Object} options
* @returns {Promise<string>} Raw WHOIS server response
* @param {string|number} asn
* @param {OptionsAsn} options
* @returns {Promise<WhoisSearchResult>} Parsed WHOIS server response
*/
query(options: CommonOptions & {
query: string;
/** Low level end of query suffix. Default `\r\n` */
querySuffix?: string;
}): Promise<string>
function asn(asn: string | number, options?: OptionsAsn): Promise<WhoisSearchResult>

/**
* Get parsed WHOIS data for a domain
*
* @param domain
* @param options
* @param {string} domain
* @param {OptionsDomain} options
* @returns {Promise<WhoisSearchResult>} 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<any>
function domain(domain: string, options?: OptionsDomain): Promise<WhoisSearchResult>

/**
* Get WHOIS data for a IP
*
* @param {string} ip
* @param {Object} options
* @returns {Promise<*>} Parsed WHOIS server response
* @param {OptionsIp} options
* @returns {Promise<WhoisSearchResult>} Parsed WHOIS server response
*/
ip(ip: string, options?: CommonOptions): Promise<any>
function ip(ip: string, options?: OptionsIp): Promise<WhoisSearchResult>

/**
* 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<string>} Raw WHOIS server response
*/
asn(asn: string | number, options?: CommonOptions): Promise<any>;
function query(options: OptionsQuery): Promise<string>

/**
* Returns a list of all TLDs, [downloaded from IANA](https://www.iana.org/domains/root/db)
* Get WHOIS data for a TLD
*
* @returns {Promise<string[]>}
* @param {string} tld Ex. `.net`
* @param {OptionsTld} options
* @returns {Promise<WhoisSearchResult>} Parsed WHOIS server response
*/
allTlds(): Promise<string[]>;
}
function tld(tld: string, options?: OptionsTld): Promise<WhoisSearchResult>

declare const whoiser: Whoiser;
export = whoiser;
/**
* Tries to guess query type and get WHOIS data
*
* @param {string} query
* @param {Options} options
* @returns {Promise<WhoisSearchResult>} Parsed WHOIS server response
*/
function whoiser(query: string, options?: OptionsGeneric): Promise<WhoisSearchResult>

export = whoiser
}