-
-
Notifications
You must be signed in to change notification settings - Fork 2
utils‐with‐parser
Eugene Lazutkin edited this page Mar 31, 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().
const withParser = require('stream-csv-as-json/utils/with-parser.js');withParser is typically not used directly — instead, use asObjects.withParser():
const chain = require('stream-chain');
const asObjects = require('stream-csv-as-json/as-objects.js');
const fs = require('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:
const withParser = require('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) |
Duplex stream | Same pipeline, wrapped as a Duplex (writable: text, readable: object mode) |
-
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