Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mkd'd readme

  • Loading branch information...
commit 530549dbbf158c95bb4dc405576c38ad54aa8322 1 parent cdccd06
@mjpearson authored
Showing with 59 additions and 8 deletions.
  1. 0  README
  2. +51 −0 README.md
  3. +8 −8 index.js
View
0  README
No changes.
View
51 README.md
@@ -0,0 +1,51 @@
+## tldtools
+
+This module provides TLD domain extraction and resolution services.
+
+Installation
+
+ npm install tldtools
+
+Usage
+
+ var tldtools = require('tldtools');
+
+### tldtools.extract(fqdn)
+
+Extracts tld, domain and subdomain parts from the provided fqdn (supports FQDNs names and URIs).
+Returns an object keyed by
+
+* tld - top level domain (com, gov.uk etc)
+* domain - first subdomain of tld
+* subdomain - prefixing A records for domain/tld
+
+eg:
+
+ var tldtools = require('tldtools');
+ console.log(tldtools.extract('http://bob:funk@wagga.wagga.funkjazz.gov.au:1234/?go=abc&123'));
+
+Returns...
+
+ TLD Cache is UP
+ { subdomain: 'funkjazz.wagga.wagga',
+ domain: 'gov',
+ tld: 'au' }
+
+### tldtools.tldCacheRefresh(onSuccess, onFail)
+
+Rebuilds the local in-memory cache from either the remote TLD datasource, or a local copy of effective_tld_names.dat if the local copy exists.
+
+* onSuccess - success callback
+* onFail(errorMessage) - failure callback
+
+
+### tldtools.whois(fqdn, opts = {});
+
+Attempts to perform a whois lookup for the provided fqdn (supprts FQDNs and URI's)
+
+Available options (opts)
+
+* hostName - whois hostname (default whois.internic.net)
+* port - whois port (default 43)
+* onSuccess(whoisData) - whois request complete callback, containing utf8 encoded whois payload
+* onFail(errorMessage, fqdn) - failure callback
View
16 index.js
@@ -5,14 +5,12 @@ var request = require('request'),
TLD_TOOLS = {
_tldSource: 'http://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1',
- _tldLocalSource: __dirname + '/tlds_local',
+ _tldLocalSource: __dirname + '/effective_tld_names.dat',
_tldCacheOut: __dirname + '/.tlds',
_whoisDefaultOpts: {
- 'hostname' : 'whois.internic.net',
+ 'hostName' : 'whois.internic.net',
'port' : 43,
- 'timeout' : false,
- 'authoritative' : 'true',
'onSuccess' : function(whoisData) {
console.log(whoisData);
},
@@ -153,6 +151,7 @@ TLD_TOOLS = {
}
if (refreshCache) {
+ this._tldCacheStruct = {},
this._readFileCB(
this._tldLocalSource, // local path
this._tldSourceParseData, // read callback
@@ -207,7 +206,7 @@ TLD_TOOLS = {
if (undefined == this._whoisCacheStruct.domainName) {
- var hostName = (undefined != opts.hostname) ? opts.hostname : this._whoisDefaultOpts.hostname;
+ var hostName = (undefined != opts.hostName) ? opts.hostName : this._whoisDefaultOpts.hostName;
var port = (undefined != opts.port) ? opts.port : this._whoisDefaultOpts.port;
var stream = net.createConnection(port, hostName);
@@ -226,14 +225,14 @@ TLD_TOOLS = {
});
stream.addListener('error', function(exception) {
- onFail(exception.description);
+ onFail(exception.description, fqdn);
});
} else {
console.log('Returning from Cache');
onSuccess(this._whoisCacheStruct.domainName);
}
} else {
- onFail(fqdn + ' is not a valid domain');
+ onFail('Invalid Domain Name', fqdn);
}
},
@@ -275,7 +274,8 @@ TLD_TOOLS = {
tldCacheRefresh: function(onSuccess, onFail) {
this._syncTLDList( {
'onSuccess': onSuccess,
- 'onFail': onFail
+ 'onFail': onFail,
+ 'refresh' : true
} );
},
Please sign in to comment.
Something went wrong with that request. Please try again.