https://github.com/cope/auto-change-description
JSON Auto Change Description
https://github.com/cope/auto-change-description
javascript json
Last synced: about 2 months ago
JSON representation
JSON Auto Change Description
- Host: GitHub
- URL: https://github.com/cope/auto-change-description
- Owner: cope
- License: unlicense
- Created: 2017-10-17T08:45:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-02T11:17:17.000Z (over 4 years ago)
- Last Synced: 2025-04-04T10:44:11.537Z (over 1 year ago)
- Topics: javascript, json
- Language: JavaScript
- Size: 114 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# auto-change-description
[](https://travis-ci.org/cope/auto-change-description)
[](https://www.codacy.com/project/cope/auto-change-description/dashboard)
[](https://coveralls.io/github/cope/auto-change-description?branch=master)
[](https://www.npmjs.com/package/auto-change-description)
[](https://www.npmjs.com/package/auto-change-description)
This simple library compares two JSONs and lists the differences found as changes.
The library checks for created, deleted or modified plain attributes. This is done using [deep-diff](https://www.npmjs.com/package/deep-diff).
Array attributes are treated as plain attributes and compared using [deep-equal](https://www.npmjs.com/package/deep-equal). If arrays contain any objects or other arrays, those are not separately considered.
Objects are finally treated recursively.
# Install
With [npm](http://npmjs.org) do:
```
npm i --save auto-change-description
```
# Use
```
const acd = require('auto-change-description');
var results = acd.describe(before, after);
```
#### Example
Comparing these two JSONs:
```
var before = {
name: 'my object',
puppy: 'yo',
description: 'it\'s an object!',
details: {
it: 'has',
an: 'array',
with: ['a', 'few', 'elements']
}
};
var after = {
name: 'updated object',
yo: 'puppy',
description: 'it\'s an object!',
details: {
it: 'has',
an: 'array',
with: ['a', 'few', 'more', 'elements', {than: 'before'}]
}
};
```
Produces this output:
```
[
'Deleted {puppy} with value (yo).',
'Created {yo} with value (puppy).',
'Modified {name} from (my object) to (updated object).',
'Modified {details.with} from (["a","few","elements"]) to (["a","few","more","elements",{"than":"before"}]).'
]
```
The output was left as an array to allow free joining as people see fit, either with '\n' or '<br>' or whatever else.
The same logic was applied to {} and () wraps, to allow easy replacement with, for example, <strong></strong>, <em></em> or any other formatting syntaxes.