Repository navigation
Conversation
The `quote` option now accepts an array of characters, so a single input can mix fields quoted with different characters, for example double and single quotes. The option is normalized to an array of buffers, the same way the `delimiter` option already is. A quoted field is closed by the quote which opened it, so the other quote characters are kept as regular content inside the field. Escaping still only applies to the quote in use, and the streaming parser buffers enough bytes for the longest configured quote to be matched across chunks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #431.
quoteaccepts an array of characters, so a single input can mix fields quoted with different characters:Changes:
normalize_optionsnormalizesquoteto an array of buffers, the shapedelimiteralready uses.quote: '"',quote: Buffer.from('"')andquote: ['"', "'"]all work, andquote: []behaves likequote: false."a'b"keeps the single quote and'a"b'keeps the double quote. Escaping still applies to the quote in use.__needMoreDataandstate.needMoreDataSizeuse the longest configured quote, so multi character quotes split across chunks are still matched.quoteJSDoc inlib/options.d.tsdocuments the array input. The website documentation is published from the separate node-csv-docs repository, so it is not part of this diff.Tests in
packages/csv-parse/test/option.quote.tscover the mixed input above, writes of one character at a time, multi character quotes, the other quote inside a field,relax_quotes, fields containing delimiters, and the unclosed quote error. Thequotenormalization assertions were updated to the array shape.Verification, run in
packages/csv-parse:npx tsc --noEmit: no errors.npx mocha "test/**/*.{js,ts}" --ignore test/samples.js: 568 passing, 2 pending.test/samples.jsis ignored because it resolvesimport.meta.urlwithpath.resolveand fails on Windows paths with or without this change.npx eslinton the changed files: clean.packages/csv,packages/csv-stringifyandpackages/stream-transform: type check and tests pass.AI was used to write this code.