Browse Source

remove __only & __except support

pull/377/head
vyrak bunleang 8 years ago
parent
commit
1c52325e02
  1. 50
      papaparse.js
  2. 54
      tests/test-cases.js

50
papaparse.js

@ -417,54 +417,20 @@
function DynamicTypingConfig(config) function DynamicTypingConfig(config)
{ {
this._columnConfig = {}; this._config = config;
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));
}
} }
DynamicTypingConfig.prototype.constructor = DynamicTypingConfig; DynamicTypingConfig.prototype.constructor = DynamicTypingConfig;
DynamicTypingConfig.prototype.isIncluded = function(field) 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. */ /** ChunkStreamer is the base prototype for various streamer implementations. */

54
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", description: "Dynamic typing by indices can be determined by function",
input: '001,002,003', input: '001,002,003',
@ -729,33 +702,6 @@ var PARSE_TESTS = [
errors: [] 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", description: "Dynamic typing by headers can be determined by function",
input: 'A_as_int,B,C_as_int\r\n001,002,003', input: 'A_as_int,B,C_as_int\r\n001,002,003',

Loading…
Cancel
Save