How to use the difflib.unifiedDiff function in difflib

To help you get started, we’ve selected a few difflib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github projectfluent / fluent / test / ebnf.js View on Github external
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);
        }
    }
github tessereact / tessereact / src / components / _lib / diff / index.js View on Github external
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')
}
github neighborhood999 / react-gh-like-diff / src / utils.js View on Github external
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
  };
};

difflib

text diff library ported from Python's difflib module

Unknown
Latest version published 12 years ago

Package Health Score

53 / 100
Full package analysis