Skip to content

Commit

Permalink
adaltas#108 skip_lines_with_empty_values: support space and tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jul 28, 2016
1 parent ab564b8 commit 4f1943c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
8 changes: 7 additions & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions src/index.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Implementation of the [`stream.Transform` API][transform]
this.emit 'error', err
Parser.prototype.__push = (line) ->
return if @options.skip_lines_with_empty_values and line.join('').trim() is ''
row = null
if @options.columns is true
@options.columns = line
Expand Down Expand Up @@ -348,16 +349,7 @@ Implementation of the [`stream.Transform` API][transform]
isRowDelimiter = true
@line.push ''
if isRowDelimiter
if @options.skip_lines_with_empty_values
isValueNotEmpty = false
for line in @line
if line isnt ''
isValueNotEmpty = true
break
if isValueNotEmpty
@__push @line
else
@__push @line
@__push @line
# Some cleanup for the next row
@line = []
i += @options.rowDelimiter?.length
Expand Down
34 changes: 14 additions & 20 deletions test/options.skip_lines_with_empty_values.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,26 @@ describe 'skip_lines_with_empty_values', ->
parse """
ABC,DEF
,
IJK,LMN
,
""", skip_lines_with_empty_values: true, (err, data) ->
return next err if err
data.should.eql [
[ 'ABC', 'DEF' ]
[ 'IJK', 'LMN' ]
]
next()

it 'skip respect parser.read', (next) ->
data = []
parser = parse skip_lines_with_empty_values: true
parser.write """
,,,,,
20322051544,1979,8.8017226E7,ABC,45,2000-01-01
,,,,,
28392898392,1974,8.8392926E7,DEF,23,2050-11-27
,,,,,
"""
parser.on 'readable', ->
while(d = parser.read())
data.push d
parser.on 'error', (err) ->
next err
parser.on 'finish', ->

it 'skip space and tabs', (next) ->
parse """
ABC,DEF
\t , \t
IJK,LMN
\t , \t
""", skip_lines_with_empty_values: true, (err, data) ->
return next err if err
data.should.eql [
['20322051544', '1979', '8.8017226E7', 'ABC', '45', '2000-01-01']
['28392898392', '1974', '8.8392926E7', 'DEF', '23', '2050-11-27']
[ 'ABC', 'DEF' ]
[ 'IJK', 'LMN' ]
]
next()
parser.end()

0 comments on commit 4f1943c

Please sign in to comment.