From 4cc3a9709ec945c0bd1d5baea983e3f7072396ae Mon Sep 17 00:00:00 2001 From: Brandon Myers Date: Fri, 25 Aug 2017 23:49:43 -0500 Subject: [PATCH] Resolved #47. Added ability to pass pre-formated arguments using array instead of object. --- .gitignore | 6 ++++++ package.json | 2 +- src/Util.js | 5 ++--- src/index.js | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index f06235c..c48503f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ node_modules dist +examples +test +.vscode +.jshintrc +jsconfig.json +webpack.config.babel.js \ No newline at end of file diff --git a/package.json b/package.json index c87df43..13de99b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mikronode", "description": "Mikrotik API implemented in Node", - "version": "2.3.2", + "version": "2.3.3", "author": "Brandon Myers ", "scripts": { "build": "webpack --color --progress", diff --git a/src/Util.js b/src/Util.js index 19425eb..7d443af 100644 --- a/src/Util.js +++ b/src/Util.js @@ -177,10 +177,9 @@ function getUnwrappedPromise() { } function objToAPIParams(obj,type) { - const prefix=type==='print'?'?':'='; - const t=RegExp("[a-zA-Z]"); + const prefix=type==='print'?'':'='; return Object.keys(obj) - .map(k=>obj[k]?`${t.test(k[0])?prefix:""}${k}=${obj[k]}`:`${t.test(k[0])?prefix:""}${k}`); + .map(k=>obj[k]?`${prefix}${k}=${obj[k]}`:`${prefix}${k}`); } function resultsToObj(r) { diff --git a/src/index.js b/src/index.js index 9dafd45..5c725fa 100644 --- a/src/index.js +++ b/src/index.js @@ -417,7 +417,7 @@ class SocketStream { write(data,args) { if (args && typeof(args)===typeof({})) { this.debug>=DEBUG.SILLY&&console.log("Converting obj to args",args); - data=data.concat(objToAPIParams(args,data[0].split('/').pop())); + data=data.concat(Array.isArray(args)?args:objToAPIParams(args,data[0].split('/').pop())); } this.debug>=DEBUG.DEBUG&&console.log('SocketStream::write:',[data]); if (!this.socket||!(this.status&(CONNECTION.CONNECTED|CONNECTION.CONNECTING))) {