Skip to content

Commit

Permalink
add documentation on merge function
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreinglebert committed May 9, 2020
1 parent 783c897 commit e629dbe
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ $ npm install json-merge-patch --save

### Applying patches:
```js
jsonmergepatch.apply(obj: Object, patch: Object) : Object
```
Applies `patch` onto source `obj`.

### Example:
```js
var source = {
"title": "Goodbye!",
"author" : {
Expand Down Expand Up @@ -55,6 +61,12 @@ var target = jsonmergepatch.apply(source, patch);

### Generating patches:
```js
jsonmergepatch.generate(source: Object, target: Object) : Object
```
Compares `source` and `target` object and generates a `patch` of the changes necessary to convert `source` into `target`.

### Example:
```js
var source = {
"title": "Goodbye!",
"author" : "John Doe"
Expand All @@ -72,6 +84,11 @@ var patch = jsonmergepatch.generate(source, target);
// }
```

### Merging patches

This function is **outside the scope of the RFC**, its purpose is to combine/squash successive patches of the same entity into one patch.
Use it at your own risks.


### Usage with Javascript objects

Expand Down Expand Up @@ -107,22 +124,6 @@ var patch = jsonmergepatch.generate(
// }
```

## API

#### jsonmergepatch.apply (`obj` Object, `patch` Object) : Object

Applies `patch` on `obj`.

#### jsonmergepatch.generate (`source` Object, `target` Object) : `patch` Object

Generates a `patch` Object from source and target Object.


#### jsonmergepatch.merge (`patch1` Object, `patch2` Object) : `patch` Object

Generates a `patch` Object by merging patch1 and patch2.


## Running tests

```sh
Expand Down

0 comments on commit e629dbe

Please sign in to comment.