From 173b8869efbe33d3ab2464614b00826b7d9ea5e6 Mon Sep 17 00:00:00 2001 From: David Worms Date: Thu, 22 Nov 2018 22:24:50 +0100 Subject: [PATCH] stream: pass stream options without modification --- CHANGELOG.md | 4 ++++ lib/es5/index.js | 21 +++++++++++++-------- lib/index.js | 10 +++++----- test/api.types.ts | 8 ++++---- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7540a41..66c77d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ New features: * options: accept camelize and underscore forms +Fix: + +* stream: pass stream options without modification + ## Version 4.0.1 Fix: diff --git a/lib/es5/index.js b/lib/es5/index.js index bece5be..854152c 100644 --- a/lib/es5/index.js +++ b/lib/es5/index.js @@ -18,6 +18,10 @@ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } @@ -78,19 +82,20 @@ function (_Transform) { _classCallCheck(this, Parser); - var options = {}; - - for (var opt in opts) { - options[underscore(opt)] = opts[opt]; - } - - options.readableObjectMode = true; - _this = _possibleConstructorReturn(this, _getPrototypeOf(Parser).call(this, options)); // Import default options + _this = _possibleConstructorReturn(this, _getPrototypeOf(Parser).call(this, _objectSpread({}, { + readableObjectMode: true + }, opts))); + var options = {}; // Import default options for (var k in default_options) { if (options[k] === undefined) { options[k] = default_options[k]; } + } // Merge with user options + + + for (var opt in opts) { + options[underscore(opt)] = opts[opt]; } // Normalize option `cast` diff --git a/lib/index.js b/lib/index.js index 0f5682d..822f993 100644 --- a/lib/index.js +++ b/lib/index.js @@ -32,18 +32,18 @@ const space = 32 class Parser extends Transform { constructor(opts = {}){ + super({...{readableObjectMode: true}, ...opts}) const options = {} - for(let opt in opts){ - options[underscore(opt)] = opts[opt] - } - options.readableObjectMode = true - super(options) // Import default options for(let k in default_options){ if(options[k] === undefined){ options[k] = default_options[k] } } + // Merge with user options + for(let opt in opts){ + options[underscore(opt)] = opts[opt] + } // Normalize option `cast` let fnCastField = null if(options.cast === undefined || options.cast === null || options.cast === false || options.cast === ''){ diff --git a/test/api.types.ts b/test/api.types.ts index 474cfb9..bdc04d4 100644 --- a/test/api.types.ts +++ b/test/api.types.ts @@ -14,10 +14,10 @@ describe('API Types', () => { keys.sort().should.eql([ 'cast', 'cast_date', 'columns', 'comment', 'delimiter', 'escape', 'from', 'from_line', 'info', 'ltrim', 'max_record_size', - 'objname', 'quote', 'raw', 'readableObjectMode', - 'record_delimiter', 'relax', 'relax_column_count', - 'rtrim', 'skip_empty_lines', 'skip_lines_with_empty_values', - 'skip_lines_with_error', 'to', 'to_line', 'trim' + 'objname', 'quote', 'raw', 'record_delimiter', + 'relax', 'relax_column_count', 'rtrim', 'skip_empty_lines', + 'skip_lines_with_empty_values', 'skip_lines_with_error', 'to', + 'to_line', 'trim' ]) })