How to use the colorette.enabled function in colorette

To help you get started, we’ve selected a few colorette 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 morishitter / stylefmt / bin / cli.js View on Github external
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)
      })