Using PapaParse transformHeader to remove whitespace from headers?

99封情书 提交于 2020-05-30 07:53:51

问题


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?


回答1:


This ended up doing the trick:

const config = {
  delimiter: ",",
  header: true,
  dynamicTyping: true,
  transformHeader:function(h) {
    return h.trim();
  }
};


来源:https://stackoverflow.com/questions/56470745/using-papaparse-transformheader-to-remove-whitespace-from-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!