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 🙏

© 2025 – Pkg Stats / Ryan Hefner

arrays-sugar

v1.0.3

Published

async versions of javascript array functions: every, filter, find, findIndex, some

Readme

arrays sugar

What's this package?

Async versions of array functions with predicate callbacks e.g.

import { findIndex } from 'arrays-sugar'

const array = [1, 2, 3];
findIndex(array, async (number) => number === 2) // 1 ✅
array.findIndex(async (number) => number === 2) // 0 ❌

Built with Typescript for Node.js or the Browser.

What's in it?

A set of purely functional array methods with async predicates: every, filter, find, findIndex, some

These are used internally in the related AI Sugar package/library. Check it out especially if you're building or working with AI in Typescript/Node.js.

So each function has 2/3 versions:

  • default version which is concurrent (uses Promise.allSettled internally) and is also available with the suffix Concurrent
   // both are equivalent
   [1, 2, 3].every(async (number) => number === 2) === true
   [1, 2, 3].everyConcurrent(async (number) => number === 2) === true
  • optimized version that may not iterate the entire array on condition that the predicate throws for falsy values (instead of returning false). This is available for all except filter which has to go through the whole array. Uses the suffix Optimized.
    const result = await findOptimized(array, async (item) => {
      if (item <= 1) {
        throw new Error("error");
      }
      return true;
    });
  • serial version that iterates one at a time (slow). Uses the suffix Serial.
    const result = await findIndexSerial(array, async (item) => {
      await sleep(100);
      return item > 1;
    });

Why?

Using callbacks with promises or async/await inside findIndex always returns truthy for all items in the array.

If you try this in the console or node.js it will always return false

[1, 2, 3].findIndex(async (number) => number === 2) === 1

The same goes for every, find, filter, some

Outside map it seems only reduce can work with promise or async/await callbacks

const sum = await [1, 2, 3].reduce((accumulator, number) => {
  return accumulator.then(value => value + number)
}, Promise.resolve(0));
console.log(sum) // 6

Coming soon

Async versions of:

  1. indexOf
  2. lastIndexOf
  3. findLast
  4. findLastIndex

That's it!

Thanks for reading. I welcome your input, suggestions, feedback. Here is the medium article I wrote introducing this library.

Check out the following related libraries that I also built with this release.

ai-sugar AI Sugar is a collection of utility functions for working with AI apis.

const sorted = await ai.sort({
  array: ["green", "red", "blue", "yellow"],
  prompt: "rainbow color order",
});
// ["red", "yellow", "green", "blue"]

zod-sugar Zod Sugar is basically reverse zod i.e. creates a zod schema from a javascript value:

const object = { foo: "bar", baz: 1 };
const schema = createZod(object);
// z.object({ foo: z.string(), bar: z.number() });
schema.safeParse(object).success // true

What I'm building

Similarly logo

Find the best alternatives with one click. Discover similar websites, tools and services instantly while browsing. Never miss out on better options again. Check out Similarly