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

concat-each

v1.0.0

Published

Iterates nested loops and concatenates values onto an Array or Set.

Downloads

8

Readme

concat-each

Iterates nested loops and concatenates values onto an Array or Set.

Installation

Requires Node.js 8.3.0 or above.

npm i concat-each

API

The module exports a single function.

Parameters

  1. base (Array, Set, WeakSet): The collection onto which new items should be concatenated. If you want to create a new collection, pass in [] or new Set() or new WeakSet().
  2. Variadic: ...iterables (one or more of: iterable): Iterable collections of items to pass to cb. Specify multiple iterables if you want nested loops.
  3. cb (function): A callback which accepts an argument for each iterable in iterables and returns an array of items to concatenate onto base.
  4. Optional: Object argument:
    • arrays / sets / weakSets (arrays of classes/strings): Arrays of classes and/or string names of classes that should be treated as equivalent to Array/Set/WeakSet (respectively).
    • loose (boolean): Whether or not to compare values loosely (as defined by looselyEquals) for the purpose of testing uniqueness if unique is true. Defaults to false.
    • looselyEquals (function): A callback that accepts two values and returns true if they are to be considered equivalent or false otherwise. This argument is only used if loose is true. If omitted, the default behavior will, among other things, consider arrays/objects to be equal if they have the same entries.
    • unique (boolean): Whether or not to refrain from adding values that already exist in base. Defaults to false. You can define what uniqueness means by using the loose and looselyEquals arguments.

Return Value

Modifies and returns base.

Example

Explaining the module is best done by showing the code it replaces:

Before

const n = []
for (const i of [1, 2, 3]) {
  for (const j of [2, 3, 4]) {
    const sum = i + j
    if (sum % 2 === 0) n.push(sum)
  }
}

n // [4, 4, 6, 6]

After

const concatEach = require('concat-each')

const n = concatEach([], [1, 2, 3], [2, 3, 4], (i, j) => (i + j) % 2 === 0 ? [i + j] : []) // [4, 4, 6, 6]

Related