-
Notifications
You must be signed in to change notification settings - Fork 19
Header fields aren't trimmed when results returned as object #65
Copy link
Copy link
Closed
Description
I ran into a bank that (stupidly) produced a CSV whose header fields had spaces around them. Since these fields were not trimmed, the object keys reflected these senseless spaces. For example:
Date, Description, Amount
2022-01-01,"My description",55
2022-05-01,"Another description",23.44Current State
Using the current code, the above produced the following results:
console.log(CSV.parse(csvStr), { output: "objects" });
[
{
"Date": "2022-01-01",
" Description": "My description",
" Amount": "55",
},
{
"Date": "2022-05-01",
" Description": "Another description",
" Amount": "23.44",
},
]Expected Result
If we've asked for objects, we should trim header fields for those objects. However, we should NOT trim any row data, including the first row if we've requested tuples (rather than objects).
Using the above example, our expected return values should be the following:
// Objects
console.log(CSV.parse(csvStr), { output: "objects" });
[
{
"Date": "2022-01-01",
"Description": "My description",
"Amount": "55",
},
{
"Date": "2022-05-01",
"Description": "Another description",
"Amount": "23.44",
},
]
// Tuples
console.log(CSV.parse(csvStr), { output: "tuples" });
[
[ "Date", " Description", " Amount" ],
[ "2022-01-01", "My description", "55" ],
[ "2022-05-01", "Another description", "23.44" ],
]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels