A Node.js package that reads a csv file and returns a collection of objects, using the first record's values as field labels.
For example:
// this csv:
//
// name,age
// sally,5
// billy,10
// becomes...
[
{name: "sally", age: "5"},
{name: "billy", age: "10"}
]
var csv = require('csv-to-collection');
csv.readCsv(__dirname + "/test.csv", function (err, data) {
if (err) throw err;
console.log(data);
});
Some of the header row values are altered and cleaned up before they are used as labels:
- new line characters are removed
- multiple spaces are replaced with 1 space
- all characters are converted to lower case
There are currently no options for this module. I'll add them when I need them, or as requested. Right now the module assumes UTF8 encoded, comma delimited, quote escaped csv files.
npm install csv-to-collection
MIT