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.

PR-URL: #39652
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
VoltrexKeyva authored and targos committed Sep 4, 2021
1 parent 49a7962 commit e101935
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 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 @@ -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);
}

Expand Down

0 comments on commit e101935

Please sign in to comment.