Skip to content

Migration from 1.x to 2.x

Eugene Lazutkin edited this page May 11, 2026 · 3 revisions

Migrating from 1.x to 2.x

This guide covers breaking changes and how to update your code.

Overview of changes

  • Source moved from root to src/.
  • Class-based Transform streams replaced with factory functions returning flushable closures.
  • Import paths changed (lowercase, .js extension).
  • stream-chain 3.x handles backpressure via flushable, many, none, gen, asStream.
  • TypeScript declarations included (.d.ts files).
  • Test framework changed from heya-unit to tape-six.

Import path changes

1.x 2.x
require('stream-csv-as-json') require('stream-csv-as-json') (unchanged)
require('stream-csv-as-json/Parser') require('stream-csv-as-json/parser.js')
require('stream-csv-as-json/AsObjects') require('stream-csv-as-json/as-objects.js')
require('stream-csv-as-json/Stringer') require('stream-csv-as-json/stringer.js')

API changes

Parser

1.x — class with constructor and static factories:

const Parser = require('stream-csv-as-json/Parser');
const p = new Parser(options);
// or
const {parser} = require('stream-csv-as-json/Parser');
const p = parser(options); // returns a Parser instance

2.x — factory function:

const parser = require('stream-csv-as-json/parser.js');
const fn = parser(options); // flushable function for chain()
const stream = parser.asStream(options); // Duplex stream

new Parser() is no longer available. Use parser() in a chain() pipeline or parser.asStream() for a standalone Duplex stream.

AsObjects

1.x:

const {asObjects} = require('stream-csv-as-json/AsObjects');
const {withParser} = require('stream-csv-as-json/AsObjects');

2.x:

const asObjects = require('stream-csv-as-json/as-objects.js');
asObjects(options); // flushable function
asObjects.asStream(options); // Duplex stream
asObjects.withParser(options); // parser + asObjects pipeline
asObjects.withParserAsStream(options); // same, as Duplex

Note: withParser is now a method on asObjects, not a separate named export.

Stringer

1.x:

const {stringer} = require('stream-csv-as-json/Stringer');
const s = stringer(options); // returns a Stringer instance

2.x:

const stringer = require('stream-csv-as-json/stringer.js');
const fn = stringer(options); // flushable function for chain()
const stream = stringer.asStream(options); // Duplex stream

Main module

1.x:

const make = require('stream-csv-as-json');
const {Parser, parser} = require('stream-csv-as-json');

2.x:

const make = require('stream-csv-as-json');
const {parser} = require('stream-csv-as-json');

make(options) still returns a stream with emit() applied. The Parser class export is removed — use parser instead.

stream-chain

1.x used stream-chain 2.x with {chain} destructuring:

const {chain} = require('stream-chain');

2.x uses stream-chain 3.x with a default export:

const chain = require('stream-chain');

Removed APIs

Removed Replacement
new Parser(options) parser(options) or parser.asStream(options)
Parser.make(options) parser(options)
Parser.parser(options) parser(options)
new AsObjects(options) asObjects(options) or asObjects.asStream(options)
AsObjects.make(options) asObjects(options)
new Stringer(options) stringer(options) or stringer.asStream(options)
Stringer.make(options) stringer(options)
make.Constructor / make.Parser parser (the factory)

Quick migration recipe

Before (1.x):

const {chain} = require('stream-chain');
const {parser} = require('stream-csv-as-json');
const {asObjects} = require('stream-csv-as-json/AsObjects');
const {streamValues} = require('stream-json/streamers/StreamValues');

chain([fs.createReadStream('data.csv'), parser(), asObjects(), streamValues(), ({value}) => console.log(value)]);

After (2.x):

const chain = require('stream-chain');
const {parser} = require('stream-csv-as-json');
const asObjects = require('stream-csv-as-json/as-objects.js');
const streamValues = require('stream-json/streamers/stream-values.js');

chain([fs.createReadStream('data.csv'), parser(), asObjects(), streamValues(), ({value}) => console.log(value)]);

Components are now plain functions instead of Transform classes, but the pipeline still produces a token stream. You still need streamValues() (or Assembler) to assemble tokens into JavaScript objects — only the import paths and instantiation style have changed.

Options unchanged

All parser, asObjects, and stringer options (packStrings, packValues, streamStrings, streamValues, separator, packKeys, streamKeys, useStringValues, useValues, fieldPrefix) work exactly as in 1.x with the same defaults and resolution logic.

Notes for code written against later 2.x point releases:

  • asObjects.useStringValues / useValues became deprecated no-ops once the header collector started auto-detecting the parser's mode — passing them no longer changes behavior but is still accepted.
  • stringer gained a rowTerminator option (default '\r\n' per RFC 4180; pass '\n' for Unix-style output).
  • The parser strips a single leading UTF-8 BOM (U+FEFF) and reads CRLF / LF / bare CR row terminators; it throws on malformed quoted values rather than silently dropping them.

Clone this wiki locally