Registry / data / stream-transform

stream-transform

JSON →
library3.4.1jsnpmunverified

Stream-transform is a robust JavaScript library designed for object transformations, implementing the Node.js `stream.Transform` API. It is a core component of the broader `node-csv` project, currently at version 3.4.1. This library offers flexible APIs, including stream-based for high scalability, and convenient callback-based and synchronous options for simpler use cases. Key differentiators include its adherence to the native Node.js stream interface, support for both synchronous and asynchronous user functions, and capabilities for sequential or concurrent execution. It can process various input and output types such as objects, arrays, and JSON, enabling operations like skipping, multiplying, altering, or cloning records. While an explicit release cadence isn't stated, its inclusion in the actively maintained `node-csv` project implies regular updates and support.

npm install stream-transform
INSTALL
IMPORT
SIG · STREAM-TRANSFORM
S
stream-transform
datajavascriptv3.4.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

transform
import { transform } from 'stream-transform/sync';
const { transform } = require('stream-transform/sync');
This is for the synchronous API. As of v3.x, `stream-transform` is primarily an ESM module, so CommonJS `require` for ES Module paths is incorrect. It may work with specific bundler configurations or older Node.js versions, but `import` is the idiomatic way.
transform
import { transform } from 'stream-transform';
const transform = require('stream-transform');
This imports the factory function for the stream-based API. Named imports are standard for ESM. Attempting to `require` this path directly in an ESM context will fail.
Transformer
import { Transformer } from 'stream-transform';
class MyTransformer extends require('stream-transform').Transformer {}
To extend the base Transformer class for custom stream implementations, use a named import. Direct `require` for extending classes is not recommended in modern Node.js ESM.
transform (Callback API)
import { transform as transformCallback } from 'stream-transform/callback';
The callback API is designed for smaller datasets that fit into memory. This specific import path is for the callback-based `transform` function.

This quickstart demonstrates the synchronous transformation API. It takes an array of arrays (records), applies a function to each record to shift its elements, and asserts the output. This API is suitable for smaller datasets that can be processed in memory.

import { transform } from "stream-transform/sync"; import assert from "node:assert"; const inputRecords = [ ["a", "b", "c", "d"], ["1", "2", "3", "4"], ["x", "y", "z", "w"] ]; const transformedRecords = transform( inputRecords, function (record) { // Example transformation: move the first element to the end record.push(record.shift()); return record; }, // Optional options object can be passed here { objectMode: true } // Assuming objectMode for array records ); assert.deepEqual(transformedRecords, [ ["b", "c", "d", "a"], ["2", "3", "4", "1"], ["y", "z", "w", "x"] ]); console.log("Transformation successful:", transformedRecords);
Debug
Known issues
breakingVersion 3.x (and `node-csv` v6.x) transitioned to ECMAScript Modules (ESM) as the primary module system. This means that `require()` statements for `stream-transform` or its sub-paths may no longer work directly or require specific Node.js `--experimental-json-modules` flags or `type: 'module'` in `package.json` for interoperability with CommonJS.
fix
Migrate your import statements to use `import` syntax (e.g., `import { transform } from 'stream-transform';`). If you must use CommonJS, ensure your environment is configured for CJS-ESM interop, or consider using older versions if migration is not feasible. For sync modules, CommonJS users previously used `require('pkg/lib/sync')` but should now use `require('pkg/sync')`.
affects: >=3.0.0
gotchaWhen using the callback or synchronous APIs (e.g., `stream-transform/sync`), the entire dataset must fit into memory. These APIs buffer all records before returning the result. For very large datasets, this can lead to out-of-memory errors.
fix
For large datasets, use the stream-based API (`import { transform } from 'stream-transform';`) which processes data in chunks, leveraging Node.js streams for memory efficiency and backpressure handling.
affects: >=1.0.0
gotchaIncorrectly mixing stream modes (objectMode vs. buffer/string mode) can lead to unexpected behavior or type errors. While `stream-transform` handles objects, piping it with streams not in `objectMode` can cause issues.
fix
Ensure `objectMode: true` is consistently set on all `stream.Transform` instances in your pipeline if you are passing JavaScript objects, not just raw buffers or strings. Verify the input/output types of connected streams.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: transform is not a function
Attempting to use `require('stream-transform')` or `require('stream-transform/sync')` in a project configured for ES Modules, or incorrect named import from an ESM package.
fix
If in an ESM project, use `import { transform } from 'stream-transform';` or `import { transform } from 'stream-transform/sync';`. If in a CJS project, ensure correct CommonJS syntax and consider that direct `require` of ESM packages can be problematic in some Node.js versions without specific configurations.
Error: The 'chunk' argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object
A stream transformation function is receiving JavaScript objects but `objectMode` is not enabled, so it expects buffers or strings.
fix
When creating a transform stream or using the `transform` factory function with JavaScript objects (e.g., arrays, JSON objects), ensure `objectMode: true` is passed in the options: `new Transformer({ objectMode: true, transform: ... })` or `transform(records, { objectMode: true }, handler)`.
Upgrade
Version history
3.4.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
stream-transform — npm install stream-transform · libregistry