Compare View
Commits (2)
Changes
Showing 4 changed files Side-by-side Diff
lib/command-parser.js
... | ... | @@ -11,7 +11,11 @@ function splitToken(msg) { |
11 | 11 | return; |
12 | 12 | } |
13 | 13 | |
14 | - return msg.trim().split(/[\s\.]+/); // eslint-disable-line no-useless-escape | |
14 | + const delimiters = msg.trim().match(/^\w+(\W)/); | |
15 | + const delimiter = delimiters && delimiters[1] ? delimiters[1] : null; | |
16 | + | |
17 | + const delimiterRegex = delimiter ? new RegExp('\\' + delimiter + '+') : new RegExp('[\\s\\.]+'); | |
18 | + return msg.trim().split(delimiterRegex); | |
15 | 19 | } |
16 | 20 | |
17 | 21 | function _makeSureAsTokensArray(msgOrTokens) { |
package-lock.json
package.json
test/command-parser.js
... | ... | @@ -13,6 +13,10 @@ describe('#command-parser', function() { |
13 | 13 | |
14 | 14 | commandParser.splitToken('SAL.1234')[1].should.equal('1234'); |
15 | 15 | commandParser.splitToken('SAL 1234')[1].should.equal('1234'); |
16 | + | |
17 | + }) | |
18 | + | |
19 | + it('should handle repeating splitter', function() { | |
16 | 20 | commandParser.splitToken('SAL 1234')[1].should.equal('1234'); |
17 | 21 | }) |
18 | 22 |