1.0.7 • Published 2 years ago

auto-change-description v1.0.7

Weekly downloads
10
License
UNLICENSED
Repository
github
Last release
2 years ago

auto-change-description

build status codacy coverage dependencies npm

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.

Array attributes are treated as plain attributes and compared using deep-equal. If arrays contain any objects or other arrays, those are not separately considered.

Objects are finally treated recursively.

Install

With npm 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.

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.1

7 years ago