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

Adding a new option to show/hide WHOIS protected data in response #96

Merged
merged 7 commits into from
Feb 6, 2023
Merged
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Get WHOIS info for domains.
- `timeout` - WHOIS server request timeout in ms. Default: 1500
- `follow` - How many WHOIS server to query. 1 = registry server (faster), 2 = registry + registrar (more domain details). Default: 2
- `raw` - Return the raw WHOIS result in response. Added to `__raw`
- `ignorePrivacy` - Show or hide the WHOIS protected data from response, accepts boolean. Default: true

```js
const whoiser = require('whoiser');
Expand Down
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ declare module 'whoiser' {
* @default '\r\n'
*/
querySuffix?: string

/**
* Ignore the protected WHOIS data from response
* and eplace them with empty values
* @default true
*/
ignorePrivacy?: boolean
}

export type OptionsIp = Pick<Options, 'host' | 'timeout' | 'raw'>
Expand Down
4 changes: 2 additions & 2 deletions src/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const parseSimpleWhois = (whois) => {
return data
}

const parseDomainWhois = (domain, whois) => {
const parseDomainWhois = (domain, whois, ignorePrivacy) => {
// Text saying there's no useful data in a field
const noData = [
'-',
Expand Down Expand Up @@ -325,7 +325,7 @@ const parseDomainWhois = (domain, whois) => {
}

// remove redacted data
if (noData.includes(value.toLowerCase())) {
if (ignorePrivacy && noData.includes(value.toLowerCase())) {
value = ''
}

Expand Down
4 changes: 2 additions & 2 deletions src/whoiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const whoisTld = async (query, { timeout = 15000, raw = false, domainTld = '' }
return data
}

const whoisDomain = async (rawDomain, { host = null, timeout = 15000, follow = 2, raw = false } = {}) => {
const whoisDomain = async (rawDomain, { host = null, timeout = 15000, follow = 2, raw = false, ignorePrivacy = true } = {}) => {
domain = punycode.toASCII(rawDomain)
const [domainName, domainTld] = splitStringBy(domain.toLowerCase(), domain.lastIndexOf('.'))
let results = {}
Expand Down Expand Up @@ -157,7 +157,7 @@ const whoisDomain = async (rawDomain, { host = null, timeout = 15000, follow = 2

try {
resultRaw = await whoisQuery({ host, query, timeout })
result = parseDomainWhois(domain, resultRaw)
result = parseDomainWhois(domain, resultRaw, ignorePrivacy)
} catch (err) {
result = { error: err.message }
}
Expand Down