最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using PapaParse transformHeader to remove whitespace from headers? - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Jun 6, 2019 at 4:02 OleOle 47k68 gold badges237 silver badges441 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

This ended up doing the trick:

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

评论列表(0)

  1. 暂无评论