# hyperdiff

> Find common, removed and added element between two arrays.

Latest version **2.0.27** (published 2026-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install hyperdiff
pnpm add hyperdiff
yarn add hyperdiff
bun add hyperdiff
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

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

## Facts

| | |
|---|---|
| Version | 2.0.27 |
| Published | 2026-08-03 |
| First published | 2017-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8 |
| Dependencies | 2 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Kiko Beats |
| Maintainers | kikobeats |
| Keywords | added, array, compare, deep, delta, diff, difference, object, removed, snapshot |

## Links

- npm: https://www.npmjs.com/package/hyperdiff
- Repository: https://github.com/kikobeats/hyperdiff
- Homepage: https://github.com/Kikobeats/hyperdiff
- Issues: https://github.com/Kikobeats/hyperdiff/issues
- npm.io page: https://npm.io/package/hyperdiff

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ~4.18.1
- [debug-logfmt](https://npm.io/package/debug-logfmt.md) ~1.4.0

## Recent versions

- 2.0.27 (latest) — 2026-08-03
- 2.0.26 — 2026-07-14
- 2.0.25 — 2026-06-19
- 2.0.24 — 2026-04-03
- 2.0.23 — 2025-11-22
- 2.0.22 — 2025-10-14
- 2.0.21 — 2025-09-04
- 2.0.20 — 2025-08-13
- 2.0.19 — 2025-08-06
- 2.0.18 — 2023-10-24
- 2.0.17 — 2023-10-09
- 2.0.16 — 2023-09-05
- 2.0.15 — 2023-09-05
- 2.0.14 — 2023-02-06
- 2.0.13 — 2022-03-02
- … 14 more at https://npm.io/package/hyperdiff/versions

## README

# hyperdiff

![Last version](https://img.shields.io/github/tag/Kikobeats/hyperdiff.svg?style=flat-square)
[![Coverage Status](https://img.shields.io/coveralls/Kikobeats/hyperdiff.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/hyperdiff)
[![NPM Status](https://img.shields.io/npm/dm/hyperdiff.svg?style=flat-square)](https://www.npmjs.org/package/hyperdiff)

> Find common, removed and added element between two collections.

## Install

```bash
$ npm install hyperdiff --save
```

## Usage

Using a flat `Array`:

```js
const diff = require('hyperdiff')

const result = diff(
  [1, 2, 3, 4, 5, 6],
  [1, 2, 4, 5, 6, 0, 9, 10]
)

console.log(result)
// {
//   added: [ 0, 9, 10 ],
//   removed: [ 3 ],
//   common: [ 1, 2, 4, 5, 6 ]
// }
```

Using an `Array` of `Object`'s (in this case you need to provide the unique id):

```js
const diff = require('hyperdiff')
const result = diff(
  [
    { id: 1, name: 'a' },
    { id: 2, name: 'b' },
    { id: 3, name: 'c' },
    { id: 4, name: 'd' },
    { id: 5, name: 'e' }
  ],
  [
    { id: 1, name: 'a' },
    { id: 2, name: 'b' },
    { id: 7, name: 'e' }
  ],
  'id'
)

console.log(result)
// {
//   added: [ { id: 7, name: 'e' } ],
//   removed: [ { id: 3, name: 'c' }, { id: 4, name: 'd' }, { id: 5, name: 'e' } ],
//   common: [ { id: 1, name: 'a' }, { id: 2, name: 'b' } ]
// }
```

It's also support multiple properties as id or provide a `function`.

## Benchmark

```bash
❯ node bench.js
simpleArrayDiff*1000: 143.742ms
hyperDiff*1000: 80.234ms
simpleArrayDiff*1000: 143.405ms
hyperDiff*1000: 75.803ms
```

## API

### hyperdiff(orig, dist, [ids])

#### orig

*Required*<br>
Type: `array`

First array for be compared.

#### dist

*Required*<br>
Type: `array`

Second array for be compared. Notes the results are modeled from the second array.

#### ids

Type: `string`|`array`|`function`

In the case that you provide an `Array` of `Object`'s, you need to specify the `key`'s to be used as `id`.

## Related

* [redis-diff](https://github.com/Kikobeats/redis-diff) - Perform a diff comparison backed by redis.

## License

MIT © [Kiko Beats](https://github.com/Kikobeats).

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