All files / csv2json/libs/core getDelimiter.js

0% Statements 0/15
0% Branches 0/6
0% Functions 0/2
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                                             
module.exports = getDelimiter;
var defaulDelimiters = [",", "|", "\t", ";", ":"];
function getDelimiter(rowStr,param) {
  var checker;
  if (param.delimiter === "auto"){
    checker = defaulDelimiters;
  } else if (param.delimiter instanceof Array) {
    checker = param.delimiter;
  } else {
    return param.delimiter;
  }
  var count = 0;
  var rtn = ",";
  checker.forEach(function(delim) {
    var delimCount = rowStr.split(delim).length;
    if (delimCount > count) {
      rtn = delim;
      count = delimCount;
    }
  });
  return rtn;
}