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

@ufonion/jsondiff-report

v0.0.4

Published

Generate report of json-diff result for 2 directories/files

Downloads

2

Readme

jsondiff-report

A utility to diff JSON files in 2 directories.

Usage

@ufonion/jsondiff-report 0.0.3
Usage:
  jsondiff-report [--output, -o] [OUT_FILE] dir1 dir2
  jsondiff-report [--file, -f] [--output, -o] [OUT_FILE] file1 file2
  jsondiff-report [--help, -h]
Generate a JSON-diff report for 2 directories/files.

positional arguments:
  dir1/file1
  dir2/file2

optional arguments:
  -h, --help    show this help message and exit
  -f, --file    compare 2 files
  -o, --output  the report output file, if this option is absent,
                the programe will use the standard output

Output Format:

| Property       | Description                                                           |
| -------------- | --------------------------------------------------------------------- |
| baseDir        | The base dir: left for dir1 / file1, right for dir2 / file2.          |
| leftOnly       | List of files that only exists in baseDir.left.                       |
| rightOnly      | List of files that only exists in baseDir.right.                      |
| all            | List of files that exists in both baseDir.left and baseDir.right.     |
| jsonFileDiff   | The json-diff result for every file                                   |

Example

Diff 2 Files

File1: test/fixtures/a/1.json

{
  "a": 1,
  "b": [1, 2, 3]
}

File2: test/fixtures/b/1.json

{
  "a": 2,
  "b": [1, 3, 2],
  "c": {
    "d": "xxx"
  }
}

Execute as below.

$ jsondiff-report -f test/fixtures/a/1.json test/fixtures/b/1.json
{
  "baseDir": {
    "left": "test/fixtures/a/1.json",
    "right": "test/fixtures/b/1.json"
  },
  "jsonFileDiff": {
    "test/fixtures/a/1.json": {
      "c__added": {
        "d": "xxx"
      },
      "a": {
        "__old": 1,
        "__new": 2
      },
      "b": [
        [
          " ",
          1
        ],
        [
          "+",
          3
        ],
        [
          " ",
          2
        ],
        [
          "-",
          3
        ]
      ]
    }
  }
}

Diff 2 Dirs

Dir1

test/fixtures/a/
├── 1.json
├── 4.json
├── b
│   ├── 2.json
│   ├── 3.json
│   └── d
│       ├── 1.json
│       └── 2.json
└── c
    └── 1.json

3 directories, 7 files

Dir2

test/fixtures/b
├── 1.json
├── 3.json
└── b
    ├── 1.json
    ├── 2.json
    └── d
        ├── 1.json
        └── 3.json

2 directories, 6 files

Execute as below.

$ jsondiff-report test/fixtures/a/ test/fixtures/b/
{
  "baseDir": {
    "left": "test/fixtures/a/",
    "right": "test/fixtures/b/"
  },
  "leftOnly": [
    "4.json",
    "b/3.json",
    "b/d/2.json",
    "c/1.json"
  ],
  "rightOnly": [
    "3.json",
    "b/1.json",
    "b/d/3.json"
  ],
  "all": [
    "1.json",
    "b/2.json",
    "b/d/1.json"
  ],
  "jsonFileDiff": {
    "1.json": {
      "c__added": {
        "d": "xxx"
      },
      "a": {
        "__old": 1,
        "__new": 2
      },
      "b": [
        [
          " ",
          1
        ],
        [
          "+",
          3
        ],
        [
          " ",
          2
        ],
        [
          "-",
          3
        ]
      ]
    },
    "b/2.json": "Unexpected end of JSON input",
    "b/d/1.json": "Unexpected end of JSON input"
  }
}

Output Description

| Property | Description | | -------------- | --------------------------------------------------------------------- | | baseDir | The base dir: left for dir1/file1, right for dir2/file2. | | leftOnly | List of files that only exists in baseDir.left. | | rightOnly | List of files that only exists in baseDir.right. | | all | List of files that exists in both baseDir.left and baseDir.right. | | jsonFileDiff | The json-diff result for every file |

jsondiff-report interfaces/functions

API Docs generated by typedoc.