How to use the disparity.unified function in disparity

To help you get started, we’ve selected a few disparity 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 MithrilJS / mithril-codemods / test / index.js View on Github external
fn(t.name, () => {
                    var input = `./transforms/${t.name}/_input.js`,
                        result, diff;
                    
                    result = transform({
                        path   : input,
                        source : fs.readFileSync(input, "utf8")
                    }, {
                        jscodeshift,
                        stats
                    });

                    diff = disparity.unified(
                        fs.readFileSync(`./transforms/${t.name}/_output.js`, "utf8").trim(),
                        result.trim(),
                        {
                            paths : [
                                `./transforms/${t.name}/_input.js (transformed)`,
                                `./transforms/${t.name}/_output.js`
                            ]
                        }
                    );

                    o(diff).equals("")(`\n${diff}`);
                })
            })
github Urigo / graphql-cli / src / cmds / diff.ts View on Github external
const target = config.endpointsExtension.getEndpoint(argv.target)
    toDesc = `${argv.target} (${target.url})`
    toSchema = await target.resolveSchema()
  } else {
    toDesc = relative(process.cwd(), config.schemaPath as string)
    toSchema = config.getSchema()
  }

  const fromSDL = printSchema(fromSchema)
  const toSDL = printSchema(toSchema)
  if (fromSDL === toSDL) {
    console.log(chalk.green('✔ No changes'))
    return
  }

  let diff = disparity.unified(fromSDL, toSDL, { paths: [fromDesc, toDesc] })
  console.log(diff)

  const dangerousChanges = findDangerousChanges(fromSchema, toSchema)
  if (dangerousChanges.length !== 0) {
    console.log(chalk.yellow('Dangerous changes:'))
    for (const change of dangerousChanges) {
      console.log(chalk.yellow('  ⚠ ' + change.description))
    }
  }

  const breakingChanges = findBreakingChanges(fromSchema, toSchema)
  if (breakingChanges.length !== 0) {
    console.log(chalk.red('BREAKING CHANGES:'))
    for (const change of breakingChanges) {
      console.log(chalk.red('  ✖ ' + change.description))
    }
github bahmutov / snap-shot / src / file-system.js View on Github external
function compareText (expected, value) {
  const textDiff = disparity.unified(expected, value)
  if (!textDiff) {
    return {changed: false}
  }
  return {
    changed: true,
    text: textDiff
  }
}
github bahmutov / snap-shot-core / src / multi-line-text-spec.js View on Github external
function compareText (options) {
  const expected = options.expected
  const value = options.value

  const textDiff = disparity.unified(expected, value)
  return textDiff ? Result.Error(textDiff) : Result.Ok()
}
github fabsrc / graphql-schema-diff / src / diff.ts View on Github external
[leftSchema, rightSchema] = [
      lexicographicSortSchema(leftSchema),
      lexicographicSortSchema(rightSchema)
    ];
  }

  const [leftSchemaSDL, rightSchemaSDL] = [
    printSchema(leftSchema),
    printSchema(rightSchema)
  ];

  if (leftSchemaSDL === rightSchemaSDL) {
    return;
  }

  const diff = disparity.unified(leftSchemaSDL, rightSchemaSDL, {
    paths: [leftSchemaLocation, rightSchemaLocation]
  });
  const diffNoColor = disparity.unifiedNoColor(leftSchemaSDL, rightSchemaSDL, {
    paths: [leftSchemaLocation, rightSchemaLocation]
  });
  const dangerousChanges = findDangerousChanges(leftSchema, rightSchema);
  const breakingChanges = findBreakingChanges(leftSchema, rightSchema);

  return {
    diff,
    diffNoColor,
    dangerousChanges,
    breakingChanges
  };
}

disparity

Colorized string diff ideal for text/code that spans through multiple lines

MIT
Latest version published 4 years ago

Package Health Score

54 / 100
Full package analysis