How to use the diff.diffCss function in diff

To help you get started, we’ve selected a few diff 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 tameraydin / ngToast / Gruntfile.js View on Github external
this.requires('cssbeautifier');

    var sassBaseCSS = grunt.file.read(paths.testSASS + 'ngToast.css');
    var sassAnimationsCSS = grunt.file.read(paths.testSASS + 'ngToast-animations.css');
    var lessBaseCSS = grunt.file.read(paths.testLESS + 'ngToast.css');
    var lessAnimationsCSS = grunt.file.read(paths.testLESS + 'ngToast-animations.css');
    grunt.file.delete('test/css-files');

    if (lessBaseCSS === sassBaseCSS && lessAnimationsCSS === sassAnimationsCSS) {
      // pass
      grunt.log.ok('LESS/SASS generated CSS matches.');
    } else {
      // fail
      var headerFooter = 'SASS differences\n'.magenta + 'LESS differences\n\n'.blue;
      var baseDiff = jsdiff.diffCss(lessBaseCSS, sassBaseCSS);
      var animationDiff = jsdiff.diffCss(lessAnimationsCSS, sassAnimationsCSS);

      grunt.log.write(headerFooter);

      baseDiff.forEach(function(line) {
        var color = line.added ? 'magenta' : line.removed ? 'blue' : 'gray';
        grunt.log.write(line.value[color]);
      });

      animationDiff.forEach(function(line) {
        var color = line.added ? 'magenta' : line.removed ? 'blue' : 'gray';
        grunt.log.write(line.value[color]);
      });

      grunt.log.write(headerFooter);
      grunt.fail.warn('Generated LESS/SASS CSS does not match!', 6);
    }
github tameraydin / ngToast / Gruntfile.js View on Github external
this.requires('sass:test');
    this.requires('cssbeautifier');

    var sassBaseCSS = grunt.file.read(paths.testSASS + 'ngToast.css');
    var sassAnimationsCSS = grunt.file.read(paths.testSASS + 'ngToast-animations.css');
    var lessBaseCSS = grunt.file.read(paths.testLESS + 'ngToast.css');
    var lessAnimationsCSS = grunt.file.read(paths.testLESS + 'ngToast-animations.css');
    grunt.file.delete('test/css-files');

    if (lessBaseCSS === sassBaseCSS && lessAnimationsCSS === sassAnimationsCSS) {
      // pass
      grunt.log.ok('LESS/SASS generated CSS matches.');
    } else {
      // fail
      var headerFooter = 'SASS differences\n'.magenta + 'LESS differences\n\n'.blue;
      var baseDiff = jsdiff.diffCss(lessBaseCSS, sassBaseCSS);
      var animationDiff = jsdiff.diffCss(lessAnimationsCSS, sassAnimationsCSS);

      grunt.log.write(headerFooter);

      baseDiff.forEach(function(line) {
        var color = line.added ? 'magenta' : line.removed ? 'blue' : 'gray';
        grunt.log.write(line.value[color]);
      });

      animationDiff.forEach(function(line) {
        var color = line.added ? 'magenta' : line.removed ? 'blue' : 'gray';
        grunt.log.write(line.value[color]);
      });

      grunt.log.write(headerFooter);
      grunt.fail.warn('Generated LESS/SASS CSS does not match!', 6);
github k0sukey / tss-formatter / lib / tssf.js View on Github external
tmp[index] = tssrc.indent + tssrc.indent + item;
				});
				newProperties.push(tssrc.indent + property.name + ': ' + '{\n' + tmp.join(',\n') + '\n' + tssrc.indent + '}');
			} else {
				newProperties.push(tssrc.indent + property.name + ': ' + typef(property, 0, tssrc));
			}
		});
		tmpStyle.push(tssrc.quote + selector + tssrc.quote + ': {\n' + newProperties.join(',\n') + '\n}');
	});

	newStyle = tmpStyle.join(tssrc.concatenation_comma ? ',\n' : '\n');

	var diff;

	if (!tssrc.strip_comment) {
		diff = jsdiff.diffCss(rawStyle, newStyle);

		newStyle = '';
		_.each(diff, function(part){
			if (part.removed &&
				part.value.match(/\/\*[\s\S]*?\*\/|\/\/.*/g)) {
				newStyle += part.value;
			} else if (!part.removed) {
				newStyle += part.value;
			}
		});
	}

	newStyle += tssrc.eof;

	if (cli.flags.diff) {
		console.info(chalk.cyan(style));
github k0sukey / tss-formatter / lib / tssf.js View on Github external
_.each(diff, function(part){
			if (part.removed &&
				part.value.match(/\/\*[\s\S]*?\*\/|\/\/.*/g)) {
				newStyle += part.value;
			} else if (!part.removed) {
				newStyle += part.value;
			}
		});
	}

	newStyle += tssrc.eof;

	if (cli.flags.diff) {
		console.info(chalk.cyan(style));

		diff = jsdiff.diffCss(rawStyle, newStyle);
		_.each(diff, function(part){
			var color = part.added ? 'green' : part.removed ? 'bgRed' : 'gray';
			process.stdout.write(chalk[color](part.value));
		});
	} else if (cli.flags.dryrun) {
		verbose(style, newStyle);
	} else {
		fs.writeFileSync(style, newStyle);
		cli.flags.verbose && verbose(style, newStyle);
	}
});
github gchq / CyberChef / src / core / operations / legacy / Diff.js View on Github external
} else {
                    diff = JsDiff.diffWordsWithSpace(samples[0], samples[1]);
                }
                break;
            case "Line":
                if (ignoreWhitespace) {
                    diff = JsDiff.diffTrimmedLines(samples[0], samples[1]);
                } else {
                    diff = JsDiff.diffLines(samples[0], samples[1]);
                }
                break;
            case "Sentence":
                diff = JsDiff.diffSentences(samples[0], samples[1]);
                break;
            case "CSS":
                diff = JsDiff.diffCss(samples[0], samples[1]);
                break;
            case "JSON":
                diff = JsDiff.diffJson(samples[0], samples[1]);
                break;
            default:
                return "Invalid 'Diff by' option.";
        }

        for (let i = 0; i < diff.length; i++) {
            if (diff[i].added) {
                if (showAdded) output += "<span class="hl5">" + Utils.escapeHtml(diff[i].value) + "</span>";
            } else if (diff[i].removed) {
                if (showRemoved) output += "<span class="hl3">" + Utils.escapeHtml(diff[i].value) + "</span>";
            } else {
                output += Utils.escapeHtml(diff[i].value);
            }