-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support null or false to omit header row #34
base: master
Are you sure you want to change the base?
Conversation
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
@@ -15,7 +15,7 @@ export const convertArrayOfObjectsToCSV = (data, { header, separator }) => { | |||
|
|||
array.forEach((row, idx) => { | |||
const thisRow = Object.keys(row); | |||
if (!header && idx === 0) { | |||
if (header === undefined && idx === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent is to allow Null or False (an explicit negative) to signify not to include the header, but when the value is not specified at all (undefined)... to automatically include the default (the current behaviour)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, so if its null or undefined it should skip this line and not go into the if stmt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By changing the logic to identify an explicit false we're able to have the following:
const dataArrays = [ {a: 1, b: 2}, {a: 3, b: 4} ];
const csvFromArrayOfArrays = convertArrayToCSV(dataArrays, { header: false });
With output of:
1,2
3,4
Versus the normal behavior of:
const dataArrays = [ {a: 1, b: 2}, {a: 3, b: 4} ];
const csvFromArrayOfArrays = convertArrayToCSV(dataArrays);
With output of:
a,b
1,2
3,4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, that looks legit. I have to take a look myself, but overall I am looking forward to getting this PR merged.
In my case, I had an array of objects but did not want the header row.
This change allows for
options.header
to be set tonull
orfalse
to explicitly omit the header row.