Class LexerTransformer

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

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.close();
}
})
.pipeThrough(new LexerTransformer())
.pipeTo(new WritableStream({ write(tokens) {
for (const token of tokens) {
console.log(token);
}
}}));
// { type: Field, value: "name", location: {...} }
// { type: FieldDelimiter, value: ",", location: {...} }
// { type: Field, value: "age", location: {...} }
// { type: RecordDelimiter, value: "\r\n", location: {...} }
// { type: Field, value: "Alice", location: {...} }
// { type: FieldDelimiter, value: ",", location: {...} }
// { type: Field, value: "20" }
// { type: RecordDelimiter, value: "\r\n", location: {...} }

Hierarchy

Constructors

Properties

Constructors

Properties

lexer: Lexer
readable: ReadableStream<Token[]>
writable: WritableStream<string>