diff --git a/lib/client.js b/lib/client.js index ff212e5..2949bd2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,5 +1,4 @@ var net = require('net'), - normalizeConnectArgs = net._normalizeConnectArgs, dns = require('dns'), util = require('util'), inherits = util.inherits, @@ -11,6 +10,29 @@ var Parser = require('./client.parser'), var CMD = require('./constants').CMD, ATYP = require('./constants').ATYP; +function normalizeConnectArgs(args) { + var options = {}; + + if (args.length === 0) { + return [options]; + } else if (args[0] !== null && typeof args[0] === 'object') { + // connect(options, [cb]) + options = args[0]; + } else if (typeof args[0] === 'string' && !(Number(args[0]) >= 0)) { + // connect(path, [cb]); + options.path = args[0]; + } else { + // connect(port, [host], [cb]) + options.port = args[0]; + if (args.length > 1 && typeof args[1] === 'string') { + options.host = args[1]; + } + } + + var cb = args[args.length - 1]; + return typeof cb === 'function' ? [options, cb] : [options]; +} + function Client(options) { if (!(this instanceof Client)) return new Client(options);