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 <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
VoltrexKeyva authored and jasnell committed Aug 12, 2021
1 parent 0b69ac7 commit ae0cfc9
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 ae0cfc9

Please sign in to comment.