From b5e59f3bbaacc2ad76b896bc72378f26cef4f064 Mon Sep 17 00:00:00 2001 From: Lee Elenbaas Date: Thu, 27 Oct 2016 12:51:28 +0300 Subject: [PATCH 1/3] copy normalizeConnectArgs from node 6 --- lib/client.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index ff212e5..5ecd90a 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 (isPipeName(args[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); From 2fc008d2486d1cc3259fb116f6b57374e73ddf69 Mon Sep 17 00:00:00 2001 From: Lee Elenbaas Date: Thu, 27 Oct 2016 13:24:26 +0300 Subject: [PATCH 2/3] fix isPipeName dependancy --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 5ecd90a..6854623 100644 --- a/lib/client.js +++ b/lib/client.js @@ -18,7 +18,7 @@ function normalizeConnectArgs(args) { } else if (args[0] !== null && typeof args[0] === 'object') { // connect(options, [cb]) options = args[0]; - } else if (isPipeName(args[0])) { + } else if (typeof args[0] === 'string' && Number(args[0]) >= 0) { // connect(path, [cb]); options.path = args[0]; } else { From 7039cb6aeb39fa3187b327bb2de5d1aedaae6a56 Mon Sep 17 00:00:00 2001 From: Lee Elenbaas Date: Thu, 27 Oct 2016 13:59:26 +0300 Subject: [PATCH 3/3] typo --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 6854623..2949bd2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -18,7 +18,7 @@ function normalizeConnectArgs(args) { } 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) { + } else if (typeof args[0] === 'string' && !(Number(args[0]) >= 0)) { // connect(path, [cb]); options.path = args[0]; } else {