Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const {
ObjectDefineProperties,
ObjectDefineProperty,
ObjectGetOwnPropertyDescriptors,
ObjectGetOwnPropertyNames,
ObjectKeys,
ObjectSetPrototypeOf,
ObjectValues,
Expand Down Expand Up @@ -115,7 +116,7 @@ function getStyleCache() {
if (styleCache === undefined) {
styleCache = { __proto__: null };
const colors = inspect.colors;
for (const key of ObjectKeys(colors)) {
for (const key of ObjectGetOwnPropertyNames(colors)) {
const codes = colors[key];
if (codes) {
const openNum = codes[0];
Expand Down Expand Up @@ -206,7 +207,7 @@ function styleText(format, text, options) {
if (key === 'none') continue;
const style = cache[key];
if (style === undefined) {
validateOneOf(key, 'format', ObjectKeys(inspect.colors));
validateOneOf(key, 'format', ObjectGetOwnPropertyNames(inspect.colors));
}
openCodes += style.openSeq;
closeCodes = style.closeSeq + closeCodes;
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-util-styletext.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ assert.throws(() => {
code: 'ERR_INVALID_ARG_VALUE',
});

// Color aliases should be accepted (e.g. 'grey' is an alias for 'gray')
// See https://github.com/nodejs/node/issues/62177
assert.strictEqual(
util.styleText('grey', 'test', { validateStream: false }),
util.styleText('gray', 'test', { validateStream: false }),
);
assert.strictEqual(
util.styleText('bgGrey', 'test', { validateStream: false }),
util.styleText('bgGray', 'test', { validateStream: false }),
);
assert.strictEqual(
util.styleText('blackBright', 'test', { validateStream: false }),
util.styleText('gray', 'test', { validateStream: false }),
);
assert.strictEqual(
util.styleText('faint', 'test', { validateStream: false }),
util.styleText('dim', 'test', { validateStream: false }),
);
assert.strictEqual(
util.styleText(['grey', 'bold'], 'test', { validateStream: false }),
util.styleText(['gray', 'bold'], 'test', { validateStream: false }),
);

assert.throws(() => {
util.styleText('red', 'text', { stream: {} });
}, {
Expand Down
Loading