npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plc_gendiff

v1.0.8

Published

Compares two configuration files and shows a difference.

Downloads

5

Readme

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

// file1.json
{
  "z": true,
  "b": {
    "c": "nested"
  },
  "y": {
    "delete": "it"
  },
  "array": {
    "change": "this"
  },
  "or": "change this",
}

// file2.json
{
  "z": true,
  "b": {
    "c": 5
  },
  "array": "now it is string"
  "or": "wanna some milk?",
  "add": {
    "object": "here",
    "nobody": "reads documentation..."
  }
}
// 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);
Property 'b.c' was updated. From 'nested' to 5
Property 'y' was removed
Property 'array' was updated. From [complex value] to 'now it is string'
Property 'or' was updated. From 'change this' to 'wanna some milk?'
Property 'array_as_value' was updated. From [1, 2, 3] to [1, 2, 5]
Property 'add' was added with value: [complex value]
// 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