How to use disparity - 8 common examples

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 juliuste / geojson-svgify / test / index.js View on Github external
const assertEqualString = (a, b) => {
	if (a === b) return
	process.stdout.write(disparity.chars(a, b) + '\n')
	process.exit(1)
}
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
  };
}
github fabsrc / graphql-schema-diff / src / diff.ts View on Github external
];
  }

  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
  };
}
github bahmutov / snap-shot-compare / src / utils.js View on Github external
function textDifference (expected, value, noColor) {
  const diff = noColor ? disparity.unifiedNoColor : disparity.unified
  const textDiff = diff(expected, value)
  return removeExplanation(textDiff)
}

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