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

Commit

Permalink
relax_column_count: handle records with more columns
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 19, 2018
1 parent ffed6c7 commit 8a5b1d1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,12 @@

# Changelog

## Trunk

Fix:

* relax_column_count: handle records with more columns

## Version 4.0.0

This is a complete rewrite based with a Buffer implementation. There are no major breaking changes but it introduces multiple minor breaking changes:
Expand Down
2 changes: 1 addition & 1 deletion lib/es5/index.js
Expand Up @@ -625,7 +625,7 @@ function (_Transform) {
var obj = {}; // Transform record array to an object

for (var i in record) {
if (columns[i].disabled) continue;
if (columns[i] === undefined || columns[i].disabled) continue;
obj[columns[i].name] = record[i];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -454,7 +454,7 @@ class Parser extends Transform {
const obj = {}
// Transform record array to an object
for(let i in record){
if(columns[i].disabled) continue
if(columns[i] === undefined || columns[i].disabled) continue
obj[columns[i].name] = record[i]
}
const {objname} = this.options
Expand Down
13 changes: 12 additions & 1 deletion test/options.relax_column_count.coffee
Expand Up @@ -33,7 +33,7 @@ describe 'options relax_column_count', ->
] unless err
next err

it 'with column', (next) ->
it 'with columns bigger than records', (next) ->
parse """
1,2,3
4,5
Expand All @@ -44,6 +44,17 @@ describe 'options relax_column_count', ->
] unless err
next err

it 'with columns smaller than records', (next) ->
parse """
1,2,3,4
5,6,7
""", columns: ['a','b','c'], relax_column_count: true, (err, data) ->
data.should.eql [
{ a: '1', b: '2', c: '3' }
{ a: '5', b: '6', c: '7'}
] unless err
next err

it 'with columns and from, doesnt break count and relying options like from', (next) ->
parse """
1,2,3
Expand Down

0 comments on commit 8a5b1d1

Please sign in to comment.