Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function handleDiff (file, original, formatted) {
var diff
var color = require('colorette')
if (original === formatted) {
diff = 'There is no difference with the original file.'
}
if (color.enabled) {
file = color.blue(file)
if(diff) {
diff = color.gray(diff)
} else {
var JsDiff = require('diff')
diff = JsDiff.createPatch(file, original, formatted)
diff = diff.split('\n').splice(4).map(function (line) {
if (line[0] === '+') {
line = color.green(line)
} else if (line[0] === '-') {
line = color.red(line)
} else if (line.match(/^@@\s+.+?\s+@@/) || '\\ No newline at end of file' === line) {
line = ''
}
return color.gray(line)
})