node-csvtojson
node-csvtojson copied to clipboard
preFileLine line index is not incremented for the last line in CSV
Hello,
.preFileLine((fileLineString, lineIdx)=>{
if (lineIdx === 0){
return fileLineString.replace(/ /g,'')
}
return fileLineString
})
I'm using preFileLine() to remove spaces in CSV column headers.
For example:
column 1, column 2
ab cd, test test
should result in
column1, column2
ab cd, test test
When there are several rows in the CSV file – everything works fine. Still, when there is only one line in the CSV – the spaces are also being replaced in it. As far as I can see, this happens because of lineIdx for the second line stays 0.
What I have noticed is that it happens for any number of rows in CSV because for the last row in a file the lineIdx counter is not being incremented.
Bump!
I'm seeing this for two-line files with a header, one more line, and with no trailing end-of-line character.