# shallow-diff

> compare two objects or arrays and return the diff (add/updated/removed/unchanged)

Latest version **0.0.5** (published 2015-06-09) · 0 weekly downloads

## Install

```sh
npm install shallow-diff
pnpm add shallow-diff
yarn add shallow-diff
bun add shallow-diff
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2015-06-09 |
| First published | 2014-04-01 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Olivier Scherrer |
| Maintainers | podefr |
| Keywords | diff, objects, array, shallow |

## Links

- npm: https://www.npmjs.com/package/shallow-diff
- Repository: git@github.com:cosmosio/shallow-diff
- Homepage: https://github.com/cosmosio/shallow-diff
- Issues: https://github.com/cosmosio/shallow-diff/issues
- npm.io page: https://npm.io/package/shallow-diff

## Dependencies (1)

- [simple-loop](https://npm.io/package/simple-loop.md) 0.0.4

## Recent versions

- 0.0.5 (latest) — 2015-06-09
- 0.0.4 — 2015-05-08
- 0.0.2 — 2014-04-01
- 0.0.1 — 2014-04-01

## README

Shallow diff
=============

Make a shallow diff between two objects/arrays to get what has been updated/deleted/added or remains unchanged.
It will not traverse the whole structure, only the top level items/property.

Installation
============

```bash
npm install shallow-diff
```

How to use
==========

Require shallow-diff:

```bash
var diff = require("shallow-diff");
```

Get the diff between two objects:

```js
var base = {a:1, b:2, c:3, d:4, f:6};
var compared = {a:1, b:20, d: 4, e: 5};

diff(base, compared);
// returns
// {
//    unchanged: ["a", "d"],
//    updated: ["b"],
//    deleted: ["f"],
//    added: ["e"]
// }
```

Get the diff between two arrays:

```js
var base = [10, 20, 30]
var compared = [15, 20]

diff(base, compared);
// returns:
// {
//    unchanged: [1],
//    updated: [0],
//    deleted: [2],
//    added: []
// }
```

CHANGELOG
=========

## 0.0.5 - 9 JUN 2015

* Also update to simple loop 0.0.4 to remove its dependency on assert. Thanks to [@markdalgleish](https://twitter.com/markdalgleish).

## 0.0.4 - 7 MAY 2015

* Remove dependency on assert and replace with own function. Saves 17kb in the end after browserfication. Thanks to [@tomekwi](https://github.com/tomekwi).

### 0.0.3 - 8 APR 2015

* Fix a bug where undefined values would appear in the diff as added and deleted. [See #1](https://github.com/cosmosio/shallow-diff/pull/1). Thanks to [@sverrejoh](https://github.com/sverrejoh)

LICENSE
=======

MIT

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