From d453331889c9986e2eeeeac5a0f2c17f47153b7a Mon Sep 17 00:00:00 2001 From: Voltrex Date: Wed, 4 Aug 2021 00:25:38 +0430 Subject: [PATCH] lib: cleanup validation Used the `validateInteger()` validator to cleanup validation and keep consistency. --- lib/internal/tty.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/internal/tty.js b/lib/internal/tty.js index 5a247c7928c346..f8bfe8cf21a32b 100644 --- a/lib/internal/tty.js +++ b/lib/internal/tty.js @@ -29,10 +29,7 @@ const { StringPrototypeToLowerCase, } = primordials; -const { - ERR_INVALID_ARG_TYPE, - ERR_OUT_OF_RANGE -} = require('internal/errors').codes; +const { validateInteger } = require('internal/validators'); let OSRelease; @@ -221,13 +218,9 @@ function hasColors(count, env) { env = count; count = 16; } else { - if (typeof count !== 'number') { - throw new ERR_INVALID_ARG_TYPE('count', 'number', count); - } - if (count < 2) { - throw new ERR_OUT_OF_RANGE('count', '>= 2', count); - } + validateInteger(count, 'count', 2); } + return count <= 2 ** getColorDepth(env); }