Passed
Push — master ( c17029...e68583 )
by Muhammad Dyas
01:29
created

utils.js ➔ splitMessage   A

Complexity

Conditions 4

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
dl 0
loc 13
rs 9.9
c 0
b 0
f 0
1
/**
2
 * Split string/message to topic and choice
3
 * reference: https://stackoverflow.com/a/18647776/2671470
4
 *
5
 * @param {string} message - the new option name
6
 * @returns {array} card
7
 */
8
function splitMessage(message) {
9
  const expression = /[^\s"]+|"([^"]*)"/gi;
10
  const result = [];
11
  let match;
12
  do {
13
    match = expression.exec(message);
14
    if (match != null) {
0 ignored issues
show
Best Practice introduced by
Comparing match to null using the != operator is not safe. Consider using !== instead.
Loading history...
15
      result.push(match[1] ? match[1] : match[0]);
16
    }
17
  } while (match != null);
18
19
  return result;
20
}
21
22
23
exports.splitMessage = splitMessage;
24