UNPKG

1.45 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const chalk_1 = require("chalk");
4const os = require("os");
5const NormalizedMessage_1 = require("../NormalizedMessage");
6/**
7 * Creates new default formatter.
8 *
9 * @returns {defaultFormatter}
10 */
11function createDefaultFormatter() {
12 return function defaultFormatter(message, useColors) {
13 const colors = new chalk_1.default.constructor({ enabled: useColors });
14 const messageColor = message.isWarningSeverity()
15 ? colors.bold.yellow
16 : colors.bold.red;
17 const fileAndNumberColor = colors.bold.cyan;
18 const codeColor = colors.grey;
19 if (message.code === NormalizedMessage_1.NormalizedMessage.ERROR_CODE_INTERNAL) {
20 return (messageColor(`INTERNAL ${message.severity.toUpperCase()}: `) +
21 message.content +
22 (message.stack
23 ? os.EOL + 'stack trace:' + os.EOL + colors.gray(message.stack)
24 : ''));
25 }
26 return [
27 messageColor(`${message.severity.toUpperCase()} in `) +
28 fileAndNumberColor(`${message.file}(${message.line},${message.character})`) +
29 messageColor(':'),
30 codeColor(message.getFormattedCode() + ': ') + message.content
31 ].join(os.EOL);
32 };
33}
34exports.createDefaultFormatter = createDefaultFormatter;
35//# sourceMappingURL=defaultFormatter.js.map
\No newline at end of file