diff --git a/CHANGELOG.md b/CHANGELOG.md index b269ccc..aaf2ec4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Enhancements: +* relax_column_count: validation refinements * relax: validation refinements * delimiter: validation refinements * max_record_size: validation refinements diff --git a/lib/es5/index.js b/lib/es5/index.js index 5164625..5375cb7 100644 --- a/lib/es5/index.js +++ b/lib/es5/index.js @@ -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, @@ -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` diff --git a/lib/index.js b/lib/index.js index c7b9e2b..3705a0f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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, @@ -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 diff --git a/test/option.relax_column_count.coffee b/test/option.relax_column_count.coffee index 7795a06..6942287 100644 --- a/test/option.relax_column_count.coffee +++ b/test/option.relax_column_count.coffee @@ -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 """