@vaziliybober/gendiff

1.1.1 • Public • Published

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

Package Sidebar

Install

npm i @vaziliybober/gendiff

Weekly Downloads

1

Version

1.1.1

License

ISC

Unpacked Size

26 kB

Total Files

33

Last publish

Collaborators

  • vaziliybober