Browse Source

Changed up the parameters to include 'arr' the row data arr after some practical use

pull/898/head
theLAZYmd 4 years ago
parent
commit
c7e45624d5
  1. 5
      docs/docs.html
  2. 4
      papaparse.js
  3. 2
      papaparse.min.js
  4. 2
      tests/test-cases.js

5
docs/docs.html

@ -512,8 +512,9 @@ var csv = Papa.unparse({ @@ -512,8 +512,9 @@ var csv = Papa.unparse({
<td>
A function to apply on each header. Requires <code>header</code> to be <code>true</code>. The function receives the header as its first argument and the index (the column number) as second. When used in conjunction with config.headerLines, the function receives a third and fourth parameter which are:
<ul>
<li>the existing header for that column based on previous lines iteration ('' if no previous lines)</li>
<li>the rowNumber (0 for the first line)</li>
<li><b>arr:</b> the string array of data for that row</li>
<li><b>acc:</b> the existing header for that column based on previous lines iteration ('' if no previous lines)</li>
<li><b>j:</b> the rowNumber (0 for the first line)</li>
</ul>
</td>
</tr>

4
papaparse.js

@ -1181,10 +1181,10 @@ License: MIT @@ -1181,10 +1181,10 @@ License: MIT
return;
var headerLines = _config.headerLines || 1;
function addHeader(j, header, i)
function addHeader(j, header, i, arr)
{
if (isFunction(_config.transformHeader))
header = _config.transformHeader(header, i, _fields[i] || '', j);
header = _config.transformHeader(header, i, arr, _fields[i] || '', j);
_fields[i] = header;
}

2
papaparse.min.js vendored

File diff suppressed because one or more lines are too long

2
tests/test-cases.js

@ -770,7 +770,7 @@ var PARSE_TESTS = [ @@ -770,7 +770,7 @@ var PARSE_TESTS = [
{
description: "Header row is generated from multiple rows when transformheader function is provided and config.headerLines is set",
input: "A,B,C\r\nD,E,F\r\nG,H,I\r\nadg,beh,cfi",
config: { header: true, transformHeader: function(header, i, acc, j) { return acc + (j % 2 ? header.toLowerCase() : header); }, headerLines: 3 },
config: { header: true, transformHeader: function(header, i, arr, acc, j) { return acc + (j % 2 ? header.toLowerCase() : header); }, headerLines: 3 },
expected: {
data: [{"AdG": "adg", "BeH": "beh", "CfI": "cfi"}],
errors: []

Loading…
Cancel
Save