From d1dad71515c29ffd2c552b68947b27bbb22c1563 Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <me@adhisimon.org>
Date: Thu, 18 Jul 2019 13:54:17 +0700
Subject: [PATCH] Smart delimiter

---
 lib/command-parser.js  | 6 +++++-
 test/command-parser.js | 4 ++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/command-parser.js b/lib/command-parser.js
index 4d338ce..7bebc52 100644
--- a/lib/command-parser.js
+++ b/lib/command-parser.js
@@ -11,7 +11,11 @@ function splitToken(msg) {
         return;
     }
 
-    return msg.trim().split(/[\s\.]+/); // eslint-disable-line no-useless-escape 
+    const delimiters = msg.trim().match(/^\w+(\W)/);
+    const delimiter = delimiters && delimiters[1] ? delimiters[1] : null;
+
+    const delimiterRegex = delimiter ? new RegExp('\\' + delimiter + '+') : new RegExp('[\\s\\.]+');
+    return msg.trim().split(delimiterRegex);
 }
 
 function _makeSureAsTokensArray(msgOrTokens) {
diff --git a/test/command-parser.js b/test/command-parser.js
index bfe5aa6..41d4b89 100644
--- a/test/command-parser.js
+++ b/test/command-parser.js
@@ -13,6 +13,10 @@ describe('#command-parser', function() {
             
             commandParser.splitToken('SAL.1234')[1].should.equal('1234');
             commandParser.splitToken('SAL 1234')[1].should.equal('1234');
+            
+        })
+
+        it('should handle repeating splitter', function() {
             commandParser.splitToken('SAL  1234')[1].should.equal('1234');
         })
 
-- 
1.9.0