-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement https://github.com/mholt/PapaParse/issues/612 #898
base: master
Are you sure you want to change the base?
Changes from all commits
c0acd22
c7e4562
417982c
ac6f191
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1180,24 +1180,26 @@ License: MIT | |
if (!_results) | ||
return; | ||
|
||
function addHeader(header, i) | ||
var headerLines = _config.headerLines || 1; | ||
function addHeader(j, header, i, arr) | ||
{ | ||
if (isFunction(_config.transformHeader)) | ||
header = _config.transformHeader(header, i); | ||
header = _config.transformHeader(header, i, arr, _fields[i] || '', j); | ||
|
||
_fields.push(header); | ||
_fields[i] = header; | ||
} | ||
|
||
if (Array.isArray(_results.data[0])) | ||
{ | ||
for (var i = 0; needsHeaderRow() && i < _results.data.length; i++) | ||
_results.data[i].forEach(addHeader); | ||
|
||
_results.data.splice(0, 1); | ||
for (var j = 0; j < Math.min(headerLines, _results.data.length); j++) | ||
{ | ||
// A function which takes two arguments (header, i) where j is set by the fact it is called in this loop. It then calls addHeader() with all three arguments | ||
_results.data[j].forEach(addHeader.bind(null, j)); | ||
} | ||
_results.data.splice(0, headerLines); | ||
} | ||
// if _results.data[0] is not an array, we are in a step where _results.data is the row. | ||
else | ||
_results.data.forEach(addHeader); | ||
_results.data.forEach(addHeader.bind(null, 0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is bind required? Could we just ignore make the arguments at the end and optional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bind is required because we're trying to parse a function into the .forEach() method, and unfortunately we have |
||
} | ||
|
||
function shouldApplyDynamicTyping(field) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep that this is only availalbe on the version 5.0
I also plan to do a minor version for the parameter. So the new parameter structure should be only available on 5.4+ versions. That should be noted too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved with ac6f191