# concat-each

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

Latest version **1.0.0** (published 2018-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install concat-each
pnpm add concat-each
yarn add concat-each
bun add concat-each
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-05-23 |
| First published | 2018-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.3.0 |
| Dependencies | 4 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Lamansky |
| Maintainers | lamansky |
| Keywords | concat, concatenate, each, array, Set |

## Links

- npm: https://www.npmjs.com/package/concat-each
- Repository: https://github.com/lamansky/concat-each
- Issues: https://github.com/lamansky/concat-each/issues
- npm.io page: https://npm.io/package/concat-each

## Dependencies (4)

- [sbo](https://npm.io/package/sbo.md) ^1.1.0
- [vfn](https://npm.io/package/vfn.md) ^1.1.0
- [vadd](https://npm.io/package/vadd.md) ^1.0.0
- [neach](https://npm.io/package/neach.md) ^1.0.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-05-23

## README

# concat-each

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

## Installation

Requires [Node.js](https://nodejs.org/) 8.3.0 or above.

```bash
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

```javascript
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

```javascript
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

* [neach](https://github.com/lamansky/neach): Nested forEach

---
_Source: https://npm.io/package/concat-each · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
