util: add 'none' style to styleText · nodejs/node@532c173 · GitHub
Skip to content

Commit 532c173

Browse files
jasnelltargos
authored andcommitted
util: add 'none' style to styleText
For cases where the style is not needed but code still calls styleText unconditionally, this adds a `none` style that not not apply any styling to the text. PR-URL: #58437 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 7a91f4a commit 532c173

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

doc/api/util.md

Lines changed: 5 additions & 0 deletions

lib/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ function lazyAbortController() {
100100
let internalDeepEqual;
101101

102102
/**
103-
* @param {string} code
103+
* @param {string} [code]
104104
* @returns {string}
105105
*/
106106
function escapeStyleCode(code) {
107+
if (code === undefined) return '';
107108
return `\u001b[${code}m`;
108109
}
109110

@@ -139,6 +140,7 @@ function styleText(format, text, { validateStream = true, stream = process.stdou
139140
let left = '';
140141
let right = '';
141142
for (const key of formatArray) {
143+
if (key === 'none') continue;
142144
const formatCodes = inspect.colors[key];
143145
// If the format is not a valid style, throw an error
144146
if (formatCodes == null) {

test/parallel/test-util-styletext.js

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)