Browse Source

Add docs and tests case for transformHeader with index

pull/810/head
Sergi Almacellas Abellana 5 years ago
parent
commit
ce858b3c41
  1. 2
      docs/docs.html
  2. 9
      tests/test-cases.js

2
docs/docs.html

@ -508,7 +508,7 @@ var csv = Papa.unparse({
<code>transformHeader</code> <code>transformHeader</code>
</td> </td>
<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. Only available starting with version 5.0.
</td> </td>
</tr> </tr>

9
tests/test-cases.js

@ -767,6 +767,15 @@ var PARSE_TESTS = [
errors: [] 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", 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"', input: 'a,b,"c"\r\nd,e,"f"\r\n,"h","i"\r\n,"k","l"',

Loading…
Cancel
Save