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

Commit

Permalink
feat: enforce usage of columns with columns_duplicates_to_array
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Apr 26, 2021
1 parent f714b89 commit d0e3471
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Please join and contribute:

## Trunk

* feat: enforce usage of columns with columns_duplicates_to_array
* fix: update error message with invalid column type

## Version 4.15.4
Expand Down
2 changes: 2 additions & 0 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ var Parser = /*#__PURE__*/function (_Transform) {
options.columns_duplicates_to_array = false;
} else if (options.columns_duplicates_to_array !== true) {
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'expect an boolean,', "got ".concat(JSON.stringify(options.columns_duplicates_to_array))], options);
} else if (options.columns === false) {
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'the `columns` mode must be activated.'], options);
} // Normalize option `comment`


Expand Down
2 changes: 2 additions & 0 deletions lib/browser/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ var Parser = /*#__PURE__*/function (_Transform) {
options.columns_duplicates_to_array = false;
} else if (options.columns_duplicates_to_array !== true) {
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'expect an boolean,', "got ".concat(JSON.stringify(options.columns_duplicates_to_array))], options);
} else if (options.columns === false) {
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'the `columns` mode must be activated.'], options);
} // Normalize option `comment`


Expand Down
2 changes: 2 additions & 0 deletions lib/es5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ var Parser = /*#__PURE__*/function (_Transform) {
options.columns_duplicates_to_array = false;
} else if (options.columns_duplicates_to_array !== true) {
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'expect an boolean,', "got ".concat(JSON.stringify(options.columns_duplicates_to_array))], options);
} else if (options.columns === false) {
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'the `columns` mode must be activated.'], options);
} // Normalize option `comment`


Expand Down
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class Parser extends Transform {
'expect an boolean,',
`got ${JSON.stringify(options.columns_duplicates_to_array)}`
], options)
}else if(options.columns === false){
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', [
'Invalid option columns_duplicates_to_array:',
'the `columns` mode must be activated.'
], options)
}
// Normalize option `comment`
if(options.comment === undefined || options.comment === null || options.comment === false || options.comment === ''){
Expand Down
11 changes: 10 additions & 1 deletion test/option.columns_duplicates_to_array.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ describe 'Option `columns_duplicates_to_array`', ->
).should.throw
code: 'CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY'
message: [
'Invalid option columns_duplicates_to_array:',
'Invalid option columns_duplicates_to_array:'
'expect an boolean, got "invalid"'
].join ' '

it 'require columns to be active', ->
(->
parse "", columns_duplicates_to_array: true
).should.throw
code: 'CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY'
message: [
'Invalid option columns_duplicates_to_array:'
'the `columns` mode must be activated.'
].join ' '

it 'when false', (next) ->
parse """
Expand Down

0 comments on commit d0e3471

Please sign in to comment.