Browse Source

Add option to trim whitespace from headers (#491)

Allow developers to trim leading/trailing spaces from headers
pull/496/head
Steve Fisher 7 years ago committed by Sergi Almacellas Abellana
parent
commit
cb68215f70
  1. 10
      papaparse.js
  2. 9
      tests/test-cases.js

10
papaparse.js

@ -990,7 +990,15 @@ @@ -990,7 +990,15 @@
return;
for (var i = 0; needsHeaderRow() && i < _results.data.length; i++)
for (var j = 0; j < _results.data[i].length; j++)
_fields.push(_results.data[i][j]);
{
var header = _results.data[i][j];
if (_config.trimHeaders) {
header = header.trim();
}
_fields.push(header);
}
_results.data.splice(0, 1);
}

9
tests/test-cases.js

@ -713,6 +713,15 @@ var PARSE_TESTS = [ @@ -713,6 +713,15 @@ var PARSE_TESTS = [
errors: []
}
},
{
description: "Header row with whitespace trimmed",
input: ' A , B , C \r\na,b,c',
config: { header: true, trimHeaders: true },
expected: {
data: [{"A": "a", "B": "b", "C": "c"}],
errors: []
}
},
{
description: "Tab delimiter",
input: 'a\tb\tc\r\nd\te\tf',

Loading…
Cancel
Save