From ce858b3c414236e52de05e2d0285e08ef2272e0a Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Wed, 24 Jun 2020 22:26:11 +0200 Subject: [PATCH] Add docs and tests case for transformHeader with index --- docs/docs.html | 2 +- tests/test-cases.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/docs.html b/docs/docs.html index 8d253a1..c4fec01 100644 --- a/docs/docs.html +++ b/docs/docs.html @@ -508,7 +508,7 @@ var csv = Papa.unparse({ transformHeader - A function to apply on each header. Requires header to be true. The function receives the header as its first argument.
+ A function to apply on each header. Requires header to be true. The function receives the header as its first argument and the index as second.
Only available starting with version 5.0. diff --git a/tests/test-cases.js b/tests/test-cases.js index bc0b333..8d15b29 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -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"',