-
-
Notifications
You must be signed in to change notification settings - Fork 2
utils‐with‐parser
Eugene Lazutkin edited this page Jun 3, 2026
·
3 revisions
withParser is a CSV-specific utility that composes the parser with another component into a single pipeline. It is used internally by as-objects to provide .withParser() and .withParserAsStream().
import withParser from 'stream-csv-as-json/utils/with-parser.js';For Web Streams, import from the browser-safe /web entry:
import withParser from 'stream-csv-as-json/web/utils/with-parser.js';withParser is typically not used directly — instead, use asObjects.withParser():
import chain from 'stream-chain';
import asObjects from 'stream-csv-as-json/as-objects.js';
import fs from 'node:fs';
const pipeline = chain([fs.createReadStream('data.csv'), asObjects.withParser()]);
pipeline.on('data', token => console.log(token));For custom components, withParser composes a parser and your function into a pipeline:
import withParser from 'stream-csv-as-json/utils/with-parser.js';
const myComponent = options => chunk => {
// process tokens
return chunk;
};
// As a flushable function for chain()
const pipeline = withParser(myComponent, options);
// As a Duplex stream (writable: text, readable: object mode)
const stream = withParser.asStream(myComponent, options);| Name | Signature | Returns | Description |
|---|---|---|---|
withParser |
(fn, options) |
flushable function | Composes parser(options) with fn(options) via gen()
|
withParser.asStream |
(fn, options) |
Node Duplex stream | Same pipeline, wrapped as a Node Duplex |
withParser.asWebStream |
(fn, options) |
Web {readable, writable} pair |
Same pipeline, wrapped as a Web TransformStream
|
-
fn— a factory function(options) => flushablethat creates the downstream component. -
options— passed to both the parser andfn.
Start here
Components
Tuning
Reference
stream-csv-as-json 1.x (legacy)
Built on stream-chain and stream-json