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

Commit

Permalink
relax: validation refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Dec 28, 2018
1 parent d80ac7d commit 3e9cd16
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@

Enhancements:

* relax: validation refinements
* delimiter: validation refinements
* max_record_size: validation refinements

Expand Down
11 changes: 9 additions & 2 deletions 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: false,
relax_column_count: false,
skip_empty_lines: false,
skip_lines_with_empty_values: false,
Expand Down Expand Up @@ -237,7 +236,15 @@ function (_Transform) {
}

return rd;
}); // Normalize options `trim`, `ltrim` and `rtrim`
}); // Normalize option `relax`

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


if (options.trim === true && options.ltrim !== false) {
options.ltrim = true;
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: false,
relax_column_count: false,
skip_empty_lines: false,
skip_lines_with_empty_values: false,
Expand Down Expand Up @@ -168,6 +167,14 @@ class Parser extends Transform {
}
return rd
})
// Normalize option `relax`
if(typeof options.relax === 'boolean'){
// Great, nothing to do
}else if(options.relax === undefined || options.relax === null){
options.relax = false
}else{
throw new Error(`Invalid Option: relax must be a boolean, got ${JSON.stringify(options.relax)}`)
}
// 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.coffee
Expand Up @@ -2,6 +2,18 @@
parse = require '../lib'

describe 'Option `relax`', ->

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

it 'true with invalid quotes in the middle', (next) ->
# try with relax true
Expand Down

0 comments on commit 3e9cd16

Please sign in to comment.