.build
.config
index.ts
tsconfig.json
Packager files
package-lock.json
package.json
Config files
.replit
replit.nix
import { assert } from 'console';
import diff from 'git-diff';
export function replDiff(
json1: any,
json2: any,
opts = { log: true }
): string | undefined {
const json1Str = JSON.stringify(json1, null, 2);
const json2Str = JSON.stringify(json2, null, 2);
const diffStr = diff(json1Str, json2Str, { color: true, flags: '-U1000' });
if (diffStr) {
if (opts.log) {
console.log(diffStr);
} else {
return diffStr;
}
}
return;
}
export function* replDiffGenerator(
jsons1: Map<string, any>[],
jsons2: Map<string, any>[],
opts = { log: true }
) {
assert(jsons1.length === jsons2.length, 'json arrays must be the same length to be diffable');
for (let i = 0; i < jsons1.length; i++) {
const result = replDiff(jsons1[i], jsons2[i], { log: false });
if (result) {
if (opts.log) {
console.log(result);
yield;
} else {
yield result;
}
}
}
}
console.log('\n');
console.log('/**');
console.log(' * THIS IS A DEMO!');
console.log(' *')
console.log(' * Start REPL by typing `node`.');
console.log(' *')
console.log(' * Type `differ = require("./.build/index.js")` to load the differ');
console.log(' *')
console.log(' */');
console.log('\n');