Skip to content

Commit

Permalink
BREAKING(csv): make ReadOptions private (#5169)
Browse files Browse the repository at this point in the history
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
  • Loading branch information
kt3k and iuioiua authored Jun 27, 2024
1 parent 7bf534f commit f36ac2b
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 9 deletions.
44 changes: 42 additions & 2 deletions csv/csv_parse_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,52 @@ 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 {@linkcode ParseError} is
* thrown.
*/
fieldsPerRecord?: number;
/**
* If you provide `skipFirstRow: true` and `columns`, the first line will be
* skipped.
Expand Down
50 changes: 43 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,48 @@ 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 {@linkcode ParseError} is
* thrown.
*/
fieldsPerRecord?: number;
/**
* If you provide `skipFirstRow: true` and `columns`, the first line will be
* skipped.
Expand Down

0 comments on commit f36ac2b

Please sign in to comment.