From b36ba020db82ddbbe4d093db38859d29b40a711c Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Wed, 27 Nov 2024 21:48:21 +0100 Subject: [PATCH] lib: refactor code to improve readability PR-URL: https://github.com/nodejs/node/pull/55995 Reviewed-By: Luigi Pinca Reviewed-By: LiviaMedeiros --- lib/internal/util/colors.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/internal/util/colors.js b/lib/internal/util/colors.js index 812048c923bee7..0b37694b513fb0 100644 --- a/lib/internal/util/colors.js +++ b/lib/internal/util/colors.js @@ -24,16 +24,27 @@ module.exports = { stream.getColorDepth() > 2 : true); }, refresh() { - const hasColors = module.exports.shouldColorize(process.stderr); - module.exports.blue = hasColors ? '\u001b[34m' : ''; - module.exports.green = hasColors ? '\u001b[32m' : ''; - module.exports.white = hasColors ? '\u001b[39m' : ''; - module.exports.yellow = hasColors ? '\u001b[33m' : ''; - module.exports.red = hasColors ? '\u001b[31m' : ''; - module.exports.gray = hasColors ? '\u001b[90m' : ''; - module.exports.clear = hasColors ? '\u001bc' : ''; - module.exports.reset = hasColors ? '\u001b[0m' : ''; - module.exports.hasColors = hasColors; + if (module.exports.shouldColorize(process.stderr)) { + module.exports.blue = '\u001b[34m'; + module.exports.green = '\u001b[32m'; + module.exports.white = '\u001b[39m'; + module.exports.yellow = '\u001b[33m'; + module.exports.red = '\u001b[31m'; + module.exports.gray = '\u001b[90m'; + module.exports.clear = '\u001bc'; + module.exports.reset = '\u001b[0m'; + module.exports.hasColors = true; + } else { + module.exports.blue = ''; + module.exports.green = ''; + module.exports.white = ''; + module.exports.yellow = ''; + module.exports.red = ''; + module.exports.gray = ''; + module.exports.clear = ''; + module.exports.reset = ''; + module.exports.hasColors = false; + } }, };