Giter Club home page Giter Club logo

auto-change-description's Introduction

auto-change-description Build Status

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.