Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var differ = through(function(ch) {
lines++
if (ch[0] === ch[1]) linesMatched++
if (lines < cutoff) {
var diff = jsDiff.diffChars(ch[1], ch[0])
diff.forEach(function(part){
var color = 'green'
if (part.added) color = 'brightRedBg white'
if (part.removed) color = 'brightRedBg white'
// var color = 'grey'
// if (part.added) color = 'green'
// if (part.removed) color = 'red'
process.stdout.write(styled(color, part.value))
})
console.log('')
}
}, function() {
differ.queue(null)
DocsComparer.prototype.compareDomSubset = function (sourceDom, targetDom, subset, relativePath, options) {
var sourceHtml = sourceDom(subset).html();
var targetHtml = targetDom(subset).html();
var diff;
var changed = false;
diff = jsdiff.diffChars(sourceHtml, targetHtml);
diff.forEach(function (part) {
changed = part.added || part.removed;
});
if (changed) {
console.error("Subset of DOM '" + subset + "' for path " + relativePath + ' is different.');
if (options.verbose > 0) {
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.log();
}
}
updateCacheTextArray(newText) {
let {textArray, lastKey} = this.state;
let currentIndex = 0;
diffChars(
textArray.map(keyValue => keyValue[1]).join(''),
newText,
).forEach(({added, removed, count, value}) => {
if (removed) {
textArray = count
? [
...textArray.slice(0, currentIndex),
...textArray.slice(currentIndex + count),
]
: []; // if count is undefined, it means text is empty
return;
}
if (added) {
textArray = [
...textArray.slice(0, currentIndex),
updateState: function (element) {
var nextStr = Util.createHTMLWordString(element), // text representation of current DOM
currStr = this.doc.toString(), // text representation of the current tree
diff = JsDiff.diffChars(currStr, nextStr), // JsDiff of two strings
index = 0;
/* Iterate through array of diffs detected by JSDiff
*
* Each 'diff' is an object that represents a part of the string:
*
* {
* added: true/undefined (True if this represents a chunk of text that was added)
* removed: true/undefined (True if this represents a chunk of text that was removed)
* value: string (The chunk of text this diff covers)
* count: int (The length of this chunk of text)
* }
*
* NOTE: If added and removed are both undefined this chunk of text text was unchanged
*/
diff.forEach(function (action) {
Change.prototype.htmlDiffText = function htmlDiffText(maxChars) {
debug("htmlDiffText");
var from = "";
var to = "";
if (this.from) from = String(this.from);
if (this.to) to = String(this.to);
if (from.length > 2000 || to.length > 2000) {
return "Disabled for texts longer than 2000 chars.";
}
// first check on only spaces
var diff = jsdiff.diffChars(from, to);
var onlySpacesAdd = true;
var onlySpacesDel = true;
diff.forEach(function(part) {
var partOnlySpace = (part.value.trim() === "");
if (part.removed) {
onlySpacesAdd = false;
if (!partOnlySpace) onlySpacesDel = false;
}
if (part.added) {
onlySpacesDel = false;
if (!partOnlySpace) onlySpacesAdd = false;
}
});
if (onlySpacesAdd) {
return '<span class="osmbc-inserted">ONLY SPACES ADDED</span>';
function createFilesDiff({ fixtureFile, targetFile }) {
const filesDiff = diff.diffChars(targetFile.source, fixtureFile.source)
if (!filesDiff || filesDiff.length === 0) {
return null
}
const outputDiff = filesDiff.reduce((acc, part) => {
if (part.added) {
return acc + chalk.bgGreen(chalk.black(part.value))
} else if (part.removed) {
return acc + chalk.bgRed(chalk.black(part.value))
}
return acc + part.value
}, '')
return {
function onlyPeriodsAdded({ misspelling, suggestions: [suggestion] }) {
if (!suggestion) {
return false;
}
const diff = diffChars(misspelling, suggestion);
return _(diff).filter('removed').isEmpty() &&
_(diff).filter('added').every(({ value }) => /^\.+$/.test(value));
}
getChangeRange(oldSnapshot) {
if (!oldSnapshot) return undefined;
const diffs = jsdiff.diffChars(oldSnapshot.text, this.text);
if (diffs.length) {
let ind = 0;
let changes = [];
for (let i = 0; i < diffs.length; i++) {
const diff = diffs[i];
if (diff.added) {
changes.push(ts.createTextChangeRange(ts.createTextSpan(ind, 0), diff.count));
ind += diff.count;
continue;
}
if (diff.removed) {
changes.push(ts.createTextChangeRange(ts.createTextSpan(ind, diff.count), 0));
continue;
}
function htmlDiff(earlier,later){
var diff = jsdiff.diffChars(earlier,later)
var outputHTML = ''
diff.forEach(function(part){
var stylestr = part.added?'DiffAdded':part.removed?'DiffRemoved':null
part.value = render.plain_render(part.value)
outputHTML += (stylestr?`<span class="${stylestr}">${part.value}</span>`:part.value)
})
return outputHTML
}
function doDiff() {
var diff = JsDiff.diffChars(self.prev.text, self.current.text);
var fragment = document.createDocumentFragment();
for (var i=0; i < diff.length; i++) {
if (diff[i].added && diff[i + 1] && diff[i + 1].removed) {
var swap = diff[i];
diff[i] = diff[i + 1];
diff[i + 1] = swap;
}
var node;
if (diff[i].removed) {
node = document.createElement('del');
node.appendChild(document.createTextNode(diff[i].value));
} else if (diff[i].added) {
node = document.createElement('ins');