node-csvtojson
node-csvtojson copied to clipboard
Ignore lines before the header
I would like to request a new parameter
startOnLine: number
let's say my data look like
----,----,----
----,----,----
field1,field2,field3
val1,val2,val3
val4,val5,val6
So I would use it as
csv({
startOnLine: 3
}).fromFile(filePath)
.then(...
and then I would get
[
{
"field1": "val1",
"field2": "val2",
"field3": "val3"
},
{
"field1": "val4",
"field2": "val5",
"field3": "val6"
}
]
Awesome project btw! Thanks
I achieved this by using the preRawData api.
csv()
.fromFile(path)
.preRawData(str => {
const lines = str.split('\n');
// header is on second line
const trimmedStr = lines.filter((_, idx) => idx > 0).join('\n');
return trimmedStr;
})
preRawData event occurs twice on the file. event that needs to be handled right ?
yeah it seems it's being called twice.
If I print out lines.length, it looks like this.
lines.length 60
lines.length 1