node-csvtojson icon indicating copy to clipboard operation
node-csvtojson copied to clipboard

preFileLine line index is not incremented for the last line in CSV

Open Rest0 opened this issue 5 years ago • 2 comments

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.

Rest0 avatar Nov 20 '19 08:11 Rest0

Bump!

prateekkathal avatar Oct 21 '20 06:10 prateekkathal

I'm seeing this for two-line files with a header, one more line, and with no trailing end-of-line character.

mikebridge avatar Jul 20 '21 22:07 mikebridge