adaltas / adaltas/node-csv

Support multiple quote characters when parsing

Open
#431 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
4.3k
Forks
299
Avg merge
16h 19m
Merged PRs (30d)
1

Description

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 https://github.com/adaltas/node-csv/issues/400. Perhaps automated detection is a sensible option.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the parser's quote option handling and existing quote-related tests. Use the draft example as the behavioral target, then run the parser test suite to verify mixed single- and double-quoted fields while preserving existing quote behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
data-engineering
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.