Skip to content

Commit

Permalink
lib: cleanup validation
Browse files Browse the repository at this point in the history
Used the `validateInteger()` validator to cleanup validation and keep
consistency.
  • Loading branch information
VoltrexKeyva committed Aug 3, 2021
1 parent dd18795 commit 96950f7
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/internal/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -220,14 +217,9 @@ function hasColors(count, env) {
(count === undefined || (typeof count === 'object' && count !== null))) {
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);
}
}
} else
validateInteger(count, 'count', 2);

return count <= 2 ** getColorDepth(env);
}

Expand Down

0 comments on commit 96950f7

Please sign in to comment.