-
-
Notifications
You must be signed in to change notification settings - Fork 2
Migration from 1.x to 2.x
This guide covers breaking changes and how to update your code.
- Source moved from root to
src/. - Class-based Transform streams replaced with factory functions returning flushable closures.
- Import paths changed (lowercase,
.jsextension). -
stream-chain3.x handles backpressure viaflushable,many,none,gen,asStream. - TypeScript declarations included (
.d.tsfiles). - Test framework changed from
heya-unittotape-six.
| 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') |
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 instance2.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 streamnew Parser() is no longer available. Use parser() in a chain() pipeline or parser.asStream() for a standalone Duplex stream.
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 DuplexNote: withParser is now a method on asObjects, not a separate named export.
1.x:
const {stringer} = require('stream-csv-as-json/Stringer');
const s = stringer(options); // returns a Stringer instance2.x:
const stringer = require('stream-csv-as-json/stringer.js');
const fn = stringer(options); // flushable function for chain()
const stream = stringer.asStream(options); // Duplex stream1.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.
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 | 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) |
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');
chain([fs.createReadStream('data.csv'), parser(), asObjects()]);Components are now plain functions — they work directly in chain() without needing streamValues() to assemble objects. The token stream is the same, so stream-json utilities still work if you need them.
All parser, asObjects, and stringer options (packStrings, packValues, streamStrings, streamValues, separator, packKeys, streamKeys, useStringValues, useValues, fieldPrefix) work exactly as before with the same defaults and resolution logic.
Start here
Components
Tuning
Reference
stream-csv-as-json 1.x (legacy)
Built on stream-chain and stream-json