index.js
function splitCsvLine(line) {
  if (!line.trim().length) {
    return [];
  }
  var fields = [];
  var inQuotes = false;
  var separator = 0;
  for (var i = 0; i < line.length; i++) {
    switch(line[i]) {
      case "\"":
        if (i>0 && line[i-1] != "\\") {
          inQuotes = !inQuotes;
        }
        break;
      case ",":
        if (!inQuotes) {
          if (separator < i) {
            var field = line.substring(separator, i).trim();
            if (field.length) {
              fields.push(field);
            }
          }
          separator = i + 1;
        }
        break;
    }
  }
  fields.push(line.substring(separator).trim());
  return fields;
}
function splitCsvLine(line) {
  if (!line.trim().length) {
    return [];
  }
  var fields = [];
  var inQuotes = false;
  var separator = 0;
  for (var i = 0; i < line.length; i++) {
    switch(line[i]) {
      case "\"":
        if (i>0 && line[i-1] != "\\") {
          inQuotes = !inQuotes;
        }
        break;
      case ",":
        if (!inQuotes) {
          if (separator < i) {
            var field = line.substring(separator, i).trim();
            if (field.length) {
              fields.push(field);
            }
          }
          separator = i + 1;
        }
        break;
    }
  }
  fields.push(line.substring(separator).trim());
  return fields;
}
function splitCsvLine ( line ) { if ( ! line . trim ( ) . length ) { return [ ] ; } var fields = [ ] ; var inQuotes = false ; var separator = 0 ; for ( var i = 0 ; i < line . length ; i ++ ) { switch ( line [ i ] ) { case "\"" : if ( i > 0 && line [ i - 1 ] != "\\" ) { inQuotes = ! inQuotes ; } break ; case "," : if ( ! inQuotes ) { if ( separator < i ) { var field = line . substring ( separator , i ) . trim ( ) ; if ( field . length ) { fields . push ( field ) ; } } separator = i + 1 ; } break ; } } fields . push ( line . substring ( separator ) . trim ( ) ) ; return fields ; }
Converts a line of a CSV file to an array of strings, omitting empty fields.
@param {String} line
@returns {String[]}
Converts a line of a CSV file to an array of strings omitting empty fields .