|
|
|
@ -205,6 +205,8 @@
@@ -205,6 +205,8 @@
|
|
|
|
|
} |
|
|
|
|
_config.dynamicTyping = dynamicTyping; |
|
|
|
|
|
|
|
|
|
_config.transform = isFunction(_config.transform) ? _config.transform : false; |
|
|
|
|
|
|
|
|
|
if (_config.worker && Papa.WORKERS_SUPPORTED) |
|
|
|
|
{ |
|
|
|
|
var w = newWorker(); |
|
|
|
@ -961,6 +963,7 @@
@@ -961,6 +963,7 @@
|
|
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
var _stepCounter = 0; // Number of times step was called (number of rows parsed)
|
|
|
|
|
var _rowCounter = 0; // Number of rows that have been parsed so far
|
|
|
|
|
var _input; // The input being parsed
|
|
|
|
|
var _parser; // The core parser being used
|
|
|
|
|
var _paused = false; // Whether we are paused or not
|
|
|
|
@ -1090,7 +1093,7 @@
@@ -1090,7 +1093,7 @@
|
|
|
|
|
if (needsHeaderRow()) |
|
|
|
|
fillHeaderFields(); |
|
|
|
|
|
|
|
|
|
return applyHeaderAndDynamicTyping(); |
|
|
|
|
return applyHeaderAndDynamicTypingAndTransformation(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function needsHeaderRow() |
|
|
|
@ -1142,9 +1145,9 @@
@@ -1142,9 +1145,9 @@
|
|
|
|
|
return value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function applyHeaderAndDynamicTyping() |
|
|
|
|
function applyHeaderAndDynamicTypingAndTransformation() |
|
|
|
|
{ |
|
|
|
|
if (!_results || (!_config.header && !_config.dynamicTyping)) |
|
|
|
|
if (!_results || (!_config.header && !_config.dynamicTyping && !_config.transform)) |
|
|
|
|
return _results; |
|
|
|
|
|
|
|
|
|
for (var i = 0; i < _results.data.length; i++) |
|
|
|
@ -1160,6 +1163,9 @@
@@ -1160,6 +1163,9 @@
|
|
|
|
|
if (_config.header) |
|
|
|
|
field = j >= _fields.length ? '__parsed_extra' : _fields[j]; |
|
|
|
|
|
|
|
|
|
if (_config.transform) |
|
|
|
|
value = _config.transform(value,field); |
|
|
|
|
|
|
|
|
|
value = parseDynamic(field, value); |
|
|
|
|
|
|
|
|
|
if (field === '__parsed_extra') |
|
|
|
@ -1176,14 +1182,16 @@
@@ -1176,14 +1182,16 @@
|
|
|
|
|
if (_config.header) |
|
|
|
|
{ |
|
|
|
|
if (j > _fields.length) |
|
|
|
|
addError('FieldMismatch', 'TooManyFields', 'Too many fields: expected ' + _fields.length + ' fields but parsed ' + j, i); |
|
|
|
|
addError('FieldMismatch', 'TooManyFields', 'Too many fields: expected ' + _fields.length + ' fields but parsed ' + j, _rowCounter + i); |
|
|
|
|
else if (j < _fields.length) |
|
|
|
|
addError('FieldMismatch', 'TooFewFields', 'Too few fields: expected ' + _fields.length + ' fields but parsed ' + j, i); |
|
|
|
|
addError('FieldMismatch', 'TooFewFields', 'Too few fields: expected ' + _fields.length + ' fields but parsed ' + j, _rowCounter + i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_config.header && _results.meta) |
|
|
|
|
_results.meta.fields = _fields; |
|
|
|
|
|
|
|
|
|
_rowCounter += _results.data.length; |
|
|
|
|
return _results; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|