Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function main(grammar_mjs, fluent_ebnf) {
let grammar_source = fs.readFileSync(grammar_mjs, "utf8");
let grammar_ebnf = fs.readFileSync(fluent_ebnf, "utf8");
let diffs = difflib.unifiedDiff(
lines(grammar_ebnf),
lines(ebnf(grammar_source)), {
fromfile: "Expected",
tofile: "Actual",
});
for (let diff of diffs) {
if (diff.startsWith("+")) {
process.stdout.write(color.green(diff));
} else if (diff.startsWith("-")) {
process.stdout.write(color.red(diff));
} else {
process.stdout.write(diff);
}
}
function diffSnapshots (name, snapshotA, snapshotB) {
return difflib.unifiedDiff(
snapshotA == null ? null : snapshotA.split('\n'),
snapshotB == null ? null : snapshotB.split('\n'),
{
fromfile: name,
tofile: name,
lineterm: ''
}
).join('\n')
}
const compare = ({ past, current, options }) => {
const nextOptions = { ...defaultOptions, ...options };
const pastArray = past.split(/\r|\n|\r\n/);
const currentArray = current.split(/\r|\n|\r\n/);
const diffArray = unifiedDiff(pastArray, currentArray, {
fromfile: nextOptions.originalFileName,
tofile: nextOptions.updatedFileName
});
const diffString = format(
'diff --git %s %s\n%s',
nextOptions.originalFileName,
nextOptions.updatedFileName,
diffArray.join('\n')
);
return {
diffString,
options: nextOptions
};
};