/*
 * TSV
 * Module for parsing TSV (and eventually other formats)
 */

const trimSplit = separator => str => str.trim().split(separator)
const isContentfulRow = row => row && !/^\s*$/.test(row)

function parseTSV(contents) {
  const content = {
    headers: [],
    rows: [],
  }
  content.rows = trimSplit('\n')(contents)
    .filter(isContentfulRow)
    .map(trimSplit('\t'))
  content.headers = content.rows.length ? content.rows[0] : [] 
  return content
}

export default parseTSV

/*
 * TSV
 * Module for parsing TSV (and eventually other formats)
 */

const normalizeEOL = str => str.replace('\r\n', '\n').replace('\r', '\n')
const isContentfulRow = row => row && !/^\s*$/.test(row)

function parseTSV(contents) {
  const content = {
    headers: [],
    rows: [],
  }
  content.rows = normalizeEOL(contents)
    .split('\n')
    .filter(isContentfulRow)
    .map(str => str.split('\t'))
  content.headers = content.rows.length ? content.rows[0] : [] 
  return content
}

export default parseTSV

Normalize TSV end-of-line without stripping all whitespace
FIX: Normalize TSV end-of-line without stripping all whitespace

(cherry picked from commit 786cfbb5847f5508720416cc7846fa1fcadc36bc)
