Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions test/parallel/test-util-styletext.js
Comment thread
Han5991 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ assert.strictEqual(
'\u001b[31mtest\u001b[39m',
);

assert.strictEqual(
util.styleText('gray', 'test', { validateStream: false }),
'\u001b[90mtest\u001b[39m',
);

assert.strictEqual(
util.styleText('grey', 'test', { validateStream: false }),
'\u001b[90mtest\u001b[39m',
);

assert.strictEqual(
util.styleText(['bold', 'red'], 'test', { validateStream: false }),
'\u001b[1m\u001b[31mtest\u001b[39m\u001b[22m',
Expand Down
Loading