1Introduction
- description:Node 控制台
- author:ydr.me
- create:2015-12-10 21:35
- update:2015-12-10 21:35
- github:
https://github.com/blearjs/blear.node.console
2Example
var console = require('blear.node.console');
3Static
3.1.colors
- 类型:
Object - 说明:颜色配置,有
black、red、grey、cyan、green、blue、yellow、inverse、magenta、bgBlack、blackBG、bgRed、redBG、bgGreen、greenBG、bgYellow、yellowBG、bgBlue、blueBG、bgMagenta、magentaBG、bgCyan、cyanBG、bgWhite、whiteBG、bold、dim、italic、underline、hidden、original
3.2.format()
console.format('a', 'b');
// => "a b"
- 类型:
Function - 说明:控制台格式化
3.3.pretty(out..., colors): prettied
console.pretty('1', 'black');
console.pretty('1', '2', ['red', 'bgBlue']);
3.3.1out
- 类型:
* - 说明:输出结果
3.3.2colors
- 类型:
String | Array - 说明:附加颜色
3.3.3prettied
- 类型:
String - 说明:附加颜色后的字符串
3.4.config(key, [val]): ret
配置默认值。默认配置为:
var configs = {
// 是否颜色输出
// PM2 环境不建议输出颜色,否则日志文件内有很多颜色代码
colorful: true,
// 日志级别
// 生产环境建议只打印出 warn、error 日志
level: [
'log',
'info',
'warn',
'error'
],
timePrefix: 'YYYY-MM-DD HH:mm:ss.SSS',
timeColors: ['cyan', 'bold'],
logColors: [],
infoColors: ['green', 'bold'],
warnColors: ['yellow', 'bold'],
errorColors: ['red', 'bold']
};
3.4.1key
- 类型:
String - 说明:键名
3.4.2val
- 类型:
String - 说明:键值,如果有值,则为设置默认值
3.4.3ret
- 类型:
String - 说明:键值,返回
key对应的默认配置
3.5.log(): undefined
- 类型:
Function - 说明:打印普通类型日志

3.6.info(): undefined
- 类型:
Function - 说明:打印信息类型日志
3.7.warn(): undefined
- 类型:
Function - 说明:打印警告类型日志
3.8.error(): undefined
- 类型:
Function - 说明:打印错误类型日志
3.9.logWithTime(): undefined
- 类型:
Function - 说明:打印时间 + 普通类型日志
3.10.infoWithTime(): undefined
- 类型:
Function - 说明:打印时间 + 信息类型日志
3.11.warnWithTime(): undefined
- 类型:
Function - 说明:打印时间 + 警告类型日志
3.12.errorWithTime(): undefined
- 类型:
Function - 说明:打印时间 + 错误类型日志
3.13.table(trs, [options]): undefined
打印表格。
console.table([
['#', 'username', 'password'],
['1', 'John Smith', '123901'],
['2', 'Tom Mass', 'mmm112333']
]);

console.table([
['#', 'username', 'password'],
['1', 'John Smith', '123901'],
['2', 'Tom Mass', 'mmm112333']
], {
padding: 5,
thead: true,
border: true,
colors: ['bgBlue', 'yellow']
});

- 类型:
Function - 说明:打印表格类型日志
3.13.1trs
- 类型:
Array - 说明:表格行数组
3.13.2options
- 类型:
Object - 说明:打印配置,默认为
defaults = { // 内边距 padding: 1, // 是否有表头 thead: false, // 外边框 border: false, // 附加颜色 colors: [] }
3.14.point(str): undefined
打点。
3.14.1str
- 类型:
String - 说明:点
- 默认:
"."
var points = ['-', '=', '>', '|', '<', '='];
var times = 0;
var time = setInterval(function () {
var index = times % (points.length - 1);
console.point(points[index]);
if (times === 30) {
clearInterval(time);
console.pointEnd();
}
times++;
}, 300);

3.15.pointEnd(): undefined
结束打点。
3.16.lineStart(): undefined
开始划线。

3.17.line([str]): undefined
划线。
3.17.1str
- 类型:
String - 说明:点
- 默认:
"="
3.18.lineEnd(): undefined
停止划线。
3.19.loading(interval, [dictionaries])
loading 显示。

3.19.1interval
- 类型:
Number - 说明:间隔时间
- 默认:
80
3.19.2dictionaries
- 类型:
Array - 说明:字典
- 默认:
['-', '\\', '|', '/', '-', '\\', '|', '/']
3.20.loadingEnd(): undefined
停止 loading。
4Dependencies
- blear.utils.access
- blear.utils.array
- blear.utils.collection
- blear.utils.date
- blear.utils.object
- blear.utils.typeis
strip-ansi
wcwidth
5Reference
无。