mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
console: use validateOneOf for colorMode validation
refactor the Console constructor to use validateOneOf for validating the colorMode parameter. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
4557c13c21
commit
90d91abbfe
@ -39,7 +39,6 @@ const {
|
||||
codes: {
|
||||
ERR_CONSOLE_WRITABLE_STREAM,
|
||||
ERR_INCOMPATIBLE_OPTION_PAIR,
|
||||
ERR_INVALID_ARG_VALUE,
|
||||
},
|
||||
isStackOverflowError,
|
||||
} = require('internal/errors');
|
||||
@ -47,6 +46,7 @@ const {
|
||||
validateArray,
|
||||
validateInteger,
|
||||
validateObject,
|
||||
validateOneOf,
|
||||
} = require('internal/validators');
|
||||
const { previewEntries } = internalBinding('util');
|
||||
const { Buffer: { isBuffer } } = require('buffer');
|
||||
@ -124,8 +124,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',
|
||||
|
@ -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'
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user