Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e83b01d
chore: archive CoffeeScript tests
jedluhmann Aug 28, 2026
d1c35e7
refactor: update code and tests to modern ES6 syntax
jedluhmann Aug 28, 2026
2d1cd5b
refactor: add semicolons
jedluhmann Aug 28, 2026
a672fa6
fix: export CLI and call it in bin/json-diff.ts
jedluhmann Aug 28, 2026
779c9d1
chore: cleanup to remove comment
jedluhmann Aug 28, 2026
6c527d8
chore: added launch config for debugging with bun
jedluhmann Aug 30, 2026
69fd384
fix: corrected test description and replaced let declarations with const
jedluhmann Aug 30, 2026
be6347f
refactor: optimizations for array diff logic (cache change and JSON.s…
jedluhmann Aug 30, 2026
6a52d5f
chore: remove comments explaining optimizations
jedluhmann Aug 30, 2026
b0a23b9
fix: call sort on array arguments, not scalarized sequences
jedluhmann Aug 30, 2026
5bd08fa
refactor: Simpify arrayDiff() by setting equal = false following the …
jedluhmann Aug 29, 2026
5f05247
fix: corrected position of prettier-ignore comments and ran lint:fix …
jedluhmann Aug 31, 2026
5046f96
refactor: optimization for objectDiff()
jedluhmann Aug 31, 2026
56aa041
chore: remove comment
jedluhmann Aug 31, 2026
5461478
fix: arguments for deepEqual were flipped, which was a bit confusing …
jedluhmann Sep 1, 2026
da01437
fix: solution 1 for objects with a high degree of correlation
jedluhmann Sep 1, 2026
549f43b
fix: solution 2 for objects with a high degree of correlation
jedluhmann Sep 1, 2026
fbfc2b5
chore: Added a conceptual overview to the README
jedluhmann Sep 3, 2026
097dae0
chore: didn't intend to commit this
jedluhmann Sep 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"include": ["lib/**/*.js"],
"exclude": ["/test/**/*.spec.js"],
"extension": [".js"],
"check-coverage": true,
"lines": 85,
"statements": 85,
"functions": 85,
"branches": 85,
"reporter": ["lcov", "text", "text-summary", "html"]
}
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
!bin/*.js
/lib-cov
test/*.js
coverage.html
.idea
.idea
coverage
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
package-lock.json
doc/
old-coffee-*/
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"useTabs": false,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 9999
}
48 changes: 29 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/bin/json-diff.js",
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"args": ["--raw-json", "--full", "a.json", "b.json"]
}
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/bin/json-diff.js",
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"args": ["--raw-json", "--full", "a.json", "b.json"]
},
{
"type": "bun",
"request": "launch",
"name": "Debug File",
"program": "${file}",
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
"stopOnEntry": false,
"watchMode": false
}
]
}
322 changes: 174 additions & 148 deletions README.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion bin/json-diff.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/usr/bin/env node
require('../lib/cli')(process.argv.slice(2));

import { CLI } from '../lib/cli.js';

CLI(process.argv.slice(2));
615 changes: 615 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import js from '@eslint/js';
import prettier from 'eslint-plugin-prettier/recommended';
import globals from 'globals';

export default [
js.configs.recommended,
prettier, // Enforces Prettier formatting rules via ESLint
{
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
...globals.node,
...globals.mocha, // Recognizes mocha primitives like 'describe' and 'it'
},
},
rules: {
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'no-console': 'warn',
},
},
];
59 changes: 30 additions & 29 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const fs = require('fs')
const tty = require('tty')
import fs from 'fs';
import tty from 'tty';

const { diff } = require('./index')
const { colorize } = require('./colorize')
import { diff } from './index';
import { colorize } from './colorize';

module.exports = function (argv) {
export const CLI = function (argv) {
const options = require('dreamopt')(
/* prettier-ignore */
[
'Usage: json-diff [-vCjfoxnskKp] first.json second.json',
' <first.json> Old file #var(file1) #required',
Expand All @@ -25,62 +26,62 @@ module.exports = function (argv) {
' -p, --precision DECIMALS Round all floating point numbers to this number of decimal places prior to comparison'
],
argv
)
);

options.outputKeys = options.outputKeys ? options.outputKeys.split(',') : []
options.excludeKeys = options.excludeKeys ? options.excludeKeys.split(',') : []
options.outputKeys = options.outputKeys ? options.outputKeys.split(',') : [];
options.excludeKeys = options.excludeKeys ? options.excludeKeys.split(',') : [];

if (options.verbose) {
process.stderr.write(`${JSON.stringify(options, null, 2)}\n`)
process.stderr.write(`${JSON.stringify(options, null, 2)}\n`);
}

if (options.verbose) {
process.stderr.write('Loading files...\n')
process.stderr.write('Loading files...\n');
}
const data1 = fs.readFileSync(options.file1, 'utf8')
const data2 = fs.readFileSync(options.file2, 'utf8')
const data1 = fs.readFileSync(options.file1, 'utf8');
const data2 = fs.readFileSync(options.file2, 'utf8');

if (options.verbose) {
process.stderr.write('Parsing old file...\n')
process.stderr.write('Parsing old file...\n');
}
const json1 = JSON.parse(data1)
const json1 = JSON.parse(data1);

if (options.verbose) {
process.stderr.write('Parsing new file...\n')
process.stderr.write('Parsing new file...\n');
}
const json2 = JSON.parse(data2)
const json2 = JSON.parse(data2);

if (options.verbose) {
process.stderr.write('Running diff...\n')
process.stderr.write('Running diff...\n');
}

const result = diff(json1, json2, options)
const result = diff(json1, json2, options);

if (options.color == null) {
options.color = tty.isatty(process.stdout.fd)
options.color = tty.isatty(process.stdout.fd);
}

if (result) {
if (options.raw) {
if (options.verbose) {
process.stderr.write('Serializing JSON output...\n')
process.stderr.write('Serializing JSON output...\n');
}
process.stdout.write(JSON.stringify(result, null, 2) + '\n')
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
} else {
if (options.verbose) {
process.stderr.write('Producing colored output...\n')
process.stderr.write('Producing colored output...\n');
}
const colorizeOptions = {
color: options.color,
maxElisions: options.maxElisions
}
process.stdout.write(colorize(result, colorizeOptions))
maxElisions: options.maxElisions,
};
process.stdout.write(colorize(result, colorizeOptions));
}
process.exit(1)
process.exit(1);
} else {
if (options.verbose) {
process.stderr.write('No diff')
process.stderr.write('No diff');
}
process.exit(0)
process.exit(0);
}
}
};
Loading