Skip to content

Commit

Permalink
Add docs and tests case for transformHeader with index
Browse files Browse the repository at this point in the history
  • Loading branch information
pokoli committed Jun 24, 2020
1 parent 018f5df commit ce858b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/docs.html
Expand Up @@ -508,7 +508,7 @@ <h5 id="config-details">Config Options</h5>
<code>transformHeader</code>
</td>
<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.<br>
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 as second.<br>
Only available starting with version 5.0.
</td>
</tr>
Expand Down
9 changes: 9 additions & 0 deletions tests/test-cases.js
Expand Up @@ -767,6 +767,15 @@ var PARSE_TESTS = [
errors: []
}
},
{
description: "transformHeader accepts and optional index attribute",
input: 'A,B,C\r\na,b,c',
config: { header: true, transformHeader: function(header, i) { return i % 2 ? header.toLowerCase() : header; } },
expected: {
data: [{"A": "a", "b": "b", "C": "c"}],
errors: []
}
},
{
description: "Line ends with quoted field, first field of next line is empty using headers",
input: 'a,b,"c"\r\nd,e,"f"\r\n,"h","i"\r\n,"k","l"',
Expand Down

0 comments on commit ce858b3

Please sign in to comment.