Closed GianlucaRi closed 4 years ago
@GianlucaRi thanks for the issue. Please put your reproduction into a repo that can be cloned and run without any additional manual steps being required by maintainers.
I've added an explicit test to make sure the option is working correctly:
It would appear that it's something on your end at this time.
Thank you, with your test I have found the problem.
It was a length header problem, I have to put headers with a good size.
If I do this, it works :
const filepath = "./test.csv";
const csv = require('csv-parser');
const fs = require('fs');
const results = [];
fs.createReadStream(filepath)
.pipe(csv({
// work
headers: ["AAA", "BBB", "CCC", "DDD", "EEE", "FFF", "GGG", "HHH", "III", "JJJ", "KKK", "LLL", "MMM", "NNN", "OOO", "PPP", "QQQ", "RRR", "SSS", "TTT", "UUU", "VVV", "WWW", "XXX"],
// work with more
// headers: ["AAA", "BBB", "CCC", "DDD", "EEE", "FFF", "GGG", "HHH", "III", "JJJ", "KKK", "LLL", "MMM", "NNN", "OOO", "PPP", "QQQ", "RRR", "SSS", "TTT", "UUU", "VVV", "WWW", "XXX", "YYY"],
// don t work with less header
// headers: ["AAA", "BBB", "CCC", "DDD", "EEE", "FFF", "GGG", "HHH", "III", "JJJ", "KKK", "LLL", "MMM", "NNN", "OOO", "PPP", "QQQ", "RRR", "SSS", "TTT", "UUU", "VVV", "WWW"],
separator: ";",
}))
.on('data', (data) => results.push(data))
.on('end', () => {
console.log("*********** results size" + results.length);
console.log(results[0]);
console.log(results[1]);
});
I'd rather not create a repository just for that, but I have modify the javascript file to allow make the local testing easy. The data must be in the same folder name : "test.csv", and the code above in index.js npm install csv-parser node index.js
Thank you for your help,
Have a nice day !
glad you got it sorted!
Hello ! I have no problem with this library in all the cases except one : When I had custom header. Maybe I am just doing a mistake
Expected Behavior
Headers present in json.
Actual Behavior
It still return 0, 1, 2 ... has headers
How Do We Reproduce?
test.csv
index.js