CSV.parseCsv()

Parse comma-separated value data

Given a string of CSV data, transforms it into an array of objects (if header data is provided) or an array of arrays.

Usage

Hover over inputs/exits for more info.

var CSV = require('machinepack-csv');


// Parse comma-separated value data

CSV.parseCsv({

csvData: '"1","2","3","4"\n"a","b","c","d"',

schema: '*',

hasHeaderRow: true,

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// OK.

success: function () {

 

},

});

Inputs

csvData required

A string of CSV data.

'"1","2","3","4"\n"a","b","c","d"'
schema required

Expected schema of each parsed row

hasHeaderRow

Indicates whether or not the data has a header row.

true

Exits

error

An unexpected error occurred.

'Invalid closing quote at line 1'
success

OK.

(varies based on provided inputs)