From fc336ef90e7b35130d1431302a4e8dee3893ea5d Mon Sep 17 00:00:00 2001 From: Mike Lohmann Date: Fri, 28 Oct 2016 10:25:48 +0200 Subject: [PATCH] Send columns names beside the current line Added a parameter sendColumns to be able to send the column names beside the current line. --- csv-streamify.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/csv-streamify.js b/csv-streamify.js index 32f2633..40542e7 100644 --- a/csv-streamify.js +++ b/csv-streamify.js @@ -16,6 +16,7 @@ module.exports = function (opts, cb) { opts.empty = opts.hasOwnProperty('empty') ? opts.empty : '' opts.objectMode = opts.objectMode || false opts.hasColumns = opts.columns || false + opts.sendColumns = opts.sendColumns || false // state var state = { @@ -58,7 +59,11 @@ function createParser (opts, state) { // emit the parsed line as an array if in object mode // or as a stringified array (default) if (opts.objectMode) { - parser.push(state._line) + if (opts.sendColumns) { + parser.push({line: state._line, columns: state._columns}) + } else { + parser.push(state._line) + } } else { parser.push(JSON.stringify(state._line) + '\n') }