Skip to content

Commit 0b87509

Browse files
committed
fixing csv2json tests
1 parent b588a06 commit 0b87509

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/csv-2-json.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,17 @@ var createDocument = function (keys, line) {
8888
* @returns {Array}
8989
*/
9090
var convertCSV = function (lines, callback) {
91-
var nonHeaderLines = lines.splice(1), // All lines that are not the header line
92-
generatedHeaders = retrieveHeading(lines, callback), // Retrieve the headings from the CSV
93-
// If the user specified keys, then filter the generated keys down to the user specified keys so we have the key index
91+
var generatedHeaders = retrieveHeading(lines, callback), // Retrieve the headings from the CSV, unless the user specified the keys
92+
nonHeaderLines = lines.splice(1), // All lines except for the header line
93+
// If the user provided keys, filter the generated keys to just the user provided keys so we also have the key index
9494
headers = options.KEYS ? _.filter(generatedHeaders, function (headerKey) {
9595
return _.contains(options.KEYS, headerKey.value);
9696
}) : generatedHeaders;
9797

98-
// Reduce the nonHeaderLines into an array of documents representing the lines
99-
return _.reduce(nonHeaderLines, function (jsonDocs, line) {
100-
if (!line) { return; } // skip over empty lines
98+
return _.reduce(nonHeaderLines, function (documentArray, line) { // For each line, create the document and add it to the array of documents
99+
if (!line) { return documentArray; } // skip over empty lines
101100
var generatedDocument = createDocument(headers, line.trim());
102-
jsonDocs.push(generatedDocument);
103-
return jsonDocs;
101+
return documentArray.concat(generatedDocument);
104102
}, []);
105103
};
106104

0 commit comments

Comments
 (0)