diff --git a/docs/docs.html b/docs/docs.html
index 68f1132..b424c7a 100644
--- a/docs/docs.html
+++ b/docs/docs.html
@@ -340,7 +340,7 @@ var csv = Papa.unparse({
quoteChar: '"',
escapeChar: '"',
header: false,
- trimHeaders: false,
+ transformHeader: undefined,
dynamicTyping: false,
preview: 0,
encoding: "",
@@ -412,10 +412,10 @@ var csv = Papa.unparse({
- trimHeaders
+ transformHeader
|
- If true leading/trailing spaces will be trimed from headers.
+ A function to apply on each header. Requires header to be true . The function receives the header as its first argument.
|
diff --git a/papaparse.js b/papaparse.js
index 8703ec8..ababc70 100755
--- a/papaparse.js
+++ b/papaparse.js
@@ -1151,8 +1151,8 @@ if (!Array.isArray)
{
var header = _results.data[i][j];
- if (_config.trimHeaders) {
- header = header.trim();
+ if (isFunction(_config.transformHeader)) {
+ header = _config.transformHeader(header);
}
_fields.push(header);
diff --git a/tests/test-cases.js b/tests/test-cases.js
index 98509de..bfc1d04 100644
--- a/tests/test-cases.js
+++ b/tests/test-cases.js
@@ -725,11 +725,11 @@ var PARSE_TESTS = [
}
},
{
- description: "Header rows are trimmed when trimHeaders is set",
- input: ' A , B , C \r\na,b ,c',
- config: { header: true, trimHeaders: true },
+ description: "Header rows are transformed when transformHeader function is provided",
+ input: 'A,B,C\r\na,b,c',
+ config: { header: true, transformHeader: function(header) { return header.toLowerCase(); } },
expected: {
- data: [{"A": "a", "B": "b ", "C": "c"}],
+ data: [{"a": "a", "b": "b", "c": "c"}],
errors: []
}
},