-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
trim config option? #241
Comments
No, just do it yourself. :) str.trim() |
Doing it yourself is actually pretty unhandy. You have a neat option to output the data as dicts with field: value. If field always contains a space in the beginning (e.g. " password" or " username") it's something not so easy to correct. I am writing this because I was about to use papa to parse files that looks like: username, email, password |
Why is it not so easy to correct? Instead of But you have to assume that the password doesn't have spaces on the edge. Could be a dangerous assumption. That's why I leave it up to the user to do. I'm not gonna go there. |
I think he's saying he would have to do results.data[i][" password"], which is a little gross. |
Oh, I see. Unfortunately, the CSV spec specifically says: "Spaces are considered part of a field and should not be ignored." - if your CSV files are created with spaces after the commas, then the spaces are errors in the input and the generator needs to be fixed. |
Well, true, the spec says that, but you get all kind of wrong csv files all the time |
While I think there should be an option for PapaParse so that you can enable trimming on the input, this problems is not too difficult to solve on your own: Just pre-process you data with the following regex
|
I honestly think this should be reconsidered... a. CSV files coming out of Excel quite often have superfluous spaces everywhere. Yes, that's valid for the format, but these are generally unintentional and break things further downstream. b. The "preprocess with regex" approach suggested by @KamalAman modifies the input data, which is bad because it makes troubleshooting downstream errors more difficult. c. Having to I'm currently trying to use the |
I used this guys trimObj() to solve this issue in my completeFn. Worked perfectly. |
I'm using Papa Parse (well Baby Parse for Node) to read local files from an upload folder. I had an issue with a space in front of a field that threw my app off. I get the data in Node using:
To trim the white space and delete empty fields from each row object, I use this:
This returns the desired results for me before processing the data and saving it to MongoDB. |
Hi @rsand27, latests paparse version can be run also on Node, so I will recomend using PapaParse instead of BabyParse on Node. If this does not work, please open a new issue. |
What if you want to trim the parsed header? I just had a prepended |
@amit777 if you set |
In case it helps anyone else, 4x version does have |
Has anybody been able to get this to work for the data values, not just the header? When I have spaces after the commas, the values have a space and double quotes. I'm using version 5.3.0. For example, even with dynamicTyping, this CSV: "Australia", "AU", "AUS", "36", "-27", "133" Gives me these values:
|
here is code . |
I do not know if this is relevant anymore, but there is 'transform' function that you can use in config which is executed on every item.
P.S. I do not know how it will handle larger datasets and will it be slow. |
Hi, is there a simple way to trim whitespace from the ends of the fieldname as well as data values? This library has everything that I want so I'm guessing I'm just missing something simple.
thanks!
The text was updated successfully, but these errors were encountered: