Node.js控制台变色(console-color-mr)

本插件可以在控制台自定义输出的颜色
在这里插入图片描述

安装

npm install -D console-color-mr

第一种用法

直接引入
require('console-color-mr');

修改了默认颜色。console.info会直接输出红色

//use color
console.info('------------ default color--------');
console.info('info', 'fff'); //green text
console.warn('this is warn');//yellowBG text
console.error('this is error');//red text
console.debug('this is debug');//gray text
console.log('this is log','msg1'.red, 'msg2'.blue);
console.info('this is info','msg1'.red, 'msg2'.blue); //force change default color
console.info('----------------------------');

在变量中或者函数中使用变色

console.group('---------variable use color------------');

let name = 'Michael';
let age  = 1000;

let obj = {
	name : 'michael',
	age  : '100'
};

function hello() {
	return 'hello';
}

function isBoole() {
	return true;
}

console.log(name);
console.log('Hello,My name is ' + name.green + ',I am a' + ' man'.yellow + '.');
console.log(age.blue);
console.log(obj.name.blue);
console.log(obj.name.greenBG);
console.log(hello().red);
//Boolean value must change to string.
console.log(isBoole().toString().red);

console.groupEnd();

第二种用法

第一种引入之后,会对原有的系统对象方法做修改。如果您仍然想使用系统对象上的方法的请用一个变量保存这个引用。
let _console = require('console-color-mr');

DEMO1

_console.info('info');
_console.debug('debug');
_console.warn('warn');
_console.error('error');

style

  • ‘bold’
  • ‘italic’
  • ‘underline’
  • ‘inverse’
  • ‘strikethrough’
  • ‘white’
  • ‘grey’
  • ‘black’
  • ‘blue’
  • ‘cyan’
  • ‘green’
  • ‘magenta’
  • ‘red’
  • ‘yellow’
  • ‘whiteBG’
  • ‘greyBG’
  • ‘blackBG’
  • ‘blueBG’
  • ‘cyanBG’
  • ‘greenBG’
  • ‘magentaBG’
  • ‘redBG’
  • ‘yellowBG’

相关文档
https://www.npmjs.com/package/console-color-mr

猜你喜欢

转载自blog.csdn.net/michael51/article/details/79035459