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

reduce-async

v0.1.6

Published

Asynchronous Array.reduce

Downloads

20

Readme

ReduceAsync Build Status

Asynchronous Array.reduce. The reduce() method applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value.


Installation

$ npm install reduce-async

Syntax

reduceAsync(array, iteratee, done[, initialValue])

Parameters

  • array Array - The array to reduce.

  • iteratee Function - The function to execute on each value in the array, taking five arguments:

    • prev Any - The value previously returned in the last invocation of the iteratee, or initialValue if supplied.

    • curr Any - The current element being processed in the array.

    • n Integer - The index of the current element being processed in the array. Start at index 0, if an initialValue is provided, and at index 1 otherwise.

    • arr Array - The array reduceAsync was called upon.

    • next Function - The function to call when you are ready to advance to the next element in the array.

  • done Function - The function called when the reduce has finished, taking one argument:

    • result Any - The value that results from the reduction.
  • initialValue Any (Optional) - Value to use as the first argument to the first call of the iteratee.

More information on how reduce works.

Examples

  • Asynchronously sum all the values of an array.

    reduceAsync([0, 1, 2, 3], (prev, curr, n, arr, next) => {
      doSomethingAsync(() => {
        next(prev + curr);
      });
    }, result => {
      // result == 6
    }));
  • Asynchronously flatten an array of arrays,

    reduceAsync([[0, 1], [2, 3], [4, 5]], (prev, curr, n, arr, next) => {
      doSomethingAsync(() => {
        next(prev.concat(curr));
      });
    }, result => {
      // result is [0, 1, 2, 3, 4, 5]
    }));
  • Asynchronously concatenate all words within an array together starting from an initial value of "foo".

    reduceAsync(['bar', 'baz']], (prev, curr, n, arr, next) => {
      doSomethingAsync(() => {
        next(prev + curr);
      });
    }, result => {
      // result is "foobarbaz"
    }, 'foo'));

Authors

License

ISC