1.0.8 • Published 4 years ago

plc_gendiff v1.0.8

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

frontend-project-lvl2

Node CI Maintainability Test Coverage


Install

  1. Simply copy-paste this in your bash/terminal:

    sudo npm i plc_gendiff

    or

    sudo npm i -g plc_gendiff

    if you want to use as a cli-app.

  2. Enter your system password.

  3. Use it as library in your code or right in your bash as a cli-application.

Uninstall:

Didn't like the app? Uninstall it:

sudo npm uninstall -g plc_gendiff

Library

If you want to use it as a library for your project, check following documentation with expamples.

Arguments

filepath1 (String): filepath to first (initial) file. Can be both absolute and relative.

filepath2 (String): filepath to second (changed) file. Can be both absolute and relative.

options (Object):

  • format (String): format of outputed result. Can be 'pretty', 'json', 'plain', for more details check up examples. By default, 'pretty'. Optional
  • sort (Boolean): sort output by keys. By default, true. Optional
  • spacesSign (String): sign used for formatting identations. By default, ' ' (one space). Optional
  • spacesCount (Number): count of spaces. Recommended to use even number: 2, 4 or higher. By default, 4. for pretty format, 0 – for json. Optional

Return

diff (String): difference between two configuration files. Format of output depends on format option.

Example

// file2.json { "z": true, "b": { "c": 5 }, "array": "now it is string" "or": "wanna some milk?", "add": { "object": "here", "nobody": "reads documentation..." } }

</details>

<details>
  <summary>Pretty format: </summary>

  ```javascript
  // app.js
  import gendiff from 'plc_gendiff';

  const prettyOptions = { format: 'pretty', spacesSign: '_' };
  const pretty = gendiff(path/to/file1, path/to/file2, prettyOptions);
```
{
__+ add: {
________nobody: reads documentation...
________object: here
____}
__- array: {
________change: this
____}
__+ array: now it is string
__- array_as_value: [1, 2, 3]
__+ array_as_value: [1, 2, 5]
____b: {
______- c: nested
______+ c: 5
____}
__- or: change this
__+ or: wanna some milk?
__- y: {
________delete: it
____}
____z: true
}
```
// app.js
import gendiff from 'plc_gendiff';

const plainOptions = { format: 'plain', sort: 'false' };
const plain = gendiff(path/to/file1, path/to/file2, plainOptions);
// app.js
import gendiff from 'plc_gendiff';

const jsonOptions = { format: 'json', sort: 2 };
const json = gendiff(path/to/file1, path/to/file2, jsonOptions);
[
  {
    "key": "add",
    "type": "added",
    "newValue": {
      "object": "here",
      "nobody": "reads documentation..."
    }
  },
  {
    "key": "array",
    "type": "changed",
    "oldValue": {
      "change": "this"
    },
    "newValue": "now it is string"
  },
  {
    "key": "array_as_value",
    "type": "changed",
    "oldValue": [
      1,
      2,
      3
    ],
    "newValue": [
      1,
      2,
      5
    ]
  },
  {
    "key": "b",
    "type": "nested",
    "children": [
      {
        "key": "c",
        "type": "changed",
        "oldValue": "nested",
        "newValue": 5
      }
    ]
  },
  {
    "key": "or",
    "type": "changed",
    "oldValue": "change this",
    "newValue": "wanna some milk?"
  },
  {
    "key": "y",
    "type": "deleted",
    "oldValue": {
      "delete": "it"
    }
  },
  {
    "key": "z",
    "type": "unchanged",
    "value": true
  }
]

CLI-application

If you want to use it right in your terminal, here's some documentation and exmaples for you.

Help

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, by default "pretty" (default: "pretty")
  
  -n, --sign <type>      sign used for formatting identations. By default, " " (one space) (default: " ")
  
  -s, --spaces <number>  count of spaces in pretty format, by default 4 for pretty format and 0 for json.
  
  -t, --sort <boolean>   sort output by keys. By default, true. (default: "true")
  
  -h, --help             display help for command

Example

gendiff -n _ ./__fixtures__/1.json ./__fixtures__/2.json

make me pretty

gendiff -f plain -t false ./__fixtures__/1.json ./__fixtures__/2.json
and
gendiff -f plain ./__fixtures__/1.json ./__fixtures__/2.json

make me plain

gendiff -f json ./__fixtures__/1.json ./__fixtures__/2.json

make me json

gendiff -f json -s 2 ./__fixtures__/1.json ./__fixtures__/2.json

make me pretty json