-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformatter.js
48 lines (37 loc) · 1.13 KB
/
formatter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var indent = require('indent-string');
var pluralize = require('pluralize');
module.exports = function (options) {
options = options || {};
var defaultStackFilter = function (string) {
return string;
};
var defaultPrint = function (str) {
process.stdout.write(str);
};
var ansi = {
green: '\x1B[32m',
red: '\x1B[31m',
yellow: '\x1B[33m',
none: '\x1B[0m'
};
this.showColors = options.showColors === undefined ? true : options.showColors;
this.formatStack = options.stackFilter || defaultStackFilter;
this.print = options.print || defaultPrint;
this.printNewline = function () {
this.print('\n');
};
this.printLine = function (message) {
this.print(message);
this.printNewline();
};
this.colorize = function (color, str) {
return this.showColors ? (ansi[color] + str + ansi.none) : str;
};
this.pluralize = function (str, count) {
return pluralize(str, count);
};
this.indent = function (str, spaces) {
return spaces <= 0 ? str : indent(str, ' ', spaces);
};
};