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

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -2408,6 +2408,9 @@ added:

24082408

- v21.7.0

24092409

- v20.12.0

24102410

changes:

2411+

- version: REPLACEME

2412+

pr-url: https://github.com/nodejs/node/pull/58437

2413+

description: Added the `'none'` format as a non-op format.

24112414

- version:

24122415

- v23.5.0

24132416

- v22.13.0

@@ -2483,6 +2486,8 @@ console.log(

24832486

);

24842487

```

24852488
2489+

The special format value `none` applies no additional styling to the text.

2490+
24862491

The full list of formats can be found in [modifiers][].

24872492
24882493

## Class: `util.TextDecoder`

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) {

Original file line numberDiff line numberDiff line change

@@ -75,6 +75,8 @@ assert.strictEqual(

7575

styled,

7676

);

7777
78+

assert.strictEqual(util.styleText('none', 'test'), 'test');

79+
7880

const fd = common.getTTYfd();

7981

if (fd !== -1) {

8082

const writeStream = new WriteStream(fd);