lib: cleanup validation

Used the `validateInteger()` validator to cleanup validation and keep
consistency.

PR-URL: https://github.com/nodejs/node/pull/39652
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
Voltrex authored and Danielle Adams committed 2021-08-16 16:35:25 -04:00
1 parent cc08d3062f
commit ca3cb96d25
1 file changed
+3 -10
+3 -10
View File
@@ -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);
}