Skip to content

utils‐with‐parser

Eugene Lazutkin edited this page Mar 31, 2026 · 3 revisions

utils/with-parser

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

const withParser = require('stream-csv-as-json/utils/with-parser.js');

Usage

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);

API

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) => flushable that creates the downstream component.
  • options — passed to both the parser and fn.

Clone this wiki locally