Compare commits

...

4 Commits

Author SHA1 Message Date
Meghan Denny
11b7c130e0 Revert "tidy"
This reverts commit 2d21bf0d75a3f6a55f8fe9f79d47846ad9f4f68d.
2025-10-07 05:23:59 +00:00
Meghan Denny
7ae3a4d54d tidy 2025-10-07 05:23:59 +00:00
autofix-ci[bot]
8730239acb [autofix.ci] apply automated fixes 2025-10-07 05:23:59 +00:00
Claude Bot
1195fa0ee6 Add 'none' option to util.styleText
Add support for the special format value 'none' in util.styleText() which applies no additional styling to the text. This matches Node.js behavior where 'none' can be used both as a single format and within arrays of formats.

Changes:
- Add 'none' format handling in single format case (returns text unchanged)
- Add 'none' format skipping in array format case (continues to next format)
- Add comprehensive tests for both single and array usage
- Maintain backward compatibility with existing functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-07 05:23:59 +00:00
2 changed files with 10 additions and 0 deletions

View File

@@ -202,6 +202,7 @@ function styleText(format, text) {
let left = "";
let right = "";
for (const key of format) {
if (key === "none") continue;
const formatCodes = inspect.colors[key];
if (formatCodes == null) {
validateOneOf(key, "format", ObjectKeys(inspect.colors));
@@ -213,6 +214,10 @@ function styleText(format, text) {
return `${left}${text}${right}`;
}
if (format === "none") {
return text;
}
let formatCodes = inspect.colors[format];
if (formatCodes == null) {

View File

@@ -41,3 +41,8 @@ assert.throws(() => {
}, {
code: 'ERR_INVALID_ARG_VALUE',
});
assert.strictEqual(util.styleText('none', 'test'), 'test');
assert.strictEqual(util.styleText(['none'], 'test'), 'test');
assert.strictEqual(util.styleText(['none', 'red'], 'test'), '\u001b[31mtest\u001b[39m');
assert.strictEqual(util.styleText(['red', 'none'], 'test'), '\u001b[31mtest\u001b[39m');