Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PapaParse transformHeader to remove whitespace from headers?

If we have a CSV file like this:

`firstName, lastName
 Jim, Carrey
 Stephen, Colbert`

Papaparse will output the dynamically typed result like this:

       {firstName: 'Jim',
       ' lastName': '30000'}

In order to just get {firstName: 'Jim', lastName...} PapaParse 5.0.0 has a transformHeaders option, but there's no documentation on how to achieve this result yet.

Anyone have a transformHeader snippet that does this?

like image 891
Ole Avatar asked Jun 08 '26 08:06

Ole


1 Answers

This ended up doing the trick:

const config = {
  delimiter: ",",
  header: true,
  dynamicTyping: true,
  transformHeader:function(h) {
    return h.trim();
  }
};
like image 126
Ole Avatar answered Jun 10 '26 21:06

Ole