Class RecordAssemblerTransformer<Header>

A transform stream that converts a stream of tokens into a stream of rows.

Param: options

The options for the parser.

Example: Parse a CSV with headers by data

new ReadableStream({
start(controller) {
controller.enqueue("name,age\r\n");
controller.enqueue("Alice,20\r\n");
controller.enqueue("Bob,25\r\n");
controller.enqueue("Charlie,30\r\n");
controller.close();
})
.pipeThrough(new LexerTransformer())
.pipeThrough(new RecordAssemblerTransformer())
.pipeTo(new WritableStream({ write(row) { console.log(row); }}));
// { name: "Alice", age: "20" }
// { name: "Bob", age: "25" }
// { name: "Charlie", age: "30" }

Example: Parse a CSV with headers by options

new ReadableStream({
start(controller) {
controller.enqueue("Alice,20\r\n");
controller.enqueue("Bob,25\r\n");
controller.enqueue("Charlie,30\r\n");
controller.close();
}
})
.pipeThrough(new LexerTransformer())
.pipeThrough(new RecordAssemblerTransformer({ header: ["name", "age"] }))
.pipeTo(new WritableStream({ write(row) { console.log(row); }}));
// { name: "Alice", age: "20" }
// { name: "Bob", age: "25" }
// { name: "Charlie", age: "30" }

Type Parameters

  • Header extends ReadonlyArray<string>

    The type of the header row.

Hierarchy

Constructors

Properties

Constructors

Properties

writable: WritableStream<Token[]>

Generated using TypeDoc