All files / csv2json/src fileline.ts

100% Statements 2/2
100% Branches 2/2
100% Functions 0/0
100% Lines 2/2

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 25                1x 1x                              
import { ParseRuntime } from "./ParseRuntime";
import getEol from "./getEol";
// const getEol = require("./getEol");
/**
 * convert data chunk to file lines array
 * @param  {string} data  data chunk as utf8 string
 * @param  {object} param Converter param object
 * @return {Object}   {lines:[line1,line2...],partial:String}
 */
export function stringToLines(data: string, param: ParseRuntime): StringToLinesResult {
  const eol = getEol(data, param);
  const lines = data.split(eol);
  const partial = lines.pop() || "";
  return { lines: lines, partial: partial };
};
 
 
export interface StringToLinesResult {
  lines: Fileline[],
  /**
   * last line which could be incomplete line.
   */
  partial: string
}
export type Fileline = string;