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

BREAKING(csv): make ReadOptions private #5169

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
BREAKING(csv): make ReadOptions private
  • Loading branch information
kt3k committed Jun 27, 2024
commit bac9bd23a08f0758e6def7cc5acaa9bd37b2dff8
43 changes: 41 additions & 2 deletions csv/csv_parse_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,51 @@ import {
type LineReader,
parseRecord,
type ParseResult,
type ReadOptions,
} from "./_io.ts";
import { TextDelimiterStream } from "@std/streams/text-delimiter-stream";

/** Options for {@linkcode CsvParseStream}. */
export interface CsvParseStreamOptions extends ReadOptions {
export interface CsvParseStreamOptions {
/** Character which separates values.
*
* @default {","}
*/
separator?: string;
/** Character to start a comment.
*
* Lines beginning with the comment character without preceding whitespace
* are ignored. With leading whitespace the comment character becomes part of
* the field, even you provide `trimLeadingSpace: true`.
*
* @default {"#"}
*/
comment?: string;
/** Flag to trim the leading space of the value.
*
* This is done even if the field delimiter, `separator`, is white space.
*
* @default {false}
*/
trimLeadingSpace?: boolean;
/**
* Allow unquoted quote in a quoted field or non-double-quoted quotes in
* quoted field.
*
* @default {false}
*/
lazyQuotes?: boolean;
/**
* Enabling checking number of expected fields for each row.
*
* If positive, each record is required to have the given number of fields.
* If === 0, it will be set to the number of fields in the first row, so that
* future rows must have the same field count.
* If negative, no check is made and records may have a variable number of
* fields.
*
* If the wrong number of fields is in a row, a `ParseError` is thrown.
*/
fieldsPerRecord?: number;
/**
* If you provide `skipFirstRow: true` and `columns`, the first line will be
* skipped.
Expand Down
49 changes: 42 additions & 7 deletions csv/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import {
type RecordWithColumn,
} from "./_io.ts";

export {
ParseError,
type ParseResult,
type ReadOptions,
type RecordWithColumn,
};
export { ParseError, type ParseResult, type RecordWithColumn };

const BYTE_ORDER_MARK = "\ufeff";

Expand Down Expand Up @@ -280,7 +275,47 @@ class Parser {
}

/** Options for {@linkcode parse}. */
export interface ParseOptions extends ReadOptions {
export interface ParseOptions {
/** Character which separates values.
*
* @default {","}
*/
separator?: string;
/** Character to start a comment.
*
* Lines beginning with the comment character without preceding whitespace
* are ignored. With leading whitespace the comment character becomes part of
* the field, even you provide `trimLeadingSpace: true`.
*
* @default {"#"}
*/
comment?: string;
/** Flag to trim the leading space of the value.
*
* This is done even if the field delimiter, `separator`, is white space.
*
* @default {false}
*/
trimLeadingSpace?: boolean;
/**
* Allow unquoted quote in a quoted field or non-double-quoted quotes in
* quoted field.
*
* @default {false}
*/
lazyQuotes?: boolean;
/**
* Enabling checking number of expected fields for each row.
*
* If positive, each record is required to have the given number of fields.
* If === 0, it will be set to the number of fields in the first row, so that
* future rows must have the same field count.
* If negative, no check is made and records may have a variable number of
* fields.
*
* If the wrong number of fields is in a row, a `ParseError` is thrown.
*/
fieldsPerRecord?: number;
/**
* If you provide `skipFirstRow: true` and `columns`, the first line will be
* skipped.
Expand Down