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

Commit d0e3471

Browse files
committed
feat: enforce usage of columns with columns_duplicates_to_array
1 parent f714b89 commit d0e3471

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Please join and contribute:
1919

2020
## Trunk
2121

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

2425
## Version 4.15.4

lib/browser/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ var Parser = /*#__PURE__*/function (_Transform) {
293293
options.columns_duplicates_to_array = false;
294294
} else if (options.columns_duplicates_to_array !== true) {
295295
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);
296+
} else if (options.columns === false) {
297+
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'the `columns` mode must be activated.'], options);
296298
} // Normalize option `comment`
297299

298300

lib/browser/sync.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ var Parser = /*#__PURE__*/function (_Transform) {
293293
options.columns_duplicates_to_array = false;
294294
} else if (options.columns_duplicates_to_array !== true) {
295295
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);
296+
} else if (options.columns === false) {
297+
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'the `columns` mode must be activated.'], options);
296298
} // Normalize option `comment`
297299

298300

lib/es5/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ var Parser = /*#__PURE__*/function (_Transform) {
185185
options.columns_duplicates_to_array = false;
186186
} else if (options.columns_duplicates_to_array !== true) {
187187
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);
188+
} else if (options.columns === false) {
189+
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', ['Invalid option columns_duplicates_to_array:', 'the `columns` mode must be activated.'], options);
188190
} // Normalize option `comment`
189191

190192

lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ class Parser extends Transform {
120120
'expect an boolean,',
121121
`got ${JSON.stringify(options.columns_duplicates_to_array)}`
122122
], options)
123+
}else if(options.columns === false){
124+
throw new CsvError('CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY', [
125+
'Invalid option columns_duplicates_to_array:',
126+
'the `columns` mode must be activated.'
127+
], options)
123128
}
124129
// Normalize option `comment`
125130
if(options.comment === undefined || options.comment === null || options.comment === false || options.comment === ''){

test/option.columns_duplicates_to_array.coffee

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@ describe 'Option `columns_duplicates_to_array`', ->
1010
).should.throw
1111
code: 'CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY'
1212
message: [
13-
'Invalid option columns_duplicates_to_array:',
13+
'Invalid option columns_duplicates_to_array:'
1414
'expect an boolean, got "invalid"'
1515
].join ' '
1616

17+
it 'require columns to be active', ->
18+
(->
19+
parse "", columns_duplicates_to_array: true
20+
).should.throw
21+
code: 'CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY'
22+
message: [
23+
'Invalid option columns_duplicates_to_array:'
24+
'the `columns` mode must be activated.'
25+
].join ' '
1726

1827
it 'when false', (next) ->
1928
parse """

0 commit comments

Comments
 (0)