# All files / csv2json/libs/core csvline.js

0% Statements 0/13
0% Branches 0/6
0% Functions 0/1
0% Lines 0/13

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
    24

     var getEol = require("./getEol");
    var rowSplit = require("./rowSplit");
    /**
     * Convert lines to csv columns
     * @param  {[type]} lines [file lines]
     * @param  {[type]} param [Converter param]
     * @return {[type]}  {lines:[[col1,col2,col3...]],partial:String}
     */
    module.exports = function (lines, param) {
      var csvLines = [];
      var left = "";
      while (lines.length) {
        var line = left + lines.shift();
        var row = rowSplit(line, param);
        if (row.closed || param.alwaysSplitAtEOL) {
          csvLines.push(row.cols);
          left = "";
        } else {
          left = line + (getEol(line, param) || "\n"); // if unable to getEol from data, assume "\n"
        }
      }
      return { lines: csvLines, partial: left };
    };