From 1c52325e02392e6d23e9a07d138678347cfeb099 Mon Sep 17 00:00:00 2001 From: vyrak bunleang Date: Fri, 7 Apr 2017 12:07:43 -0600 Subject: [PATCH] remove __only & __except support --- papaparse.js | 50 +++++++---------------------------------- tests/test-cases.js | 54 --------------------------------------------- 2 files changed, 8 insertions(+), 96 deletions(-) diff --git a/papaparse.js b/papaparse.js index 068d331..61ca896 100644 --- a/papaparse.js +++ b/papaparse.js @@ -417,54 +417,20 @@ function DynamicTypingConfig(config) { - this._columnConfig = {}; - this._isAllDynamic = false; - this._isBlackListOnly = true; - - if (config === true) - { - this._isAllDynamic = true; - return; - } - else if (typeof config === 'function') - { - this._isIncluded = config; - } - else if (!config) - { - return; - } - - if (config.__only instanceof Array) - { - this._isBlackListOnly = false; - config.__only.forEach(function(field) - { - this._columnConfig[field] = true; - }.bind(this)); - } - else - { - this._isBlackListOnly = !!config.__except; - this._columnConfig = config; - } - - if (config.__except instanceof Array) - { - config.__except.forEach(function(field) - { - this._columnConfig[field] = false; - }.bind(this)); - } + this._config = config; } DynamicTypingConfig.prototype.constructor = DynamicTypingConfig; DynamicTypingConfig.prototype.isIncluded = function(field) { - if (typeof this._isIncluded === 'function') + if (typeof this._config === 'function') + { + return this._config(field); + } + if (typeof this._config === 'object') { - return this._isIncluded(field); + return this._config[field] === true; } - return this._isAllDynamic || this._columnConfig[field] === true || (this._isBlackListOnly && this._columnConfig[field] !== false) + return !!this._config; }; /** ChunkStreamer is the base prototype for various streamer implementations. */ diff --git a/tests/test-cases.js b/tests/test-cases.js index 9cbabd8..f9e93ea 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -693,33 +693,6 @@ var PARSE_TESTS = [ }] } }, - { - description: "Dynamic typing can be applied to `__only` indices", - input: '001,002,003', - config: { dynamicTyping: { __only: [1] } }, - expected: { - data: [["001", 2, "003"]], - errors: [] - } - }, - { - description: "Dynamic typing can be applied to all indices and not `__except` indices", - input: '001,002,003', - config: { dynamicTyping: { __except: [1] } }, - expected: { - data: [[1, "002", 3]], - errors: [] - } - }, - { - description: "Dynamic typing can be applied to `__only` indices and not `__except` indices", - input: '001,002,003', - config: { dynamicTyping: { __only: [1, 2], __except: [1] } }, - expected: { - data: [["001", "002", 3]], - errors: [] - } - }, { description: "Dynamic typing by indices can be determined by function", input: '001,002,003', @@ -729,33 +702,6 @@ var PARSE_TESTS = [ errors: [] } }, - { - description: "Dynamic typing can be applied to `__only` headers", - input: 'A,B,C\r\n001,002,003', - config: { header: true, dynamicTyping: { __only: ['B'] } }, - expected: { - data: [{"A": "001", "B": 2, "C": "003"}], - errors: [] - } - }, - { - description: "Dynamic typing can be applied to all headers and not `__except` headers", - input: 'A,B,C\r\n001,002,003', - config: { header: true, dynamicTyping: { __except: ['B'] } }, - expected: { - data: [{"A": 1, "B": "002", "C": 3}], - errors: [] - } - }, - { - description: "Dynamic typing can be applied to `__only` headers and not `__except` headers", - input: 'A,B,C\r\n001,002,003', - config: { header: true, dynamicTyping: { __only: ['B', 'C'], __except: ['B'] } }, - expected: { - data: [{"A": "001", "B": "002", "C": 3}], - errors: [] - } - }, { description: "Dynamic typing by headers can be determined by function", input: 'A_as_int,B,C_as_int\r\n001,002,003',