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

Support multiple quote characters when parsing #431

Open
loucadufault opened this issue May 22, 2024 · 3 comments
Open

Support multiple quote characters when parsing #431

loucadufault opened this issue May 22, 2024 · 3 comments

Comments

@loucadufault
Copy link

Summary

The library should be able to parse CSVs while considering multiple different potential quote character used for each value independently. E.g. allow a CSV mixing both single quote and double quotes.

Motivation

Use cases where CSVs mix values ported over from other formats (e.g. literals in a programming language) which enclose values in single quotes, and manually input. Reconciling the two quote styles would enable parsing the CSV regardless of which (if any) quote character was used.

Alternative

Regex to strip replace single quotes with double quotes via a utility, though this will break quotes in values.

Draft

Let the quote option take in an array of characters, and consider each when parsing the values.

Example unit test:

const records = parse(`
a,"b",'c'
'd',e,"f"
`.trim(), {
  quote: ['"', '\''],
});

assert.deepStrictEqual(
  records, [
    ['a', 'b', 'c'],
    ['d', 'e', 'f']
  ]
);

Additional context

Similar to #400. Perhaps automated detection is a sensible option.

@wdavidw
Copy link
Member

wdavidw commented May 23, 2024

We do it for some other options, not too hard to implement so no problem to go this direction.

@loucadufault
Copy link
Author

I can propose a PR, seems the changes would be fairly localized. Lmk if that would be any help

@wdavidw
Copy link
Member

wdavidw commented May 24, 2024

Agreed, please propose a PR. (not sure what Lmk stands for)

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

No branches or pull requests

2 participants