Class CsvParseStream<T>
Type Parameters
- const T extends CsvParseStreamOptions | undefined = undefined
The type of options for the stream.
Index
Constructors
Accessors
Constructors
constructor
- new
Csv <const T>(options?): CsvParseStream<T>Parse Stream Construct a new instance.
Type Parameters
- const T extends undefined | CsvParseStreamOptions = undefined
Parameters
Optionaloptions: TOptions for the stream.
Returns CsvParseStream<T>
Accessors
readable
- get readable(): ReadableStream<RowType<T>>
The instance's ReadableStream.
Returns ReadableStream<RowType<T>>
The instance's ReadableStream.
Example: Usage
import { CsvParseStream } from "@std/csv/parse-stream";
import { assertEquals } from "@std/assert/equals";
const source = ReadableStream.from([
"name,age\n",
"Alice,34\n",
"Bob,24\n",
]);
const parseStream = new CsvParseStream({ skipFirstRow: true });
const parts = source.pipeTo(parseStream.writable);
assertEquals(await Array.fromAsync(parseStream.readable), [
{ name: "Alice", age: "34" },
{ name: "Bob", age: "24" },
]);
writable
- get writable(): WritableStream<string>
The instance's WritableStream.
Returns WritableStream<string>
The instance's WritableStream.
Example: Usage
import { CsvParseStream } from "@std/csv/parse-stream";
import { assertEquals } from "@std/assert/equals";
const source = ReadableStream.from([
"name,age\n",
"Alice,34\n",
"Bob,24\n",
]);
const parseStream = new CsvParseStream({ skipFirstRow: true });
const parts = source.pipeTo(parseStream.writable);
assertEquals(await Array.fromAsync(parseStream.readable), [
{ name: "Alice", age: "34" },
{ name: "Bob", age: "24" },
]);
CsvParseStreamtransforms a stream of CSV-encoded text into a stream of parsed objects.A
CsvParseStreamexpects input conforming to RFC 4180.Example: Usage with default options
Example: Skip first row with `skipFirstRow: true`
Example: Specify columns with `columns` option
Example: Specify columns with `columns` option and skip first row with
skipFirstRow: trueExample: TSV (tab-separated values) with `separator: "\t"`
Example: Trim leading space with `trimLeadingSpace: true`
Example: Quoted fields
Example: Allow lazy quotes with `lazyQuotes: true`
Example: Define comment prefix with `comment` option
Example: Infer the number of fields from the first row with
fieldsPerRecord: 0Example: Enforce the number of field for each row with `fieldsPerRecord: 2`