Skip to content

Commit

Permalink
console: use validateOneOf for colorMode validation
Browse files Browse the repository at this point in the history
refactor the Console constructor to use validateOneOf for validating
the colorMode parameter.

PR-URL: #54245
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
rayark1 authored and targos committed Oct 2, 2024
1 parent 6e7de37 commit a110409
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ const {
isStackOverflowError,
codes: {
ERR_CONSOLE_WRITABLE_STREAM,
ERR_INVALID_ARG_VALUE,
ERR_INCOMPATIBLE_OPTION_PAIR,
},
} = require('internal/errors');
const {
validateArray,
validateInteger,
validateObject,
validateOneOf,
} = require('internal/validators');
const { previewEntries } = internalBinding('util');
const { Buffer: { isBuffer } } = require('buffer');
Expand Down Expand Up @@ -135,8 +135,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
throw new ERR_CONSOLE_WRITABLE_STREAM('stderr');
}

if (typeof colorMode !== 'boolean' && colorMode !== 'auto')
throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);
validateOneOf(colorMode, 'colorMode', ['auto', true, false]);

if (groupIndentation !== undefined) {
validateInteger(groupIndentation, 'groupIndentation',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-console-tty-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ check(false, false, false);
});
},
{
message: `The argument 'colorMode' is invalid. Received ${received}`,
message: `The argument 'colorMode' must be one of: 'auto', true, false. Received ${received}`,
code: 'ERR_INVALID_ARG_VALUE'
}
);
Expand Down

0 comments on commit a110409

Please sign in to comment.