Skip to content

Commit ce7c8cf

Browse files
committed
add tests from papaparse + extract bytes from options in parseChunk
1 parent bb924c7 commit ce7c8cf

6 files changed

Lines changed: 775 additions & 46 deletions

File tree

src/chunk.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { testEmptyLine } from './utils'
99

1010
/**
1111
* Parses a chunk of bytes into CSV data.
12+
* @param bytes The chunk of bytes to parse.
1213
* @param options Options for parsing the chunk.
13-
* @param options.bytes The chunk of bytes to parse.
1414
* @param options.delimiter The delimiter used in the CSV data. Defaults to ','.
1515
* @param options.newline The newline used in the CSV data. Defaults to '\n'.
1616
* @param options.quoteChar The quote character used in the CSV data. Defaults to '"'.
@@ -22,27 +22,26 @@ import { testEmptyLine } from './utils'
2222
* @yields Parsed data and metadata.
2323
* @returns A generator yielding parsed data and metadata.
2424
*/
25-
export function* parseChunk({
26-
bytes,
27-
delimiter,
28-
newline,
29-
quoteChar,
30-
escapeChar,
31-
comments,
32-
delimitersToGuess,
33-
skipEmptyLines,
34-
ignoreLastRow,
35-
}: {
36-
bytes: Uint8Array
37-
delimiter?: string
38-
newline?: string
39-
quoteChar?: string
40-
escapeChar?: string
41-
comments?: boolean | string
42-
delimitersToGuess?: string[]
43-
skipEmptyLines?: boolean | 'greedy'
44-
ignoreLastRow?: boolean
45-
}): Generator<ParseResult, void, unknown> {
25+
export function* parseChunk(bytes: Uint8Array,
26+
{
27+
delimiter,
28+
newline,
29+
quoteChar,
30+
escapeChar,
31+
comments,
32+
delimitersToGuess,
33+
skipEmptyLines,
34+
ignoreLastRow,
35+
}: {
36+
delimiter?: string
37+
newline?: string
38+
quoteChar?: string
39+
escapeChar?: string
40+
comments?: boolean | string
41+
delimitersToGuess?: string[]
42+
skipEmptyLines?: boolean | 'greedy'
43+
ignoreLastRow?: boolean
44+
} = {}): Generator<ParseResult, void, unknown> {
4645
const decoder = new TextDecoder('utf-8')
4746
const input = decoder.decode(bytes)
4847

src/url.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export async function* parseUrl(
7171
}
7272

7373
let consumedBytes = 0
74-
for (const result of (options?.parseChunk ?? parseChunk)({
75-
bytes,
74+
for (const result of (options?.parseChunk ?? parseChunk)(bytes, {
7675
ignoreLastRow: true, // the remaining bytes may not contain a full last row
7776
})) {
7877
consumedBytes += result.meta.byteCount

0 commit comments

Comments
 (0)