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-transformVerified import paths — ran on the pinned version, not inferred.
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.
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')`.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.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.
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.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)`.No dependency data recorded yet.