npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

work-faster

v2.3.0

Published

same as array.forEach, but in parallel

Downloads

741

Readme

NPM Version NPM Downloads Code Coverage GitHub Workflow Status

Overview

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.


Main Components

class: ProgressBar

A 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.

function: forEachAsync

Executes 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.

Stream Namespace

class: WFReadable

A 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.

class: WFTransform

A 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.

class: WFWritable

A custom writable stream wrapper.

  • Constructor: new WFWritable(inner: Writable)
    • inner: The writable stream.

function: compress

Compresses 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.

function: decompress

Decompresses data based on the specified type.

  • Parameters:
    • type: Decompression type ('gzip', 'brotli', 'lz4', or 'zstd').
  • Returns: A WFTransform stream for decompression.

functions: Utilities

  • 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.

functions: Stream Processing

  • pipeline: Combines a series of readable, transform, and writable streams into a unified pipeline.
  • merge: Merges two streams (readable/transform or writable) into one.

functions: File and Line Utilities

  • 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.

Installation

npm install work-faster

Usage Examples

Using forEachAsync for Parallel Processing

import { forEachAsync } from 'work-faster';

await forEachAsync([1, 2, 3], async (item) => {
  console.log(item);
}, 2);

Compressing and Decompressing Data

import { compress, decompress } from 'work-faster';

const compressedStream = await compress('gzip');
const decompressedStream = await decompress('gzip');