# @helcor/merge-collections

> Merge two arrays of objects by identifier

Latest version **1.0.0-beta.9** (published 2020-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @helcor/merge-collections
pnpm add @helcor/merge-collections
yarn add @helcor/merge-collections
bun add @helcor/merge-collections
```

## 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-beta.9 |
| Published | 2020-09-22 |
| First published | 2018-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | romelperez |

## Links

- npm: https://www.npmjs.com/package/@helcor/merge-collections
- Repository: https://github.com/romelperez/helcor
- Homepage: https://github.com/romelperez/helcor#readme
- Issues: https://github.com/romelperez/helcor/issues
- npm.io page: https://npm.io/package/@helcor/merge-collections

## Dependencies (1)

- [extend](https://npm.io/package/extend.md) ^3.0.2

## Recent versions

- 1.0.0-beta.9 (latest) — 2020-09-22
- 1.0.0-beta.6 — 2018-12-23
- 1.0.0-beta.5 — 2018-12-22
- 1.0.0-beta.3 — 2018-12-22
- 1.0.0-beta.2 — 2018-12-21

## README

![helcor](https://github.com/romelperez/helcor/raw/main/helcor.jpg)

# `@helcor/merge-collections`

<a href="https://npmjs.org/package/@helcor/merge-collections">
  <img src="https://img.shields.io/npm/v/@helcor/merge-collections.svg" alt="version" />
</a>
<a href="https://npmjs.org/package/@helcor/merge-collections">
  <img src="https://img.shields.io/npm/dm/@helcor/merge-collections.svg" alt="downloads" />
</a>

Merge two arrays of objects by identifier.

## API

`mergeCollections(array1, array2, options)`

- `Array array1` - Source collection.
- `Array array2` - Collection to merge.
- `Object options` - Options. (Optional)
  - `string id` - The identifier. Default: `'id'`. (Optional)
  - `boolean shallow` - Shallow extend. Default: `false`. (Optional)
- Returns `Array` - A new collection with the merged items.

## Example

```js
import mergeCollections from '@helcor/merge-collections';

const col1 = [
  { myId: 'x1', v: 'a' },
  { myId: 'x2', v: 'b' },
  { myId: 'x3', v: 'c' }
];
const col2 = [
  { myId: 'x1', v: 'x' },
  { myId: 'x2', v: 'y' },
  { myId: 'x4', v: 'z' }
];
const received = mergeCollections(col1, col2, { id: 'myId' });
const expected = [
  { myId: 'x1', v: 'x' },
  { myId: 'x2', v: 'y' },
  { myId: 'x3', v: 'c' },
  { myId: 'x4', v: 'z' }
];
expect(received).toEqual(expected);
```

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