Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
Renamed package to diff-to-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
taylank committed Dec 18, 2017
1 parent 1c94756 commit c27f1a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# json-diff-patch
# diff-to-patch

A function that compares two JavaScript-objects and returns an array of JSON Patch-operations representing the difference between the two objects.

## Install

```bash
npm install json-diff-patch
npm install diff-to-patch
```

## Usage

To use the function, simply ```require``` it and pass two objects you want to compare to it:

```javascript
const jsonDiffPatch = require('json-diff-patch');
const diffToPatch = require('diff-to-patch');

jsonDiffPatch({ foo: 'bar' }, { foo: 'baz' });
diffToPatch({ foo: 'bar' }, { foo: 'baz' });
// => [{ op: 'replace', path: '/foo', value: 'baz' }]

jsonDiffPatch({}, { foo: 'bar' });
diffToPatch({}, { foo: 'bar' });
// => [{ op: 'add', path: '/foo', value: 'bar' }]

jsonDiffPatch({ foo: 'bar' }, {});
diffToPatch({ foo: 'bar' }, {});
// => [{ op: 'remove', path: '/foo' }]

jsonDiffPatch([1, 2, 3], [1, 2, 4]);
diffToPatch([1, 2, 3], [1, 2, 4]);
// => [{ op: 'replace', path: '/2', value: 4}]

jsonDiffPatch([1, 2, 3], [1, 2, 3, 4]);
diffToPatch([1, 2, 3], [1, 2, 3, 4]);
// => [{ op: 'add', path: '/3', value: 4}]

jsonDiffPatch([1, 2, 3], [1, 2]);
diffToPatch([1, 2, 3], [1, 2]);
// => [{ op: 'remove', path: '/2'}]
```

Expand Down Expand Up @@ -66,7 +66,7 @@ let objB = {
email: 'bob@gmail.com'
}

jsonDiffPatch(objA, objB);
diffToPatch(objA, objB);
/*
=> [
{ op: 'replace', path: '/name', value: 'Bobby' },
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "json-diff-patch",
"name": "diff-to-patch",
"version": "0.1.0",
"description": "A function that compares two JavaScript-objects and returns an array of JSON Patch-operations representing the difference between the two objects.",
"main": "index.js",
Expand All @@ -8,7 +8,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/taylanken/json-diff-patch.git"
"url": "git+https://github.com/taylanken/diff-to-patch.git"
},
"keywords": [
"json",
Expand All @@ -23,7 +23,7 @@
"author": "Taylan Kenanoglu",
"license": "MIT",
"bugs": {
"url": "https://github.com/taylanken/json-diff-patch/issues"
"url": "https://github.com/taylanken/diff-to-patch/issues"
},
"homepage": "https://github.com/taylanken/json-diff-patch#readme"
"homepage": "https://github.com/taylanken/diff-to-patch#readme"
}

0 comments on commit c27f1a6

Please sign in to comment.