Commit 0c77c866d3c25d684c3175896240810a5895a545
1 parent
13b04dfe0d
Exists in
master
ESLINT on command-parsers/command
Showing 1 changed file with 10 additions and 12 deletions Side-by-side Diff
lib/command-parser.js
1 | -"use strict"; | |
2 | - | |
3 | 1 | const commands = require('./command-group'); |
4 | 2 | |
5 | 3 | function splitToken(msg) { |
6 | 4 | if (typeof msg !== 'string') { |
7 | - return; | |
5 | + return null; | |
8 | 6 | } |
9 | 7 | |
10 | 8 | if (!msg.trim()) { |
11 | - return; | |
9 | + return null; | |
12 | 10 | } |
13 | 11 | |
14 | 12 | const delimiters = msg.trim().match(/^\w+(\W)/); |
15 | 13 | const delimiter = delimiters && delimiters[1] ? delimiters[1] : null; |
16 | 14 | |
17 | - const delimiterRegex = delimiter ? new RegExp('\\' + delimiter + '+') : new RegExp('[\s\.]+'); | |
15 | + const delimiterRegex = delimiter ? new RegExp(`\\${delimiter}+`) : new RegExp('[\s\.]+'); | |
18 | 16 | return msg.trim().split(delimiterRegex); |
19 | 17 | } |
20 | 18 | |
21 | -function _makeSureAsTokensArray(msgOrTokens) { | |
19 | +function makeSureAsTokensArray(msgOrTokens) { | |
22 | 20 | if (typeof msgOrTokens === 'string') { |
23 | 21 | return splitToken(msgOrTokens); |
24 | 22 | } |
... | ... | @@ -27,18 +25,18 @@ function _makeSureAsTokensArray(msgOrTokens) { |
27 | 25 | } |
28 | 26 | |
29 | 27 | function extractCommand(msgOrTokens) { |
30 | - msgOrTokens = _makeSureAsTokensArray(msgOrTokens); | |
28 | + const msgOrTokensArray = makeSureAsTokensArray(msgOrTokens); | |
31 | 29 | |
32 | - if (!msgOrTokens) return; | |
33 | - return msgOrTokens[0]; | |
30 | + if (!msgOrTokensArray) return null; | |
31 | + return msgOrTokensArray[0]; | |
34 | 32 | } |
35 | 33 | |
36 | 34 | function extractCommandGroup(msgOrTokens) { |
37 | 35 | const cmd = extractCommand(msgOrTokens); |
38 | - if (!cmd) return; | |
39 | - return commands[ cmd.toLowerCase() ]; | |
36 | + if (!cmd) return null; | |
37 | + return commands[cmd.toLowerCase()]; | |
40 | 38 | } |
41 | 39 | |
42 | 40 | exports.splitToken = splitToken; |
43 | 41 | exports.extractCommand = extractCommand; |
44 | -exports.extractCommandGroup = extractCommandGroup; | |
45 | 42 | \ No newline at end of file |
43 | +exports.extractCommandGroup = extractCommandGroup; |