-
Notifications
You must be signed in to change notification settings - Fork 361
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
Opts object being modified by parsing method #317
Comments
Shouldn't be the same if I don't define let Json2csvParser = require('json2csv').Parser
let json2csv = new Json2csvParser({
header: false
})
console.log(json2csv.parse([
{
"a": 1,
"b": 2
},
{
"a": 3,
"b": 4
}
]))
// Output:
// 1,2
// 3,4
console.log(json2csv.parse([
{
"a": 1,
"x": 2
},
{
"a": 3,
"x": 4
}
]))
// Output:
// 1,
// 3,
// Should be?
// 1,2
// 3,4 |
It's a bug indeed!! I'll fix it asap. Thanks for reporting with such a clear code sample :) |
fields
selectionfields
selection when header: false
Not so good: I didn't figure out that the problem was when you use I've change the sample code. |
And you need to have the same object for the options! Work: let Json2csvParser = require('json2csv').Parser
let json2csv = new Json2csvParser({
header: false
})
console.log(json2csv.parse([
{
'a': 1,
'b': 2
},
{
'a': 3,
'b': 4
}
]))
// Output:
// 1,2
// 3,4
console.log()
json2csv = new Json2csvParser({
header: false
})
console.log(json2csv.parse([
{
'a': 1,
'x': 2
},
{
'a': 3,
'x': 4
}
]))
// Output:
// 1,2
// 3,4 Do not work: let Json2csvParser = require('json2csv').Parser
let json2csvParserOptions = {
header: false
}
let json2csv = new Json2csvParser(json2csvParserOptions)
console.log(json2csv.parse([
{
'a': 1,
'b': 2
},
{
'a': 3,
'b': 4
}
]))
// Output:
// 1,2
// 3,4
console.log()
json2csv = new Json2csvParser(json2csvParserOptions)
console.log(json2csv.parse([
{
'a': 1,
'x': 2
},
{
'a': 3,
'x': 4
}
]))
// Output:
// 1,
// 3, |
Yeah. The problem is that running any parsing modified the options object. Once again, thanks for reporting. Will be fixed whenever the PR get's merged. |
Fix published in v4.2.1 |
fields
selection when header: false
Thx for the reactivity! |
Thanks for the detailed issue 💃 |
Versions:
The text was updated successfully, but these errors were encountered: