Skip to content

Instantly share code, notes, and snippets.

@RafaPegorari
Created April 7, 2017 16:04
Show Gist options
  • Save RafaPegorari/0aa93483839e12c49afb19d39f3de5ef to your computer and use it in GitHub Desktop.
Save RafaPegorari/0aa93483839e12c49afb19d39f3de5ef to your computer and use it in GitHub Desktop.
/**
* Color
*
* @author: Rafael Pegorari <rafapegorari@gmail.com>
* @copyright Copyright (c) 2015-2017, MEANStack.io.
* @license See LICENSE
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
*/
var util = require('util');
/**
* Style of color for console.
*
* @returns {{}}
* @constructor
*/
class Color {
constructor() {
/**
* Colors
*
* @type {{red: string, green: string, yellow: string, blue: string, black: string}}
*/
this.colors = {
red: '\x1B[31m',
green: '\x1B[32m',
yellow: '\x1B[33m',
blue: '\x1B[34m',
black: '\x1B[39m'
};
return this.generate();
}
/**
* Generate method colors.
*
* @returns {{}}
*/
generate () {
let methods = {};
Object.keys(this.colors).forEach((index) => {
return methods[index] = (str) => {
return util.format('%s%s%s', this.colors[index], str, this.colors.black);
}
});
return methods;
};
}
module.exports = new Color();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment