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: validation refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Dec 28, 2018
1 parent 3e9cd16 commit 10e706b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@

Enhancements:

* relax_column_count: validation refinements
* relax: validation refinements
* delimiter: validation refinements
* max_record_size: validation refinements
Expand Down
9 changes: 8 additions & 1 deletion lib/es5/index.js
Expand Up @@ -55,7 +55,6 @@ var default_options = {
from_line: 1,
objname: undefined,
// TODO create a max_comment_size
relax_column_count: false,
skip_empty_lines: false,
skip_lines_with_empty_values: false,
skip_lines_with_error: false,
Expand Down Expand Up @@ -243,6 +242,14 @@ function (_Transform) {
options.relax = false;
} else {
throw new Error("Invalid Option: relax must be a boolean, got ".concat(JSON.stringify(options.relax)));
} // Normalize option `relax_column_count`


if (typeof options.relax_column_count === 'boolean') {// Great, nothing to do
} else if (options.relax_column_count === undefined || options.relax_column_count === null) {
options.relax_column_count = false;
} else {
throw new Error("Invalid Option: relax_column_count must be a boolean, got ".concat(JSON.stringify(options.relax_column_count)));
} // Normalize options `trim`, `ltrim` and `rtrim`


Expand Down
9 changes: 8 additions & 1 deletion lib/index.js
Expand Up @@ -15,7 +15,6 @@ const default_options = {
from_line: 1,
objname: undefined,
// TODO create a max_comment_size
relax_column_count: false,
skip_empty_lines: false,
skip_lines_with_empty_values: false,
skip_lines_with_error: false,
Expand Down Expand Up @@ -175,6 +174,14 @@ class Parser extends Transform {
}else{
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`)
}
// Normalize option `relax_column_count`
if(typeof options.relax_column_count === 'boolean'){
// Great, nothing to do
}else if(options.relax_column_count === undefined || options.relax_column_count === null){
options.relax_column_count = false
}else{
throw new Error(`Invalid Option: relax_column_count must be a boolean, got ${JSON.stringify(options.relax_column_count)}`)
}
// Normalize options `trim`, `ltrim` and `rtrim`
if(options.trim === true && options.ltrim !== false){
options.ltrim = true
Expand Down
12 changes: 12 additions & 0 deletions test/option.relax_column_count.coffee
Expand Up @@ -2,6 +2,18 @@
parse = require '../lib'

describe 'Option `relax_column_count`', ->

it 'validation', ->
parse '', relax_column_count: true, (->)
parse '', relax_column_count: false, (->)
parse '', relax_column_count: null, (->)
parse '', relax_column_count: undefined, (->)
(->
parse '', relax_column_count: 1, (->)
).should.throw 'Invalid Option: relax_column_count must be a boolean, got 1'
(->
parse '', relax_column_count: 'oh no', (->)
).should.throw 'Invalid Option: relax_column_count must be a boolean, got "oh no"'

it 'throw error by default', (next) ->
parse """
Expand Down

0 comments on commit 10e706b

Please sign in to comment.