same as array.forEach, but in parallel
npm install work-faster



- Overview
- Main Components
- class: ProgressBar
- function: forEachAsync
- Stream Namespace
- class: WFReadable
- class: WFTransform
- class: WFWritable
- function: compress
- function: decompress
- functions: Utilities
- functions: Stream Processing
- functions: File and Line Utilities
- Installation
- Usage Examples
work-faster is an NPM package providing utilities for working with asynchronous streams, parallel processing, and data compression in Node.js. It includes classes and functions that enhance readability and modularity for handling streams, processing data asynchronously, and performing common file and stream-based operations efficiently.
---
ProgressBarA progress indicator for tracking and displaying task completion over time.
- Constructor: new ProgressBar(total, timeStep?)
- total (required): The total steps for the progress bar.
- timeStep (optional, default: 1000 ms): Refresh rate of the progress bar.
- Methods:
- increment(value?): Advances the progress by value (default: 1).
- update(value): Updates the progress directly to a specific value.
- close(): Closes and finalizes the progress bar display.
forEachAsyncExecutes an asynchronous callback function over items with an optional parallel limit.
- Parameters:
- items: Iterable or async iterable items to process.
- callback(item, index): Async function executed for each item.
- maxParallel (optional): Maximum parallel tasks.
- Returns: A promise resolving when all items are processed.
WFReadableA custom readable stream wrapper.
- Constructor: new WFReadable(inner: Readable)
- inner: The original readable stream.
- Methods:
- pipe(destination): Pipes data to another transform or writable stream.
- merge(destination): Merges data from another transform stream.
- [Symbol.asyncIterator]: Iterates over the stream asynchronously.
WFTransformA custom duplex transform stream wrapper.
- Constructor: new WFTransform(inner: Duplex)
- inner: The duplex stream.
- Methods:
- pipe(destination): Pipes data to another transform or writable stream.
- merge(destination): Merges data from another transform stream.
WFWritableA custom writable stream wrapper.
- Constructor: new WFWritable(inner: Writable)
- inner: The writable stream.
compressCompresses data based on the specified type and options.
- Parameters:
- type: Compression type ('gzip', 'brotli', 'lz4', or 'zstd').
- options: Compression options (e.g., level).
- Returns: A WFTransform stream for compression.
decompressDecompresses data based on the specified type.
- Parameters:
- type: Decompression type ('gzip', 'brotli', 'lz4', or 'zstd').
- Returns: A WFTransform stream for decompression.
- fromValue: Wraps a single value as a readable stream.
- fromArray: Converts an array of items into a readable stream.
- toBuffer: Collects data from a stream into a Buffer.
- toString: Collects data from a stream into a string.
- toArray: Collects all data chunks from a stream into an array.
- pipeline: Combines a series of readable, transform, and writable streams into a unified pipeline.
- merge: Merges two streams (readable/transform or writable) into one.
- read: Reads a file from the filesystem or a URL as a readable stream.
- asBuffer: Converts a string or buffer-based stream into a buffer stream.
- asLines: Splits a stream by lines or regex pattern.
---
``bash`
npm install work-faster
Using forEachAsync for Parallel Processing
`javascript
import { forEachAsync } from 'work-faster';
await forEachAsync([1, 2, 3], async (item) => console.log(item), 2);
`
Compressing and Decompressing Data
`javascript
import { compress, decompress } from 'work-faster';
const compressedStream = await compress('gzip');
const decompressedStream = await decompress('gzip');
``