Skip to content

Commit ce858b3

Browse files
author
Sergi Almacellas Abellana
committed
Add docs and tests case for transformHeader with index
1 parent 018f5df commit ce858b3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

docs/docs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ <h5 id="config-details">Config Options</h5>
508508
<code>transformHeader</code>
509509
</td>
510510
<td>
511-
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>
511+
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>
512512
Only available starting with version 5.0.
513513
</td>
514514
</tr>

tests/test-cases.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,15 @@ var PARSE_TESTS = [
767767
errors: []
768768
}
769769
},
770+
{
771+
description: "transformHeader accepts and optional index attribute",
772+
input: 'A,B,C\r\na,b,c',
773+
config: { header: true, transformHeader: function(header, i) { return i % 2 ? header.toLowerCase() : header; } },
774+
expected: {
775+
data: [{"A": "a", "b": "b", "C": "c"}],
776+
errors: []
777+
}
778+
},
770779
{
771780
description: "Line ends with quoted field, first field of next line is empty using headers",
772781
input: 'a,b,"c"\r\nd,e,"f"\r\n,"h","i"\r\n,"k","l"',

0 commit comments

Comments
 (0)