UNPKG

traceperf

Version:

High-performance function execution tracking and monitoring for Node.js

160 lines 3.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.colorize = colorize; exports.bold = bold; exports.dim = dim; exports.underline = underline; exports.red = red; exports.green = green; exports.yellow = yellow; exports.blue = blue; exports.magenta = magenta; exports.cyan = cyan; exports.gray = gray; exports.supportsColor = supportsColor; const constants_1 = require("../core/constants"); /** * Utilities for working with terminal colors */ /** * Apply color to a string * * @param text - The text to colorize * @param color - The color to apply * @returns The colorized string */ function colorize(text, color) { if (typeof supportsColor === 'function' ? !supportsColor() : false) { return text; } return `${color}${text}${constants_1.COLORS.reset}`; } /** * Apply bold formatting to a string * * @param text - The text to make bold * @returns The bold string */ function bold(text) { if (typeof supportsColor === 'function' ? !supportsColor() : false) { return text; } return `${constants_1.COLORS.bright}${text}${constants_1.COLORS.reset}`; } /** * Apply dim formatting to a string * * @param text - The text to make dim * @returns The dim string */ function dim(text) { if (typeof supportsColor === 'function' ? !supportsColor() : false) { return text; } return `${constants_1.COLORS.dim}${text}${constants_1.COLORS.reset}`; } /** * Apply underline formatting to a string * * @param text - The text to underline * @returns The underlined string */ function underline(text) { if (typeof supportsColor === 'function' ? !supportsColor() : false) { return text; } return `${constants_1.COLORS.underscore}${text}${constants_1.COLORS.reset}`; } /** * Apply red color to a string * * @param text - The text to colorize * @returns The red string */ function red(text) { return colorize(text, constants_1.COLORS.fg.red); } /** * Apply green color to a string * * @param text - The text to colorize * @returns The green string */ function green(text) { return colorize(text, constants_1.COLORS.fg.green); } /** * Apply yellow color to a string * * @param text - The text to colorize * @returns The yellow string */ function yellow(text) { return colorize(text, constants_1.COLORS.fg.yellow); } /** * Apply blue color to a string * * @param text - The text to colorize * @returns The blue string */ function blue(text) { return colorize(text, constants_1.COLORS.fg.blue); } /** * Apply magenta color to a string * * @param text - The text to colorize * @returns The magenta string */ function magenta(text) { return colorize(text, constants_1.COLORS.fg.magenta); } /** * Apply cyan color to a string * * @param text - The text to colorize * @returns The cyan string */ function cyan(text) { return colorize(text, constants_1.COLORS.fg.cyan); } /** * Apply gray color to a string * * @param text - The text to colorize * @returns The gray string */ function gray(text) { return colorize(text, constants_1.COLORS.fg.gray); } /** * Check if terminal supports colors * * @returns Whether the terminal supports colors */ function supportsColor() { if (process.env.FORCE_COLOR === '0') { return false; } if (process.env.FORCE_COLOR) { return true; } if (process.platform === 'win32') { return true; } if ('CI' in process.env) { return true; } if (process.env.COLORTERM) { return true; } if (process.env.TERM === 'dumb') { return false; } if (process.stdout.isTTY) { return true; } return false; } //# sourceMappingURL=colors.js.map