forked from snd/whois-available
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
35 lines (22 loc) · 1.05 KB
/
index.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
punycode = require 'punycode'
common = require './common'
whoisServers = require './whois-servers'
whoisCommands = require './whois-commands'
availabilityChecks = require './availability-checks'
module.exports = (domain, cb) ->
if domain is ''
return process.nextTick -> cb new Error 'domain must not be empty'
domainPunycode = punycode.toASCII domain
domainParts = domainPunycode.split '.'
tld = domainParts[domainParts.length-1]
whoisServer = whoisServers[tld]
unless whoisServer?
return process.nextTick -> cb new Error "no whois server for tld #{tld}"
availabilityCheck = availabilityChecks[whoisServer]
unless availabilityCheck?
return process.nextTick -> cb new Error "no check for availability for whois server #{whoisServer}"
command = whoisCommands[whoisServer] || (x) -> x
common.whoisRequest whoisServer, command(domainPunycode), (err, response) ->
return cb err if err?
isAvailable = -1 isnt response.indexOf availabilityCheck
cb null, response, isAvailable