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

Commit 54288bd

Browse files
jasnelladuh95
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 20d978d commit 54288bd

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
@@ -217,10 +217,11 @@ function pad(n) {
217217
}
218218

219219
/**
220-
* @param {string} code
220+
* @param {string} [code]
221221
* @returns {string}
222222
*/
223223
function escapeStyleCode(code) {
224+
if (code === undefined) return '';
224225
return `\u001b[${code}m`;
225226
}
226227

@@ -256,6 +257,7 @@ function styleText(format, text, { validateStream = true, stream = process.stdou
256257
let left = '';
257258
let right = '';
258259
for (const key of formatArray) {
260+
if (key === 'none') continue;
259261
const formatCodes = inspect.colors[key];
260262
// If the format is not a valid style, throw an error
261263
if (formatCodes == null) {

test/parallel/test-util-styletext.js

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)