@vaziliybober/gendiff

Generator of difference between two config files

Usage no npm install needed!

<script type="module">
  import vaziliyboberGendiff from 'https://cdn.skypack.dev/@vaziliybober/gendiff';
</script>

README

Gendiff

Maintainability Test Coverage Continuous integration workflow

Gendiff is an npm module that generates the difference between two configuration files and formats it into a string

The following configuration file types are supported: json (.json), yaml (.yml), ini (.ini)

This is the lvl-2 frontend project on https://ru.hexlet.io/

Example

In this example three pairs of files are containing the same data, but in different formats. Because the data itself is the same, the gendiff applied to all the three sets of data will lead to equal results:

file1.json file2.json result (stylish) result (plain) result (json)
{
  "hello": "world",
  "obj": {
    "foo": "bar",
    "node": {
      "array": [1],
      "str": "jkl;"
    }
  }
}
{
  "number": 17,
  "obj": {
    "foo": "bar",
    "node": {
      "array": [1],
      "str": "asdf"
    }
  }
}
{
  - hello: world
  + number: 17
    obj: {
        foo: bar
        node: {
            array: [
                1
            ]
          - str: jkl;
          + str: asdf
        }
    }
}
Property 'hello' was removed
Property 'number' was added with value: 17
Property 'obj.node.str' was updated. From 'jkl;' to 'asdf'

[{"type":"leaf","name":"hello","status":"removed","value":"world"},{"type":"leaf","name":"number","status":"added","value":17},{"type":"node","name":"obj","children":[{"type":"leaf","name":"foo","status":"unchanged","value":"bar"},{"type":"node","name":"node","children":[{"type":"leaf","name":"array","status":"unchanged","value":[1]},{"type":"leaf","name":"str","status":"modified","valueBefore":"jkl;","valueAfter":"asdf"}]}]}]

file1.yml file2.yml
hello: world
obj:
  foo: bar
  node:
    array:
      - 1
    str: jkl;
hello: world
obj:
  foo: bar
  node:
    array:
      - 1
    str: jkl;
file1.ini file2.ini
hello=world

[obj]
foo=bar

[obj.node]
array[]=1
str=jkl\;
number=17

[obj]
foo=bar

[obj.node]
array[]=1
str=asdf

Install

npm install -g @vaziliybober/gendiff

Clone

git clone https://github.com/vaziliybober/gendiff.git
cd gendiff/
make install
make link

Use

Usage: gendiff [options] <filepath1> <filepath2>

Compares two configuration files and shows a difference.

Options:
  -V, --version        output the version number
  -f, --format [type]  output format (default: "stylish")
  -h, --help           output usage information

Demo

Show Demo