# changeset

> Library to diff JSON objects into atomic put and delete operations, and apply change sets to objects. Useful with Levelup/LevelDB object synchronization.

Latest version **0.2.6** (published 2021-03-05) · BSD-3-Clause license · 0 weekly downloads

## Install

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

## 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.2.6 |
| Published | 2021-03-05 |
| First published | 2013-06-10 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 121 |
| Author | Eugene Ware |
| Maintainers | nharbour, eugeneware |
| Keywords | leveldb, levelup, json, diff, change, changes, changeset |

## Links

- npm: https://www.npmjs.com/package/changeset
- Repository: https://github.com/eugeneware/changeset
- Homepage: https://github.com/eugeneware/changeset#readme
- Issues: https://github.com/eugeneware/changeset/issues
- npm.io page: https://npm.io/package/changeset

## Dependencies (2)

- [udc](https://npm.io/package/udc.md) ^1.0.0
- [underscore](https://npm.io/package/underscore.md) ^1.8.3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.2.6 (latest) — 2021-03-05
- 0.2.5 — 2021-03-05
- 0.2.4 — 2018-12-18
- 0.2.3 — 2018-12-18
- 0.2.1 — 2017-01-31
- 0.2.0 — 2017-01-31
- 0.1.0 — 2014-09-30
- 0.0.6 — 2013-09-10
- 0.0.5 — 2013-06-16
- 0.0.4 — 2013-06-11
- 0.0.3 — 2013-06-10
- 0.0.2 — 2013-06-10
- 0.0.1 — 2013-06-10

## README

# changeset

Generate diff changesets for javascript objects, decomposing diffs into a series of puts and delete operations. The format is similar to the [levelup](https://github.com/rvagg/node-levelup) [batch](https://github.com/rvagg/node-levelup#batch) operation list for bulk operations.

Handles circular references of Objects and Arrays.

[![build status](https://secure.travis-ci.org/eugeneware/changeset.png)](http://travis-ci.org/eugeneware/changeset)

# Example

Take a diff of two objects and produce a list of transformation operations:

``` js
var diff = require('changeset');
var a = {
  name: 'Eugene',
  number: 42,
  tags: ['tag1', 'tag2', 'tag3'],
  scores: {
    tetris: 1000,
    carmageddon: 3
  }
};

var b = {
  name: 'Susan',
  number: 43,
  tags: ['tag1', 'tag4'],
  scores: {
    carmageddon: 3,
    zelda: 3000
  },
  age: 37
};

var changes = diff(a, b);
expect(changes).to.deep.equal([
  { type: 'put', key: ['name'], value: 'Susan' },
  { type: 'put', key: ['number'], value: 43 },
  { type: 'put', key: ['tags', '1'], value: 'tag4' },
  { type: 'del', key: ['tags', '2'] },
  { type: 'del', key: ['scores', 'tetris'] },
  { type: 'put', key: ['scores', 'zelda'], value: 3000 },
  { type: 'put', key: ['age'], value: 37 }
]);
```

Apply an operational changeset and apply it to an object to get a transformed object:

``` js
var diff = require('changeset');

var changes = [
  { type: 'put', key: ['name'], value: 'Susan' },
  { type: 'put', key: ['number'], value: 43 },
  { type: 'put', key: ['tags', '1'], value: 'tag4' },
  { type: 'del', key: ['tags', '2'] },
  { type: 'del', key: ['scores', 'tetris'] },
  { type: 'put', key: ['scores', 'zelda'], value: 3000 },
  { type: 'put', key: ['age'], value: 37 }
];

var a = {
  name: 'Eugene',
  number: 42,
  tags: ['tag1', 'tag2', 'tag3'],
  scores: {
    tetris: 1000,
    carmageddon: 3
  }
};

// apply the changes to a
var b_ = diff.apply(changes, a);

var b = {
  name: 'Susan',
  number: 43,
  tags: ['tag1', 'tag4'],
  scores: {
    carmageddon: 3,
    zelda: 3000
  },
  age: 37
};

// the transformed object should now equal b
expect(b_).to.deep.equals(b);
```

By default ```apply``` will return a new modified object after applying the
changeset. If you want to modify the destination, pass true as the third
parameter:

``` js
// apply the changes to a and modify a
var b_ = diff.apply(changes, a, true);
// a is now modified, and b_ is the same as a
expect(b_).to.equal(a);
```

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