Skip to content
Open
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
24 changes: 23 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var net = require('net'),
normalizeConnectArgs = net._normalizeConnectArgs,
dns = require('dns'),
util = require('util'),
inherits = util.inherits,
Expand All @@ -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);
Expand Down