ryu1kn / csv-writer

Convert objects/arrays into a CSV string or write them into a CSV file
https://www.npmjs.com/package/csv-writer
MIT License
246 stars 39 forks source link

Empty newlines #13

Closed jpospychala closed 6 years ago

jpospychala commented 6 years ago

Hi there, nice project! I just found it on npm and noticed some unusual behavior I thought worth reporting. In the example you write:

`console.log(csvStringifier.getHeaderString()); // => 'NAME,LANGUAGE\n'

console.log(csvStringifier.stringifyRecords(records)); // => 'Bob,"French, English"\nMary,English\n'`

but the output then is:

` NAME,LANGUAGE

Bob,"French, English" Mary,English

`

Note the empty newlines after header and after output. I'm not quite sure if this really is correct output.

jpospychala commented 6 years ago

okay rereading this I think it's an unfortunate example in README.md that this function results are passed to console.log which adds it's own newlines.

ryu1kn commented 6 years ago

Hi @jpospychala

console.log which adds it's own newlines

Yeah, that's it. If you concatenate getHeaderString and stringifyRecords outputs, you shouldn't see redundant newlines 😉

console.log(csvStringifier.getHeaderString() + csvStringifier.stringifyRecords(records));