Closed hassanhe closed 6 years ago
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
lib/csv-stringifiers/object.js | 6 | 7 | 85.71% | ||
<!-- | Total: | 6 | 7 | 85.71% | --> |
Totals | |
---|---|
Change from base Build 31: | 1.4% |
Covered Lines: | 60 |
Relevant Lines: | 67 |
Thank you @hassangit for the PR and sorry for my slow response.
I see the point of the enhancement but I'm kind of inclined to keep the current behaviour with the following reasons:
csv-writer
takes over part of the csv data preparation, but never be enough; resulting the responsibility split into 2 sides.{a: {b: 'value'}}
and {'a.b': 'value'}
I'm curious to see what code made you think you need this enhancement. With the concrete sample code, it might be easier to see the benefit.
@ryu1kn yes you're right about the single responsibility of the library, and the reason this enhancement came to my mind is after i had to flatten the data in order to use this library for my data model, and that annoyed me, i felt that the library lakes this simple feature to access the nested property with just a dot instead of several lines of code that i have to maintain, though i am with the library implementing this little step it benefits as a user a lot.
and for your third point i didn't understand the {a: {b: 'value'}}
way of referencing, if you are convinced of my point of view and want to implement this feature could you tell me an example of referencing that way to make sure of implementing it in future PR.
and i saw you are busy with other newer ✨ good repo's of your's so thanks 👍
@hassangit Thanks!
With the 3rd point, I meant the issue we would face if the user wants to write a value whose key contains .
, like:
const csvWriter = createCsvWriter({
path: './file.csv',
header: ['a.b']
});
csvWriter.writeRecords([{'a.b': 'value'}]) // Passing an object that has string 'a.b' as a key
The user expects to see the value in the CSV but they would get an empty string.
@hassangit I'm closing this PR for now, but thanks for your time and consideration for the contribution!
this will prevent the need to flatten the data model when writing a nested object based data to cvs
const records= [{ foo:{ bar:'bar value' } }]
if you want to writefoo.bar
in csv you reference it in the header now with dot notation likeconst params = { ... header: [ { id: 'foo.bar', title: 'bar' } ] }