The type of the header row
The assembler options type
Optionaloptions: OptionsCSV assembler options including header, outputFormat, etc.
OptionalstreamOptions: CSVRecordAssemblerTransformerStreamOptionsStream-specific options like backpressureCheckInterval
OptionalwritableStrategy: QueuingStrategy<TokenNoLocation>Strategy for the writable side (default: { highWaterMark: 1024, size: () => 1 })
OptionalreadableStrategy: QueuingStrategy<CSVRecord<Header, InferFormat<Options>>>Strategy for the readable side (default: { highWaterMark: 256, size: () => 1 })
A CSVRecordAssemblerTransformer instance configured with the specified options
Choosing the Right API for guidance on selecting the appropriate API level.
import { createStringCSVLexerTransformer, createCSVRecordAssemblerTransformer } from 'web-csv-toolbox';
new ReadableStream({
start(controller) {
controller.enqueue("name,age\r\n");
controller.enqueue("Alice,20\r\n");
controller.enqueue("Bob,25\r\n");
controller.close();
}
})
.pipeThrough(createStringCSVLexerTransformer())
.pipeThrough(createCSVRecordAssemblerTransformer())
.pipeTo(new WritableStream({ write(record) {
console.log(record);
}}));
// { name: "Alice", age: "20" }
// { name: "Bob", age: "25" }
import { createStringCSVLexerTransformer, createCSVRecordAssemblerTransformer } from 'web-csv-toolbox';
const transformer = createCSVRecordAssemblerTransformer({
header: ['name', 'age']
});
// Data without header row
csvStream
.pipeThrough(createStringCSVLexerTransformer())
.pipeThrough(transformer);
import { createStringCSVLexerTransformer, createCSVRecordAssemblerTransformer } from 'web-csv-toolbox';
const transformer = createCSVRecordAssemblerTransformer({
outputFormat: 'array'
});
csvStream
.pipeThrough(createStringCSVLexerTransformer())
.pipeThrough(transformer)
.pipeTo(new WritableStream({ write(record) {
console.log(record); // ['Alice', '20']
}}));
import { createStringCSVLexerTransformer, createCSVRecordAssemblerTransformer } from 'web-csv-toolbox';
const transformer = createCSVRecordAssemblerTransformer(
{ header: ['name', 'age'] },
{ backpressureCheckInterval: 20 },
new CountQueuingStrategy({ highWaterMark: 2048 }),
new CountQueuingStrategy({ highWaterMark: 512 })
);
await tokenStream
.pipeThrough(transformer)
.pipeTo(yourRecordProcessor);
Factory function to create a CSVRecordAssemblerTransformer instance.
This function internally creates a CSVRecordAssembler and wraps it in a CSVRecordAssemblerTransformer, providing a simpler API for stream-based CSV record assembly.