Skip to content
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

Invalid row index doesn't reflect original row count #130

Closed
jamescoletti opened this issue Mar 16, 2016 · 1 comment
Closed

Invalid row index doesn't reflect original row count #130

jamescoletti opened this issue Mar 16, 2016 · 1 comment

Comments

@jamescoletti
Copy link

This doesn't seem very intuitive at first glance. If it's by design, perhaps the docs should be updated.

When an invalid row is encountered, it appears to be removed from the original internal row count before the data-invalid event is emitted. This means each index value really corresponds to the total number of valid rows, not total rows, which presumably the user would need to keep track of while parsing.

Thanks for your work on this library.

var csv = require('fast-csv');

var csvData = "id,name,location\n\
1,Joe,Boston\n\
2,Emily,San Francisco\n\
,Harold,Dallas\n\
,Kate,Seattle\n\
5,William,New York";

csv.fromString(csvData, {headers: true})
  .validate(function (data) {
    return data.id;
  })
  .on('data', function (data) {
    console.log(data);
  })
  .on('data-invalid', function (data, index) {
    console.log(data, 'Error line: ' + index);
  });

/**
Outputs:

{ id: '1', name: 'Joe', location: 'Boston' }
{ id: '2', name: 'Emily', location: 'San Francisco' }
{ id: '', name: 'Harold', location: 'Dallas' } 'Error line: 2'
{ id: '', name: 'Kate', location: 'Seattle' } 'Error line: 2'
{ id: '5', name: 'William', location: 'New York' }

**/
doug-martin added a commit that referenced this issue Jul 28, 2019
* [FIXED] Invalid row index doesn't reflect original row count #130 #266 - @chrwnsk
@doug-martin doug-martin mentioned this issue Jul 28, 2019
@doug-martin
Copy link
Contributor

This will be fixed in v8.2.0 #268. Ill close this once the new version is published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants