Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function coloredDiffLog(one,other) {
should(typeof(one)=="string");
should(typeof(other)=="string");
var diff = jsdiff.diffWords(one, other);
diff.forEach(function (part) {
// green for additions, red for deletions
// grey for common parts
var color = part.added ? 'green' :
part.removed ? 'red' : 'grey';
process.stderr.write(part.value[color]);
});
console.info();
}
const handleTEXT = (oldText, newText, source) => {
const oldStr = oldText.text,
newStr = newText.text;
let root = toHTML(source);
let color = '',
container = null,
diff = jsdiff.diffWords(oldStr, newStr),
temp = document.createElement('div');
diff.forEach((part) => {
// green for additions, red for deletions
color = part.added ? 'ins' : part.removed ? 'del' : '';
container = document.createElement('span');
container.className = color;
container.appendChild(document.createTextNode(part.value));
temp.appendChild(container);
});
const markedText = temp.innerHTML;
$(root).find(`*:contains(${oldStr})`)
.filter(function() { return $(this).text() === oldStr; })
if (expected_type === 'object') {
const delta = jsondiffpatch.diff(actual[failed_test_number], expected[failed_test_number])
const output = jsondiffpatch.formatters.console.format(delta)
println(output, 4)
} else if (expected_type === 'array') {
const compared = diffJson(actual, expected)
.map(writeDiff)
.join('');
println(compared, 4);
} else if (expected === 'undefined' && actual === 'undefined') {
;
} else if (expected_type === 'string') {
const compared = diffWords(actual, expected)
.map(writeDiff)
.join('');
println(compared, 4);
} else {
println(
chalk.red.inverse(actual) + chalk.green.inverse(expected),
4
);
}
};
return chalk.greenBright(charChange.value)
})
.join('')
}
}
return chalk.greenBright(change.value)
}
if (change.removed) {
if (
change.value.split('\n').length <= 2 &&
index > 0 &&
changes[index + 1] &&
changes[index + 1].added &&
changes[index + 1].value.split('\n').length <= 2
) {
const charChanges = diffWords(change.value, changes[index + 1].value)
if (charChanges.length < change.value.length - 3) {
return charChanges
.map(charChange => {
if (charChange.removed) {
return strongRed(charChange.value)
}
if (charChange.added) {
return ''
}
return chalk.redBright(charChange.value)
})
.join('')
}
}
function formatExpectedType(expected, actual) {
const diff = jsdiff.diffWords(formatType(actual), formatType(expected));
return (
'<div class="linter-elm-make-details-expected-type">' +
diff
.map(part => {
if (part.added) {
return (
'<span class="linter-elm-make-expected-type-diff-changed">' +
_.escape(part.value) +
'</span>'
);
} else if (!part.removed) {
return '<span>' + _.escape(part.value) + '</span>';
}
return '';
})
.join('') +</div>
const DiffField = ({ one, two, view, schema }) => {
let parts;
if (schema.widget) {
switch (schema.widget) {
case 'richtext':
parts = diffWords(one.data, two.data);
break;
case 'datetime':
parts = diffWords(
moment(one).format('LLLL'),
moment(two).format('LLLL'),
);
break;
case 'textarea':
default:
parts = diffWords(one, two);
break;
}
} else if (schema.type === 'boolean') {
parts = diffWords(one ? 'Yes' : 'No', two ? 'Yes' : 'No');
} else if (schema.type === 'array') {
parts = diffWords(join(one, ', '), join(two, ', '));
areStringsEqual(a: string, b: string) {
const diffs = diff.diffWords(a, b);
for (const d of diffs) {
if (d.added || d.removed) {
return false;
}
}
return true;
}
}
if (file.binary === undefined) {
file.binary = binaryDiff.isBinary(file.path, file.contents);
}
const actual = fs.readFileSync(path.resolve(filepath));
if (!(contents instanceof Buffer)) {
contents = Buffer.from(contents || '', 'utf8');
}
if (file.binary) {
return actual.toString('hex') !== contents.toString('hex');
}
if (this.ignoreWhitespace) {
file.changes = jsdiff.diffWords(
actual.toString(),
contents.toString(),
this.diffOptions
);
} else {
file.changes = jsdiff.diffLines(
actual.toString(),
contents.toString(),
this.diffOptions
);
}
const changes = file.changes;
return changes.length > 1 || changes[0].added || changes[0].removed;
}
const DiffField = ({ one, two, view, schema }) => {
let parts;
if (schema.widget) {
switch (schema.widget) {
case 'richtext':
parts = diffWords(one.data, two.data);
break;
case 'datetime':
parts = diffWords(
moment(one).format('LLLL'),
moment(two).format('LLLL'),
);
break;
case 'textarea':
default:
parts = diffWords(one, two);
break;
}
} else if (schema.type === 'boolean') {
parts = diffWords(one ? 'Yes' : 'No', two ? 'Yes' : 'No');
} else if (schema.type === 'array') {
parts = diffWords(join(one, ', '), join(two, ', '));
} else {
parts = diffWords(one, two);
}
return (
{schema.title}
<table>
</table>
function compare (text1, text2) {
return diffWords(text1, text2, { ignoreCase: true })
}