jsout
Version:
A Syslog-compatible, small, and simple logger for Typescript/Javascript projects. Sponsored by https://aeroview.io
65 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getColorFunctions = getColorFunctions;
// Complete ANSI color codes for future extensibility
const colors = {
reset: '\x1b[0m',
bold: '\x1b[1m',
dim: '\x1b[2m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m',
gray: '\x1b[90m',
bgRed: '\x1b[41m',
bgGreen: '\x1b[42m',
bgYellow: '\x1b[43m',
bgBlue: '\x1b[44m',
bgMagenta: '\x1b[45m',
bgCyan: '\x1b[46m',
bgWhite: '\x1b[47m',
};
/**
* Portable color functions that work everywhere
* Uses ANSI codes in terminal environments, no-op in non-terminal environments
*/
function getColorFunctions() {
// Check if we're in a terminal environment that supports colors
const isTerminal = typeof process !== 'undefined'
&& process.stdout
&& process.stdout.isTTY
&& process.env.TERM !== 'dumb';
if (isTerminal) {
// Terminal environment - use ANSI colors
return {
bold: (str) => `${colors.bold}${str}${colors.reset}`,
bgGreenBright: (str) => `${colors.bgGreen}${str}${colors.reset}`,
black: (str) => `${colors.reset}${str}${colors.reset}`,
whiteBright: (str) => `${colors.white}${str}${colors.reset}`,
gray: (str) => `${colors.gray}${str}${colors.reset}`,
white: (str) => `${colors.white}${str}${colors.reset}`,
yellowBright: (str) => `${colors.yellow}${str}${colors.reset}`,
redBright: (str) => `${colors.red}${str}${colors.reset}`,
bgRedBright: (str) => `${colors.bgRed}${str}${colors.reset}`,
};
}
else {
// Non-terminal environment (browser, etc.) - no colors
const noop = (str) => str;
return {
bold: noop,
bgGreenBright: noop,
black: noop,
whiteBright: noop,
gray: noop,
white: noop,
yellowBright: noop,
redBright: noop,
bgRedBright: noop,
};
}
}
//# sourceMappingURL=colors.js.map