Skip to content

A console utility that can compare and calculate the differences between two JSON or YAML files.

Notifications You must be signed in to change notification settings

ElenaManukyan/Difference-Calculator

Repository files navigation

Difference Calculator (gendiff)

Tests and code analysis:

Actions Status example workflow

Difference Calculator is a CLI utility for comparing two data structures. It identifies and displays the differences between them in various formats. This tool is widely used in real-world scenarios, such as tracking configuration changes or analyzing test results.

Features

  • Supports JSON and YAML input formats.
  • Generates output in three formats:
    • Stylish (tree-like structure)
    • Plain text (detailed textual description)
    • JSON (structured data for further processing)

Requirements

Node.js >= 14

Installation

  1. Make sure you have Node.js version 14 or higher installed.
  2. Clone the repository:
    git clone https://github.com/ElenaManukyan/Difference-Calculator.git
  3. Navigate to the project directory:
    cd Difference-Calculator
  4. Install dependencies:
    npm install

Development and Testing

Linting:

The project uses ESLint with Airbnb's coding standards. To lint the code, run:

npx eslint .

or:

make lint

Testing:

Tests are written using the Jest framework. To run all tests, execute:

npm test

or:

make test

Formatting:

To ensure consistent code style, use Prettier:

npx prettier --write .

Usage

The gendiff command compares two files and outputs their differences.

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

Compares two configuration files and shows a difference.

Options:
  -V, --version          output the version number
  -f, --format <format>  output format (default: "stylish")
  -h, --help             display help for command

Usage examples:

Creating difference between 2 flat .json files:

Creating difference between 2 flat .yml files:

Creating difference between 2 nested .json files:

Creating difference between 2 nested .yml files:

Creating difference between 2 nested .json files with '--format plain' parameter:

Creating difference between 2 nested .yml files with '--format plain' parameter:

Creating difference between 2 nested .json files with '--format json' parameter:

Creating difference between 2 nested .yml files with '--format json' parameter:

About

A console utility that can compare and calculate the differences between two JSON or YAML files.

Resources

Stars

Watchers

Forks

Packages

No packages published