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

[encoding] add csv parse #458

Merged
merged 11 commits into from
May 30, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
fix parameters
  • Loading branch information
zekth committed May 30, 2019
commit e05684a9dec9297e50122ab725ff4babadeb4cca
12 changes: 5 additions & 7 deletions encoding/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export class ParseError extends Error {
}

export interface ParseOptions {
comma: string;
comma?: string;
comment?: string;
trimLeadingSpace: boolean;
trimLeadingSpace?: boolean;
lazyQuotes?: boolean;
fieldsPerRecord?: number;
}

function chkOptions(opt: ParseOptions): void {
if (
INVALID_RUNE.includes(opt.comma) ||
INVALID_RUNE.includes(opt.comma!) ||
INVALID_RUNE.includes(opt.comment!) ||
opt.comma === opt.comment
) {
Expand Down Expand Up @@ -69,7 +69,7 @@ export async function read(
return [];
}

result = line.split(opt.comma);
result = line.split(opt.comma!);

let quoteError = false;
result = result.map(
Expand Down Expand Up @@ -179,9 +179,7 @@ export interface ExtendedParseOptions extends ParseOptions {
export async function parse(
input: string | BufReader,
opt: ExtendedParseOptions = {
header: false,
comma: ",",
trimLeadingSpace: false
header: false
}
): Promise<unknown[]> {
let r: string[][];
Expand Down
4 changes: 1 addition & 3 deletions encoding/csv_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,7 @@ for (const testCase of parseTestCases) {
async fn(): Promise<void> {
const r = await parse(testCase.in, {
header: testCase.header,
parse: testCase.parse,
comma: ",",
trimLeadingSpace: false
parse: testCase.parse
});
assertEquals(r, testCase.result);
}
Expand Down