From aa9bd2cace4a5f352c8b8fd6cec8722151282102 Mon Sep 17 00:00:00 2001 From: Glen Selle Date: Tue, 3 Jan 2017 08:57:37 -0600 Subject: [PATCH 1/3] Added a columnTransform func to transform column names --- csv-streamify.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/csv-streamify.js b/csv-streamify.js index 32f2633..dd473e3 100644 --- a/csv-streamify.js +++ b/csv-streamify.js @@ -16,7 +16,8 @@ module.exports = function (opts, cb) { opts.empty = opts.hasOwnProperty('empty') ? opts.empty : '' opts.objectMode = opts.objectMode || false opts.hasColumns = opts.columns || false - + opts.columnTransform = opts.columnTransform || function(l) { return l } + // state var state = { body: [], @@ -41,7 +42,7 @@ function createParser (opts, state) { if (opts.hasColumns) { if (state.lineNo === 0) { - state._columns = state._line + state._columns = state._line.map(opts.columnTransform) state.lineNo += 1 reset() return From 8ce1181905b1c34c68cfe482568bf6d092e7d635 Mon Sep 17 00:00:00 2001 From: Glen Selle Date: Tue, 3 Jan 2017 09:04:02 -0600 Subject: [PATCH 2/3] Updated readme with usage example --- Readme.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index c8d5112..b1b1ce8 100644 --- a/Readme.md +++ b/Readme.md @@ -71,7 +71,12 @@ The options are also passed to the underlying transform stream, so you can pass objectMode: false, // if set to true, uses first row as keys -> [ { column1: value1, column2: value2 }, ...] - columns: false + columns: false, + + // each csv column name is optionally mapped to this so its value can be transformed + columnTransform: function(name) { + return name + } } ``` From fae418d0f1201b6859d4e36a4cd6e6f96a047d29 Mon Sep 17 00:00:00 2001 From: Glen Selle Date: Tue, 3 Jan 2017 09:20:24 -0600 Subject: [PATCH 3/3] Fixed StandardJS formatting --- csv-streamify.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csv-streamify.js b/csv-streamify.js index dd473e3..254853e 100644 --- a/csv-streamify.js +++ b/csv-streamify.js @@ -16,8 +16,8 @@ module.exports = function (opts, cb) { opts.empty = opts.hasOwnProperty('empty') ? opts.empty : '' opts.objectMode = opts.objectMode || false opts.hasColumns = opts.columns || false - opts.columnTransform = opts.columnTransform || function(l) { return l } - + opts.columnTransform = opts.columnTransform || function (l) { return l } + // state var state = { body: [],