Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions bin/jsonld.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Copyright (c) 2013-2022 Digital Bazaar, Inc.
* All rights reserved.
*/
import {createDeepComparer} from 'deep-comparer';
import {fileURLToPath} from 'node:url';
import https from 'node:https';
import {inspect} from 'node:util';
Expand Down Expand Up @@ -424,6 +425,26 @@ _jsonLdCommand(program.command('canonize [filename|URL|-]'))
await _output(result, cmd);
});

program.command('diff <filenameA> <filenameB>')
.description('compare two JSON-LD documents in expanded form')
.action(async function diff(filenameA, filenameB, cmd) {
const options = _jsonLdOptions(cmd, filenameA);
options.keepFreeFloatingNodes = cmd.keepFreeFloatingNodes;

const resultA = await jsonld.expand(filenameA, options);
const resultB = await jsonld.expand(filenameB, options);

const deepCompare = createDeepComparer();
const differences = await deepCompare(resultA, resultB);

if(differences.length > 0) {
console.log('Differences found:');
console.dir(differences, {depth: 5});
} else {
console.log('No differences found.');
}
});

program
.parseAsync(process.argv)
.catch(e => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"type": "module",
"dependencies": {
"commander": "^11.1.0",
"deep-comparer": "^2.0.3",
"jsonld": "^8.3.2",
"jsonld-request": "^2.0.1"
},
Expand Down