Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transformHeader returns function instead of string: trim is not a function #1006

Open
bettysteger opened this issue Jun 21, 2023 · 8 comments

Comments

@bettysteger
Copy link

In version 5.3.2 this works:

transformHeader: function(header) { return header.trim(); }

In version 5.4.1 i got the following error because header is sometimes a function, sometimes a string, but the 1st param should always be a string?!

TypeError
header.trim is not a function. (In 'header.trim()', 'header.trim' is undefined)
@kraighamady
Copy link

You can try declaring the function elsewhere? I was able to make it work with an arrow function instead of a declaration.

example:

transformHeader: (header) => { return header.trim() },

Hopefully that works for you?

@bettysteger
Copy link
Author

@kraighamady this makes no difference

@kraighamady
Copy link

kraighamady commented Feb 6, 2024

@bettysteger Two thing I just noticed. With a type error you are using typescript? if so, you can do what I did which is explicitly type the header param in the function:

transformHeader: (header: string) => { return header.trim() },

The issue is that your typescript checker doesn't know that header is a string so cannot be sure that the trim() function is by default in the prototype. So the error is coming from your function and not papaparse's typing of the config object. I checked and they have the property transformHeader accepting any as a value.

I am not sure why you can get away without typing in the function in the latest version version the previous release.

@bettysteger
Copy link
Author

@kraighamady unfortunately I am not using typescript for this project

@kraighamady
Copy link

I'd have to see more of the code and the values in your csv. You could try forcing the variable to string:

String(header).trim()

@bettysteger
Copy link
Author

@kraighamady but why do i need that now? in v5.3.2 it works, because it is always a string, and somehow in v5.4.1 it seems that the function is called twice: #1029

@kraighamady
Copy link

Not sure. I am having the duplicate call issue as well. I was just offering a workaround in case you were blocked. I am just a user of the package and not involved in the development of the tool.

@bettysteger
Copy link
Author

@kraighamady oh thanks! no i just keep v5.3.2 for now :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants