Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

skip_empty_lines property is not working as expected #308

Open
hemanthreddyk opened this issue Feb 9, 2021 · 5 comments
Open

skip_empty_lines property is not working as expected #308

hemanthreddyk opened this issue Feb 9, 2021 · 5 comments

Comments

@hemanthreddyk
Copy link

hemanthreddyk commented Feb 9, 2021

skip_empty_lines : Don't generate records for empty lines (line matching /\s*/), defaults to false.

As per the above definition it should ignore a row if it contains any string matching the regex '/\s*/'.
But when a row contains a space or tab in it, its not skipping the row and I am encountering following error
CsvError: Invalid Record Length: expect 2, got 1 on line 2

As a work around I have set trim as true and then it works.
Am I doing something wrong here or is it an issue?

const parse = require('csv-parse')
const assert = require('assert')

parse(`
"key_1","key_2"\n\t\n"value 1","value 2"
`.trim(), {
  // trim: true,
  columns: false,
  skip_empty_lines: true
}, (err, records) => {
  if (err) {
    console.log('******', err)
  }
  assert.deepStrictEqual(
    records, [
         [
         'key_1',
         'key_2'
        ],
        [
         'value 1',
          'value 2'
        ]]
  )
})
@wdavidw
Copy link
Member

wdavidw commented Feb 9, 2021

Could you edit you issue with a valid markdown syntax using triple backticks, thank you

@wdavidw
Copy link
Member

wdavidw commented Feb 9, 2021

The doc is wrong. In the current implementation, by "empty", we really mean empty, no spaces, no tabs. Let me see if I can do sth about it

@wdavidw
Copy link
Member

wdavidw commented Feb 9, 2021

You can combine skip_lines_with_empty_values and relax_column_count. Would that works for you ? I'll fix the doc

@hemanthreddyk
Copy link
Author

My use-case here is to ignore the second row which had tab space in it.
By enabling 'relax_column_count' I wont get an error if column count doesn't match with header count which is not desirable for us.

@wdavidw
Copy link
Member

wdavidw commented Feb 9, 2021

Then your solution with trim shall be appropriate.

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

No branches or pull requests

2 participants